From e50674833d9ba6eed2ec47ec2f0e867596713523 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Tue, 30 Aug 2022 19:05:29 +0200 Subject: [PATCH] image-dired: Prefer defvar-keymap * lisp/image/image-dired-dired.el (image-dired-minor-mode-map): * lisp/image/image-dired.el (image-dired-thumbnail-mode-line-up-map) (image-dired-thumbnail-mode-tag-map) (image-dired-thumbnail-mode-map) (image-dired-display-image-mode-map): Prefer defvar-keymap. --- lisp/image/image-dired-dired.el | 45 ++++----- lisp/image/image-dired.el | 164 ++++++++++++++------------------ 2 files changed, 92 insertions(+), 117 deletions(-) diff --git a/lisp/image/image-dired-dired.el b/lisp/image/image-dired-dired.el index d5d7e0c38fb..aa9fa38751a 100644 --- a/lisp/image/image-dired-dired.el +++ b/lisp/image/image-dired-dired.el @@ -191,30 +191,27 @@ With prefix argument, move ARG lines." (select-window window)) (message "Thumbnail buffer not visible")))) -(defvar image-dired-minor-mode-map - (let ((map (make-sparse-keymap))) - ;; (set-keymap-parent map dired-mode-map) - ;; Hijack previous and next line movement. Let C-p and C-b be - ;; though... - (define-key map "p" #'image-dired-dired-previous-line) - (define-key map "n" #'image-dired-dired-next-line) - (define-key map [up] #'image-dired-dired-previous-line) - (define-key map [down] #'image-dired-dired-next-line) - - (define-key map (kbd "C-S-n") #'image-dired-next-line-and-display) - (define-key map (kbd "C-S-p") #'image-dired-previous-line-and-display) - (define-key map (kbd "C-S-m") #'image-dired-mark-and-display-next) - - (define-key map "\C-td" #'image-dired-display-thumbs) - (define-key map [tab] #'image-dired-jump-thumbnail-buffer) - (define-key map "\C-ti" #'image-dired-dired-display-image) - (define-key map "\C-tx" #'image-dired-dired-display-external) - (define-key map "\C-ta" #'image-dired-display-thumbs-append) - (define-key map "\C-t." #'image-dired-display-thumb) - (define-key map "\C-tc" #'image-dired-dired-comment-files) - (define-key map "\C-tf" #'image-dired-mark-tagged-files) - map) - "Keymap for `image-dired-minor-mode'.") +(defvar-keymap image-dired-minor-mode-map + :doc "Keymap for `image-dired-minor-mode'." + ;; Hijack previous and next line movement. Let C-p and C-b be + ;; though... + "p" #'image-dired-dired-previous-line + "n" #'image-dired-dired-next-line + "" #'image-dired-dired-previous-line + "" #'image-dired-dired-next-line + + "C-S-n" #'image-dired-next-line-and-display + "C-S-p" #'image-dired-previous-line-and-display + "C-S-m" #'image-dired-mark-and-display-next + + "C-t d" #'image-dired-display-thumbs + "" #'image-dired-jump-thumbnail-buffer + "C-t i" #'image-dired-dired-display-image + "C-t x" #'image-dired-dired-display-external + "C-t a" #'image-dired-display-thumbs-append + "C-t ." #'image-dired-display-thumb + "C-t c" #'image-dired-dired-comment-files + "C-t f" #'image-dired-mark-tagged-files) (easy-menu-define image-dired-minor-mode-menu image-dired-minor-mode-map "Menu for `image-dired-minor-mode'." diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index 7c4de161728..87c2cd3f094 100644 --- a/lisp/image/image-dired.el +++ b/lisp/image/image-dired.el @@ -819,84 +819,64 @@ You probably want to use this together with (select-window window)) (message "Associated dired buffer not visible")))) -(defvar image-dired-thumbnail-mode-line-up-map - (let ((map (make-sparse-keymap))) - ;; map it to "g" so that the user can press it more quickly - (define-key map "g" #'image-dired-line-up-dynamic) - ;; "f" for "fixed" number of thumbs per row - (define-key map "f" #'image-dired-line-up) - ;; "i" for "interactive" - (define-key map "i" #'image-dired-line-up-interactive) - map) - "Keymap for line-up commands in `image-dired-thumbnail-mode'.") - -(defvar image-dired-thumbnail-mode-tag-map - (let ((map (make-sparse-keymap))) - ;; map it to "t" so that the user can press it more quickly - (define-key map "t" #'image-dired-tag-thumbnail) - ;; "r" for "remove" - (define-key map "r" #'image-dired-tag-thumbnail-remove) - map) - "Keymap for tag commands in `image-dired-thumbnail-mode'.") - -(defvar image-dired-thumbnail-mode-map - (let ((map (make-sparse-keymap))) - (define-key map [right] #'image-dired-forward-image) - (define-key map [left] #'image-dired-backward-image) - (define-key map [up] #'image-dired-previous-line) - (define-key map [down] #'image-dired-next-line) - (define-key map "\C-f" #'image-dired-forward-image) - (define-key map "\C-b" #'image-dired-backward-image) - (define-key map "\C-p" #'image-dired-previous-line) - (define-key map "\C-n" #'image-dired-next-line) - - (define-key map "<" #'image-dired-beginning-of-buffer) - (define-key map ">" #'image-dired-end-of-buffer) - (define-key map (kbd "M-<") #'image-dired-beginning-of-buffer) - (define-key map (kbd "M->") #'image-dired-end-of-buffer) - - (define-key map "d" #'image-dired-flag-thumb-original-file) - (define-key map [delete] #'image-dired-flag-thumb-original-file) - (define-key map "m" #'image-dired-mark-thumb-original-file) - (define-key map "u" #'image-dired-unmark-thumb-original-file) - (define-key map "U" #'image-dired-unmark-all-marks) - (define-key map "." #'image-dired-track-original-file) - (define-key map [tab] #'image-dired-jump-original-dired-buffer) - - ;; add line-up map - (define-key map "g" image-dired-thumbnail-mode-line-up-map) - ;; add tag map - (define-key map "t" image-dired-thumbnail-mode-tag-map) - - (define-key map "\C-m" #'image-dired-display-thumbnail-original-image) - (define-key map [C-return] #'image-dired-thumbnail-display-external) - - (define-key map "L" #'image-dired-rotate-original-left) - (define-key map "R" #'image-dired-rotate-original-right) - - (define-key map "D" #'image-dired-thumbnail-set-image-description) - (define-key map "S" #'image-dired-slideshow-start) - (define-key map "\C-d" #'image-dired-delete-char) - (define-key map " " #'image-dired-display-next-thumbnail-original) - (define-key map (kbd "DEL") #'image-dired-display-previous-thumbnail-original) - (define-key map "c" #'image-dired-comment-thumbnail) - - ;; Mouse - (define-key map [mouse-2] #'image-dired-mouse-display-image) - (define-key map [mouse-1] #'image-dired-mouse-select-thumbnail) - (define-key map [mouse-3] #'image-dired-mouse-select-thumbnail) - (define-key map [down-mouse-1] #'image-dired-mouse-select-thumbnail) - (define-key map [down-mouse-2] #'image-dired-mouse-select-thumbnail) - (define-key map [down-mouse-3] #'image-dired-mouse-select-thumbnail) - ;; Seems I must first set C-down-mouse-1 to undefined, or else it - ;; will trigger the buffer menu. If I try to instead bind - ;; C-down-mouse-1 to `image-dired-mouse-toggle-mark', I get a message - ;; about C-mouse-1 not being defined afterwards. Annoying, but I - ;; probably do not completely understand mouse events. - (define-key map [C-down-mouse-1] #'undefined) - (define-key map [C-mouse-1] #'image-dired-mouse-toggle-mark) - map) - "Keymap for `image-dired-thumbnail-mode'.") +(defvar-keymap image-dired-thumbnail-mode-map + :doc "Keymap for `image-dired-thumbnail-mode'." + "" #'image-dired-forward-image + "" #'image-dired-backward-image + "" #'image-dired-previous-line + "" #'image-dired-next-line + "C-f" #'image-dired-forward-image + "C-b" #'image-dired-backward-image + "C-p" #'image-dired-previous-line + "C-n" #'image-dired-next-line + + "<" #'image-dired-beginning-of-buffer + ">" #'image-dired-end-of-buffer + "M-<" #'image-dired-beginning-of-buffer + "M->" #'image-dired-end-of-buffer + + "d" #'image-dired-flag-thumb-original-file + "" #'image-dired-flag-thumb-original-file + "m" #'image-dired-mark-thumb-original-file + "u" #'image-dired-unmark-thumb-original-file + "U" #'image-dired-unmark-all-marks + "." #'image-dired-track-original-file + "" #'image-dired-jump-original-dired-buffer + + "g g" #'image-dired-line-up-dynamic + "g f" #'image-dired-line-up + "g i" #'image-dired-line-up-interactive + + "t t" #'image-dired-tag-thumbnail + "t r" #'image-dired-tag-thumbnail-remove + + "RET" #'image-dired-display-thumbnail-original-image + "C-" #'image-dired-thumbnail-display-external + + "L" #'image-dired-rotate-original-left + "R" #'image-dired-rotate-original-right + + "D" #'image-dired-thumbnail-set-image-description + "S" #'image-dired-slideshow-start + "C-d" #'image-dired-delete-char + "SPC" #'image-dired-display-next-thumbnail-original + "DEL" #'image-dired-display-previous-thumbnail-original + "c" #'image-dired-comment-thumbnail + + ;; Mouse + "" #'image-dired-mouse-display-image + "" #'image-dired-mouse-select-thumbnail + "" #'image-dired-mouse-select-thumbnail + "" #'image-dired-mouse-select-thumbnail + "" #'image-dired-mouse-select-thumbnail + "" #'image-dired-mouse-select-thumbnail + ;; Seems I must first set C-down-mouse-1 to undefined, or else it + ;; will trigger the buffer menu. If I try to instead bind + ;; C-down-mouse-1 to `image-dired-mouse-toggle-mark', I get a message + ;; about C-mouse-1 not being defined afterwards. Annoying, but I + ;; probably do not completely understand mouse events. + "C-" #'undefined + "C-" #'image-dired-mouse-toggle-mark) (easy-menu-define image-dired-thumbnail-mode-menu image-dired-thumbnail-mode-map "Menu for `image-dired-thumbnail-mode'." @@ -930,21 +910,19 @@ You probably want to use this together with ["Refresh thumb" image-dired-refresh-thumb]) ["Quit" quit-window])) -(defvar image-dired-display-image-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "S" #'image-dired-slideshow-start) - (define-key map (kbd "SPC") #'image-dired-display-next-thumbnail-original) - (define-key map (kbd "DEL") #'image-dired-display-previous-thumbnail-original) - (define-key map "n" #'image-dired-display-next-thumbnail-original) - (define-key map "p" #'image-dired-display-previous-thumbnail-original) - (define-key map "m" #'image-dired-mark-thumb-original-file) - (define-key map "d" #'image-dired-flag-thumb-original-file) - (define-key map "u" #'image-dired-unmark-thumb-original-file) - (define-key map "U" #'image-dired-unmark-all-marks) - ;; Disable keybindings from `image-mode-map' that doesn't make sense here. - (define-key map "o" nil) ; image-save - map) - "Keymap for `image-dired-display-image-mode'.") +(defvar-keymap image-dired-display-image-mode-map + :doc "Keymap for `image-dired-display-image-mode'." + "S" #'image-dired-slideshow-start + "SPC" #'image-dired-display-next-thumbnail-original + "DEL" #'image-dired-display-previous-thumbnail-original + "n" #'image-dired-display-next-thumbnail-original + "p" #'image-dired-display-previous-thumbnail-original + "m" #'image-dired-mark-thumb-original-file + "d" #'image-dired-flag-thumb-original-file + "u" #'image-dired-unmark-thumb-original-file + "U" #'image-dired-unmark-all-marks + ;; Disable keybindings from `image-mode-map' that doesn't make sense here. + "o" nil) ; image-save (define-derived-mode image-dired-thumbnail-mode special-mode "image-dired-thumbnail" -- 2.39.2