From cdf5340f51d4346c276102331e3ed29561753b26 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Thu, 15 Dec 2016 21:59:15 -0500 Subject: [PATCH] New commands image-scroll-left and image-scroll-right * etc/NEWS: Mention them. * lisp/image-mode.el (image-scroll-left, image-scroll-right): New functions. --- etc/NEWS | 6 ++++++ lisp/image-mode.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index fdd901f0dd6..e69ba874849 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -456,6 +456,12 @@ details. *** New setf-able function to access and set image parameters is provided: 'image-property'. +--- +*** New commands 'image-scroll-left' and 'image-scroll-right' +for 'image-mode' that complement 'image-scroll-up' and +'image-scroll-down': they have the same prefix arg behavior and stop +at image boundaries. + --- ** The default 'Info-default-directory-list' no longer checks some obsolete directory suffixes (gnu, gnu/lib, gnu/lib/emacs, emacs, lib, lib/emacs) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index ce56208c6df..4a7178d18af 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -273,6 +273,48 @@ When calling from a program, supply as argument a number, nil, or `-'." (max 0 (- win-height next-screen-context-lines))))) (t (image-next-line (- (prefix-numeric-value n)))))) +(defun image-scroll-left (&optional n) + "Scroll image in current window leftward by N character widths. +Stop if the right edge of the image is reached. +If ARG is omitted or nil, scroll leftward by a near full screen. +A near full screen is 2 columns less than a full screen. +Negative ARG means scroll rightward. +If ARG is the atom `-', scroll rightward by nearly full screen. +When calling from a program, supply as argument a number, nil, or `-'." + (interactive "P") + (cond ((null n) + (let* ((edges (window-inside-edges)) + (win-width (- (nth 2 edges) (nth 0 edges)))) + (image-forward-hscroll + (max 0 (- win-width 2))))) + ((eq n '-) + (let* ((edges (window-inside-edges)) + (win-width (- (nth 2 edges) (nth 0 edges)))) + (image-forward-hscroll + (min 0 (- 2 win-width))))) + (t (image-forward-hscroll (prefix-numeric-value n))))) + +(defun image-scroll-right (&optional n) + "Scroll image in current window rightward by N character widths. +Stop if the left edge of the image is reached. +If ARG is omitted or nil, scroll downward by a near full screen. +A near full screen is 2 less than a full screen. +Negative ARG means scroll leftward. +If ARG is the atom `-', scroll leftward by nearly full screen. +When calling from a program, supply as argument a number, nil, or `-'." + (interactive "P") + (cond ((null n) + (let* ((edges (window-inside-edges)) + (win-width (- (nth 2 edges) (nth 0 edges)))) + (image-forward-hscroll + (min 0 (- 2 win-width))))) + ((eq n '-) + (let* ((edges (window-inside-edges)) + (win-width (- (nth 2 edges) (nth 0 edges)))) + (image-forward-hscroll + (max 0 (- win-width 2))))) + (t (image-forward-hscroll (- (prefix-numeric-value n)))))) + (defun image-bol (arg) "Scroll horizontally to the left edge of the image in the current window. With argument ARG not nil or 1, move forward ARG - 1 lines first, @@ -401,6 +443,8 @@ call." (define-key map [remap scroll-down] 'image-scroll-down) (define-key map [remap scroll-up-command] 'image-scroll-up) (define-key map [remap scroll-down-command] 'image-scroll-down) + (define-key map [remap scroll-left] 'image-scroll-left) + (define-key map [remap scroll-right] 'image-scroll-right) (define-key map [remap move-beginning-of-line] 'image-bol) (define-key map [remap move-end-of-line] 'image-eol) (define-key map [remap beginning-of-buffer] 'image-bob) -- 2.39.2