(@code{image-previous-file}) to visit the next image file and the
previous image file in the same directory, respectively.
+@findex image-mode-mark-file
+@findex image-mode-unmark-file
+@findex image-mode-copy-file-name-as-kill
+ When looking through images, it's sometimes convenient to be able to
+mark the files for later processing (for instance, if you want to
+select a group of images to copy somewhere else). The @kbd{m}
+(@code{image-mode-mark-file}) command will mark the current file in
+any Dired buffer(s) that display the current file's directory. If no
+such buffer is open, the directory is opened in a new buffer. To
+unmark files, use the @kbd{u} (@code{image-mode-mark-file}) command.
+Finally, if you just want to copy the current buffers file name to the
+kill ring, you can use the @kbd{w}
+(@code{image-mode-copy-file-name-as-kill}) command.
+
@findex image-toggle-animation
@findex image-next-frame
@findex image-previous-frame
(define-key map "a-" 'image-decrease-speed)
(define-key map "a0" 'image-reset-speed)
(define-key map "ar" 'image-reverse-speed)
- (define-key map "k" 'image-kill-buffer)
+ (define-key map "w" 'image-mode-copy-file-name-as-kill)
+ (define-key map "m" 'image-mode-mark-file)
+ (define-key map "u" 'image-mode-unmark-file)
(define-key map [remap forward-char] 'image-forward-hscroll)
(define-key map [remap backward-char] 'image-backward-hscroll)
(define-key map [remap right-char] 'image-forward-hscroll)
:help "Move to next image in this directory"]
["Previous Image" image-previous-file :active buffer-file-name
:help "Move to previous image in this directory"]
+ ["Copy File Name" image-mode-copy-file-name-as-kill
+ :active buffer-file-name
+ :help "Copy the current file name to the kill ring"]
"--"
["Fit Frame to Image" image-mode-fit-frame :active t
:help "Resize frame to match image"]
(interactive "p")
(image-next-file (- n)))
+(defun image-mode-copy-file-name-as-kill ()
+ "Push the currently visited file name onto the kill ring."
+ (interactive)
+ (unless buffer-file-name
+ (error "The current buffer doesn't visit a file"))
+ (kill-new buffer-file-name)
+ (message "Copied %s" buffer-file-name))
+
+(defun image-mode-mark-file ()
+ "Mark the current file in the appropriate dired buffer(s).
+Any dired buffer that's opened to the current file's directory
+will have the line where the image appears (if any) marked.
+
+If no such buffer exists, it will be opened."
+ (interactive)
+ (unless buffer-file-name
+ (error "The current buffer doesn't visit a file."))
+ (image-mode--mark-file buffer-file-name #'dired-mark "marked"))
+
+(defun image-mode-unmark-file ()
+ "Unmark the current file in the appropriate dired buffer(s).
+Any dired buffer that's opened to the current file's directory
+will remove the mark from the line where the image appears (if
+any).
+
+If no such buffer exists, it will be opened."
+ (interactive)
+ (unless buffer-file-name
+ (error "The current buffer doesn't visit a file."))
+ (image-mode--mark-file buffer-file-name #'dired-unmark "unmarked"))
+
+(declare-function dired-mark "dired" (arg &optional interactive))
+(declare-function dired-unmark "dired" (arg &optional interactive))
+(declare-function dired-goto-file "dired" (file))
+
+(defun image-mode--mark-file (file function message)
+ (require 'dired)
+ (let* ((dir (file-name-directory file))
+ (buffers
+ (cl-loop for buffer in (buffer-list)
+ when (with-current-buffer buffer
+ (and (eq major-mode 'dired-mode)
+ (equal (file-truename dir)
+ (file-truename default-directory))))
+ collect buffer))
+ results)
+ (unless buffers
+ (save-excursion
+ (setq buffers (list (find-file-noselect dir)))))
+ (dolist (buffer buffers)
+ (with-current-buffer buffer
+ (if (not (dired-goto-file file))
+ (push (format "couldn't find in %s" (directory-file-name dir))
+ results)
+ (funcall function 1)
+ (push (format "%s in %s" message (directory-file-name dir))
+ results))))
+ ;; Capitalize first character.
+ (let ((string (mapconcat #'identity results "; ")))
+ (message "%s%s" (capitalize (substring string 0 1))
+ (substring string 1)))))
+
(defun image-mode--images-in-directory (file)
(let* ((dir (file-name-directory buffer-file-name))
(files (directory-files dir nil