diff options
| author | Lars Ingebrigtsen | 2019-10-01 19:53:48 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-01 19:53:48 +0200 |
| commit | 98bbded2b37b7608573b1a9c596f5c215257b7ad (patch) | |
| tree | 86ce7ebf95ac7b1553f53e27e3b1dd65cc7a93fd | |
| parent | 41f59e71e2fc60a10991b4e1457fa787e87ab2b3 (diff) | |
| download | emacs-98bbded2b37b7608573b1a9c596f5c215257b7ad.tar.gz emacs-98bbded2b37b7608573b1a9c596f5c215257b7ad.zip | |
Add support for Dired file marking from image-mode
* doc/emacs/files.texi (File Conveniences): Document them.
* lisp/image-mode.el (image-mode--mark-file): New function.
(image-mode-unmark-file, image-mode-mark-file)
(image-mode-copy-file-name-as-kill): New commands and keystrokes.
| -rw-r--r-- | doc/emacs/files.texi | 14 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/image-mode.el | 69 |
3 files changed, 88 insertions, 1 deletions
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 0ff64d529c0..9fe1b564a82 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi | |||
| @@ -2119,6 +2119,20 @@ displayed. You can press @kbd{n} (@code{image-next-file}) and @kbd{p} | |||
| 2119 | (@code{image-previous-file}) to visit the next image file and the | 2119 | (@code{image-previous-file}) to visit the next image file and the |
| 2120 | previous image file in the same directory, respectively. | 2120 | previous image file in the same directory, respectively. |
| 2121 | 2121 | ||
| 2122 | @findex image-mode-mark-file | ||
| 2123 | @findex image-mode-unmark-file | ||
| 2124 | @findex image-mode-copy-file-name-as-kill | ||
| 2125 | When looking through images, it's sometimes convenient to be able to | ||
| 2126 | mark the files for later processing (for instance, if you want to | ||
| 2127 | select a group of images to copy somewhere else). The @kbd{m} | ||
| 2128 | (@code{image-mode-mark-file}) command will mark the current file in | ||
| 2129 | any Dired buffer(s) that display the current file's directory. If no | ||
| 2130 | such buffer is open, the directory is opened in a new buffer. To | ||
| 2131 | unmark files, use the @kbd{u} (@code{image-mode-mark-file}) command. | ||
| 2132 | Finally, if you just want to copy the current buffers file name to the | ||
| 2133 | kill ring, you can use the @kbd{w} | ||
| 2134 | (@code{image-mode-copy-file-name-as-kill}) command. | ||
| 2135 | |||
| 2122 | @findex image-toggle-animation | 2136 | @findex image-toggle-animation |
| 2123 | @findex image-next-frame | 2137 | @findex image-next-frame |
| 2124 | @findex image-previous-frame | 2138 | @findex image-previous-frame |
| @@ -2726,6 +2726,12 @@ buffer-local, so each buffer could have its own values for these | |||
| 2726 | parameters. | 2726 | parameters. |
| 2727 | 2727 | ||
| 2728 | +++ | 2728 | +++ |
| 2729 | *** Three new 'image-mode' commands have been added: 'm', which marks | ||
| 2730 | the file in the dired buffer(s) for the directory the file is in; 'u', | ||
| 2731 | which unmarks the file; and 'w', which pushes the current buffer's file | ||
| 2732 | name to the kill ring. | ||
| 2733 | |||
| 2734 | +++ | ||
| 2729 | *** The command 'image-rotate' now accepts a prefix argument. | 2735 | *** The command 'image-rotate' now accepts a prefix argument. |
| 2730 | With a prefix argument, 'image-rotate' now rotates the image at point | 2736 | With a prefix argument, 'image-rotate' now rotates the image at point |
| 2731 | 90 degrees counter-clockwise, instead of the default clockwise. | 2737 | 90 degrees counter-clockwise, instead of the default clockwise. |
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index aaec9026e57..ed796565a38 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -430,7 +430,9 @@ call." | |||
| 430 | (define-key map "a-" 'image-decrease-speed) | 430 | (define-key map "a-" 'image-decrease-speed) |
| 431 | (define-key map "a0" 'image-reset-speed) | 431 | (define-key map "a0" 'image-reset-speed) |
| 432 | (define-key map "ar" 'image-reverse-speed) | 432 | (define-key map "ar" 'image-reverse-speed) |
| 433 | (define-key map "k" 'image-kill-buffer) | 433 | (define-key map "w" 'image-mode-copy-file-name-as-kill) |
| 434 | (define-key map "m" 'image-mode-mark-file) | ||
| 435 | (define-key map "u" 'image-mode-unmark-file) | ||
| 434 | (define-key map [remap forward-char] 'image-forward-hscroll) | 436 | (define-key map [remap forward-char] 'image-forward-hscroll) |
| 435 | (define-key map [remap backward-char] 'image-backward-hscroll) | 437 | (define-key map [remap backward-char] 'image-backward-hscroll) |
| 436 | (define-key map [remap right-char] 'image-forward-hscroll) | 438 | (define-key map [remap right-char] 'image-forward-hscroll) |
| @@ -477,6 +479,9 @@ call." | |||
| 477 | :help "Move to next image in this directory"] | 479 | :help "Move to next image in this directory"] |
| 478 | ["Previous Image" image-previous-file :active buffer-file-name | 480 | ["Previous Image" image-previous-file :active buffer-file-name |
| 479 | :help "Move to previous image in this directory"] | 481 | :help "Move to previous image in this directory"] |
| 482 | ["Copy File Name" image-mode-copy-file-name-as-kill | ||
| 483 | :active buffer-file-name | ||
| 484 | :help "Copy the current file name to the kill ring"] | ||
| 480 | "--" | 485 | "--" |
| 481 | ["Fit Frame to Image" image-mode-fit-frame :active t | 486 | ["Fit Frame to Image" image-mode-fit-frame :active t |
| 482 | :help "Resize frame to match image"] | 487 | :help "Resize frame to match image"] |
| @@ -986,6 +991,68 @@ replacing the current Image mode buffer." | |||
| 986 | (interactive "p") | 991 | (interactive "p") |
| 987 | (image-next-file (- n))) | 992 | (image-next-file (- n))) |
| 988 | 993 | ||
| 994 | (defun image-mode-copy-file-name-as-kill () | ||
| 995 | "Push the currently visited file name onto the kill ring." | ||
| 996 | (interactive) | ||
| 997 | (unless buffer-file-name | ||
| 998 | (error "The current buffer doesn't visit a file")) | ||
| 999 | (kill-new buffer-file-name) | ||
| 1000 | (message "Copied %s" buffer-file-name)) | ||
| 1001 | |||
| 1002 | (defun image-mode-mark-file () | ||
| 1003 | "Mark the current file in the appropriate dired buffer(s). | ||
| 1004 | Any dired buffer that's opened to the current file's directory | ||
| 1005 | will have the line where the image appears (if any) marked. | ||
| 1006 | |||
| 1007 | If no such buffer exists, it will be opened." | ||
| 1008 | (interactive) | ||
| 1009 | (unless buffer-file-name | ||
| 1010 | (error "The current buffer doesn't visit a file.")) | ||
| 1011 | (image-mode--mark-file buffer-file-name #'dired-mark "marked")) | ||
| 1012 | |||
| 1013 | (defun image-mode-unmark-file () | ||
| 1014 | "Unmark the current file in the appropriate dired buffer(s). | ||
| 1015 | Any dired buffer that's opened to the current file's directory | ||
| 1016 | will remove the mark from the line where the image appears (if | ||
| 1017 | any). | ||
| 1018 | |||
| 1019 | If no such buffer exists, it will be opened." | ||
| 1020 | (interactive) | ||
| 1021 | (unless buffer-file-name | ||
| 1022 | (error "The current buffer doesn't visit a file.")) | ||
| 1023 | (image-mode--mark-file buffer-file-name #'dired-unmark "unmarked")) | ||
| 1024 | |||
| 1025 | (declare-function dired-mark "dired" (arg &optional interactive)) | ||
| 1026 | (declare-function dired-unmark "dired" (arg &optional interactive)) | ||
| 1027 | (declare-function dired-goto-file "dired" (file)) | ||
| 1028 | |||
| 1029 | (defun image-mode--mark-file (file function message) | ||
| 1030 | (require 'dired) | ||
| 1031 | (let* ((dir (file-name-directory file)) | ||
| 1032 | (buffers | ||
| 1033 | (cl-loop for buffer in (buffer-list) | ||
| 1034 | when (with-current-buffer buffer | ||
| 1035 | (and (eq major-mode 'dired-mode) | ||
| 1036 | (equal (file-truename dir) | ||
| 1037 | (file-truename default-directory)))) | ||
| 1038 | collect buffer)) | ||
| 1039 | results) | ||
| 1040 | (unless buffers | ||
| 1041 | (save-excursion | ||
| 1042 | (setq buffers (list (find-file-noselect dir))))) | ||
| 1043 | (dolist (buffer buffers) | ||
| 1044 | (with-current-buffer buffer | ||
| 1045 | (if (not (dired-goto-file file)) | ||
| 1046 | (push (format "couldn't find in %s" (directory-file-name dir)) | ||
| 1047 | results) | ||
| 1048 | (funcall function 1) | ||
| 1049 | (push (format "%s in %s" message (directory-file-name dir)) | ||
| 1050 | results)))) | ||
| 1051 | ;; Capitalize first character. | ||
| 1052 | (let ((string (mapconcat #'identity results "; "))) | ||
| 1053 | (message "%s%s" (capitalize (substring string 0 1)) | ||
| 1054 | (substring string 1))))) | ||
| 1055 | |||
| 989 | (defun image-mode--images-in-directory (file) | 1056 | (defun image-mode--images-in-directory (file) |
| 990 | (let* ((dir (file-name-directory buffer-file-name)) | 1057 | (let* ((dir (file-name-directory buffer-file-name)) |
| 991 | (files (directory-files dir nil | 1058 | (files (directory-files dir nil |