From: Stefan Kangas Date: Sat, 24 Sep 2022 11:36:39 +0000 (+0200) Subject: image-dired: Fix C-a/C-e in thumbnail buffer X-Git-Tag: emacs-29.0.90~1856^2~262 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0bca1b4d037ef23d259dc6e7561266bf54433339;p=emacs.git image-dired: Fix C-a/C-e in thumbnail buffer * lisp/image/image-dired.el (image-dired--movement-ensure-point-pos): New function, and... (image-dired--movement-command): ...new macros broken out from... (image-dired-next-line, image-dired-previous-line) (image-dired-beginning-of-buffer, image-dired-end-of-buffer): ...here. (image-dired-move-beginning-of-line) (image-dired-move-end-of-line): New commands. (image-dired-thumbnail-mode-map): Remap 'move-beginning-of-line' and 'move-beginning-of-line' to above new commands. --- diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index c25dcad7695..f73b81c22de 100644 --- a/lisp/image/image-dired.el +++ b/lisp/image/image-dired.el @@ -655,56 +655,57 @@ On reaching end or beginning of buffer, stop and show a message." (interactive "p" image-dired-thumbnail-mode) (image-dired-forward-image (- (or arg 1)))) +(defun image-dired--movement-ensure-point-pos (&optional reverse) + "Ensure point is on an image." + (while (and (not (image-at-point-p)) + (not (if reverse (bobp) (eobp)))) + (forward-char (if reverse -1 1)))) + +(defmacro image-dired--movement-command (to &optional reverse) + `(progn + (goto-char ,to) + (image-dired--movement-ensure-point-pos ,reverse) + (when image-dired-track-movement + (image-dired-track-original-file)) + (image-dired-update-header-line))) + +(defmacro image-dired--movement-command-line (&optional reverse) + `(image-dired--movement-command + (let ((goal-column (current-column))) + (forward-line ,(if reverse -1 1)) + (move-to-column goal-column) + (point)) + ,reverse)) + (defun image-dired-next-line () "Move to next line in the thumbnail buffer." (interactive nil image-dired-thumbnail-mode) - (let ((goal-column (current-column))) - (forward-line 1) - (move-to-column goal-column)) - ;; If we end up in an empty spot, back up to the next thumbnail. - (if (not (image-dired-image-at-point-p)) - (image-dired-backward-image)) - (if image-dired-track-movement - (image-dired-track-original-file)) - (image-dired-update-header-line)) + (image-dired--movement-command-line)) (defun image-dired-previous-line () "Move to previous line in the thumbnail buffer." (interactive nil image-dired-thumbnail-mode) - (let ((goal-column (current-column))) - (forward-line -1) - (move-to-column goal-column)) - ;; If we end up in an empty spot, back up to the next thumbnail. - ;; This should only happen if the user deleted a thumbnail and did - ;; not refresh, so it is not very common. But we can handle it in a - ;; good manner, so why not? - (if (not (image-dired-image-at-point-p)) - (image-dired-backward-image)) - (if image-dired-track-movement - (image-dired-track-original-file)) - (image-dired-update-header-line)) + (image-dired--movement-command-line 'reverse)) (defun image-dired-beginning-of-buffer () "Move to the first image in the thumbnail buffer." (interactive nil image-dired-thumbnail-mode) - (goto-char (point-min)) - (while (and (not (image-at-point-p)) - (not (eobp))) - (forward-char 1)) - (when image-dired-track-movement - (image-dired-track-original-file)) - (image-dired-update-header-line)) + (image-dired--movement-command (point-min))) (defun image-dired-end-of-buffer () "Move to the last image in the thumbnail buffer." (interactive nil image-dired-thumbnail-mode) - (goto-char (point-max)) - (while (and (not (image-at-point-p)) - (not (bobp))) - (forward-char -1)) - (when image-dired-track-movement - (image-dired-track-original-file)) - (image-dired-update-header-line)) + (image-dired--movement-command (point-max) 'reverse)) + +(defun image-dired-move-beginning-of-line () + "Move to the beginning of current line in thumbnail buffer." + (interactive nil image-dired-thumbnail-mode) + (image-dired--movement-command (pos-bol))) + +(defun image-dired-move-end-of-line () + "Move to the end of current line in thumbnail buffer." + (interactive nil image-dired-thumbnail-mode) + (image-dired--movement-command (pos-eol) 'reverse)) ;;; Header line @@ -894,7 +895,10 @@ You probably want to use this together with "" #'image-dired-mouse-select-thumbnail "" #'image-dired-mouse-select-thumbnail "C-" #'ignore ; Don't open the buffer menu. - "C-" #'image-dired-mouse-toggle-mark) + "C-" #'image-dired-mouse-toggle-mark + + " " #'image-dired-move-beginning-of-line + " " #'image-dired-move-end-of-line) (easy-menu-define image-dired-thumbnail-mode-menu image-dired-thumbnail-mode-map "Menu for `image-dired-thumbnail-mode'."