1 ;;; image-dired.el --- use dired to browse and manipulate your images -*- lexical-binding: t -*-
3 ;; Copyright (C) 2005-2018 Free Software Foundation, Inc.
6 ;; Keywords: multimedia
7 ;; Author: Mathias Dahl <mathias.rem0veth1s.dahl@gmail.com>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
29 ;; I needed a program to browse, organize and tag my pictures. I got
30 ;; tired of the old gallery program I used as it did not allow
31 ;; multi-file operations easily. Also, it put things out of my
32 ;; control. Image viewing programs I tested did not allow multi-file
33 ;; operations or did not do what I wanted it to.
35 ;; So, I got the idea to use the wonderful functionality of Emacs and
36 ;; `dired' to do it. It would allow me to do almost anything I wanted,
37 ;; which is basically just to browse all my pictures in an easy way,
38 ;; letting me manipulate and tag them in various ways. `dired' already
39 ;; provide all the file handling and navigation facilities; I only
40 ;; needed to add some functions to display the images.
42 ;; I briefly tried out thumbs.el, and although it seemed more
43 ;; powerful than this package, it did not work the way I wanted to. It
44 ;; was too slow to created thumbnails of all files in a directory (I
45 ;; currently keep all my 2000+ images in the same directory) and
46 ;; browsing the thumbnail buffer was slow too. image-dired.el will not
47 ;; create thumbnails until they are needed and the browsing is done
48 ;; quickly and easily in dired. I copied a great deal of ideas and
49 ;; code from there though... :)
51 ;; `image-dired' stores the thumbnail files in `image-dired-dir'
52 ;; using the file name format ORIGNAME.thumb.ORIGEXT. For example
53 ;; ~/.emacs.d/image-dired/myimage01.thumb.jpg. The "database" is for
54 ;; now just a plain text file with the following format:
56 ;; file-name-non-directory;comment:comment-text;tag1;tag2;tag3;...;tagN
62 ;; * The ImageMagick package. Currently, `convert' and `mogrify' are
63 ;; used. Find it here: http://www.imagemagick.org.
65 ;; * For non-lossy rotation of JPEG images, the JpegTRAN program is
68 ;; * For `image-dired-get-exif-data' and `image-dired-write-exif-data' to work,
69 ;; the command line tool `exiftool' is needed. It can be found here:
70 ;; http://www.sno.phy.queensu.ca/~phil/exiftool/. These two functions
71 ;; are, among other things, used for writing comments to image files
72 ;; using `image-dired-thumbnail-set-image-description' and to create
73 ;; "unique" file names using `image-dired-get-exif-file-name' (used by
74 ;; `image-dired-copy-with-exif-file-name').
80 ;; This information has been moved to the manual. Type `C-h r' to open
81 ;; the Emacs manual and go to the node Thumbnails by typing `g
84 ;; Quickstart: M-x image-dired RET DIRNAME RET
86 ;; where DIRNAME is a directory containing image files.
91 ;; * Supports all image formats that Emacs and convert supports, but
92 ;; the thumbnails are hard-coded to JPEG format.
94 ;; * WARNING: The "database" format used might be changed so keep a
95 ;; backup of `image-dired-db-file' when testing new versions.
97 ;; * `image-dired-display-image-mode' does not support animation
102 ;; * Support gallery creation when using per-directory thumbnail
105 ;; * Some sort of auto-rotate function based on rotate info in the
108 ;; * Investigate if it is possible to also write the tags to the image
111 ;; * From thumbs.el: Add an option for clean-up/max-size functionality
112 ;; for thumbnail directory.
114 ;; * From thumbs.el: Add setroot function.
116 ;; * From thumbs.el: Add image resizing, if useful (image-dired's automatic
117 ;; "image fit" might be enough)
119 ;; * From thumbs.el: Add the "modify" commands (emboss, negate,
122 ;; * Add `image-dired-display-thumbs-ring' and functions to cycle that. Find
123 ;; out which is best, saving old batch just before inserting new, or
124 ;; saving the current batch in the ring when inserting it. Adding it
125 ;; probably needs rewriting `image-dired-display-thumbs' to be more general.
127 ;; * Find some way of toggling on and off really nice keybindings in
128 ;; dired (for example, using C-n or <down> instead of C-S-n). Richard
129 ;; suggested that we could keep C-t as prefix for image-dired commands
130 ;; as it is currently not used in dired. He also suggested that
131 ;; `dired-next-line' and `dired-previous-line' figure out if
132 ;; image-dired is enabled in the current buffer and, if it is, call
133 ;; `image-dired-dired-next-line' and
134 ;; `image-dired-dired-previous-line', respectively. Update: This is
135 ;; partly done; some bindings have now been added to dired.
137 ;; * Enhanced gallery creation with basic CSS-support and pagination
138 ;; of tag pages with many pictures.
140 ;; * Rewrite `image-dired-modify-mark-on-thumb-original-file' to be
143 ;; * In some way keep track of buffers and windows and stuff so that
144 ;; it works as the user expects.
146 ;; * More/better documentation
152 (require 'format-spec
)
153 (require 'image-mode
)
160 (defgroup image-dired nil
161 "Use dired to browse your images as thumbnails, and more."
162 :prefix
"image-dired-"
163 :link
'(info-link "(emacs) Image-Dired")
166 (defcustom image-dired-dir
(locate-user-emacs-file "image-dired/")
167 "Directory where thumbnail images are stored."
171 (defcustom image-dired-thumbnail-storage
'use-image-dired-dir
172 "How to store image-dired's thumbnail files.
173 Image-Dired can store thumbnail files in one of two ways and this is
174 controlled by this variable. \"Use image-dired dir\" means that the
175 thumbnails are stored in a central directory. \"Per directory\"
176 means that each thumbnail is stored in a subdirectory called
177 \".image-dired\" in the same directory where the image file is.
178 \"Thumbnail Managing Standard\" means that the thumbnails are
179 stored and generated according to the Thumbnail Managing Standard
180 that allows sharing of thumbnails across different programs."
181 :type
'(choice :tag
"How to store thumbnail files"
182 (const :tag
"Use image-dired-dir" use-image-dired-dir
)
183 (const :tag
"Thumbnail Managing Standard (normal 128x128)" standard
)
184 (const :tag
"Thumbnail Managing Standard (large 256x256)" standard-large
)
185 (const :tag
"Per-directory" per-directory
))
188 (defcustom image-dired-db-file
189 (expand-file-name ".image-dired_db" image-dired-dir
)
190 "Database file where file names and their associated tags are stored."
194 (defcustom image-dired-temp-image-file
195 (expand-file-name ".image-dired_temp" image-dired-dir
)
196 "Name of temporary image file used by various commands."
200 (defcustom image-dired-gallery-dir
201 (expand-file-name ".image-dired_gallery" image-dired-dir
)
202 "Directory to store generated gallery html pages.
203 This path needs to be \"shared\" to the public so that it can access
204 the index.html page that image-dired creates."
208 (defcustom image-dired-gallery-image-root-url
209 "http://your.own.server/image-diredpics"
210 "URL where the full size images are to be found.
211 Note that this path has to be configured in your web server. Image-Dired
212 expects to find pictures in this directory."
216 (defcustom image-dired-gallery-thumb-image-root-url
217 "http://your.own.server/image-diredthumbs"
218 "URL where the thumbnail images are to be found.
219 Note that this path has to be configured in your web server. Image-Dired
220 expects to find pictures in this directory."
224 (defcustom image-dired-cmd-create-thumbnail-program
226 "Executable used to create thumbnail.
227 Used together with `image-dired-cmd-create-thumbnail-options'."
231 (defcustom image-dired-cmd-create-thumbnail-options
232 '("-size" "%wx%h" "%f[0]" "-resize" "%wx%h>" "-strip" "jpeg:%t")
233 "Options of command used to create thumbnail image.
234 Used with `image-dired-cmd-create-thumbnail-program'.
235 Available format specifiers are: %w which is replaced by
236 `image-dired-thumb-width', %h which is replaced by `image-dired-thumb-height',
237 %f which is replaced by the file name of the original image and %t
238 which is replaced by the file name of the thumbnail file."
240 :type
'(repeat (string :tag
"Argument"))
243 (defcustom image-dired-cmd-create-temp-image-program
"convert"
244 "Executable used to create temporary image.
245 Used together with `image-dired-cmd-create-temp-image-options'."
249 (defcustom image-dired-cmd-create-temp-image-options
250 '("-size" "%wx%h" "%f[0]" "-resize" "%wx%h>" "-strip" "jpeg:%t")
251 "Options of command used to create temporary image for display window.
252 Used together with `image-dired-cmd-create-temp-image-program',
253 Available format specifiers are: %w and %h which are replaced by
254 the calculated max size for width and height in the image display window,
255 %f which is replaced by the file name of the original image and %t which
256 is replaced by the file name of the temporary file."
258 :type
'(repeat (string :tag
"Argument"))
261 (defcustom image-dired-cmd-pngnq-program
262 (or (executable-find "pngnq")
263 (executable-find "pngnq-s9"))
264 "The file name of the `pngnq' program.
265 It quantizes colors of PNG images down to 256 colors or fewer
266 using the NeuQuant algorithm."
268 :type
'(choice (const :tag
"Not Set" nil
) file
)
271 (defcustom image-dired-cmd-pngnq-options
273 "Arguments to pass `image-dired-cmd-pngnq-program'.
274 Available format specifiers are the same as in
275 `image-dired-cmd-create-thumbnail-options'."
277 :type
'(repeat (string :tag
"Argument"))
280 (defcustom image-dired-cmd-pngcrush-program
(executable-find "pngcrush")
281 "The file name of the `pngcrush' program.
282 It optimizes the compression of PNG images. Also it adds PNG textual chunks
283 with the information required by the Thumbnail Managing Standard."
284 :type
'(choice (const :tag
"Not Set" nil
) file
)
287 (defcustom image-dired-cmd-pngcrush-options
289 "-text" "b" "Description" "Thumbnail of file://%f"
290 "-text" "b" "Software" ,(emacs-version)
291 ;; "-text b \"Thumb::Image::Height\" \"%oh\" "
292 ;; "-text b \"Thumb::Image::Mimetype\" \"%mime\" "
293 ;; "-text b \"Thumb::Image::Width\" \"%ow\" "
294 "-text" "b" "Thumb::MTime" "%m"
295 ;; "-text b \"Thumb::Size\" \"%b\" "
296 "-text" "b" "Thumb::URI" "file://%f"
298 "Arguments for `image-dired-cmd-pngcrush-program'.
299 Available format specifiers are the same as in
300 `image-dired-cmd-create-thumbnail-options', with %q for a
301 temporary file name (typically generated by pnqnq)"
303 :type
'(repeat (string :tag
"Argument"))
306 (defcustom image-dired-cmd-optipng-program
(executable-find "optipng")
307 "The file name of the `optipng' program."
309 :type
'(choice (const :tag
"Not Set" nil
) file
)
312 (defcustom image-dired-cmd-optipng-options
'("-o5" "%t")
313 "Arguments passed to `image-dired-optipng-program'.
314 Available format specifiers are described in
315 `image-dired-cmd-create-thumbnail-options'."
317 :type
'(repeat (string :tag
"Argument"))
318 :link
'(url-link "man:optipng(1)")
321 (defcustom image-dired-cmd-create-standard-thumbnail-options
322 (append '("-size" "%wx%h" "%f[0]")
323 (unless (or image-dired-cmd-pngcrush-program
324 image-dired-cmd-pngnq-program
)
326 "-set" "Thumb::MTime" "%m"
327 "-set" "Thumb::URI" "file://%f"
328 "-set" "Description" "Thumbnail of file://%f"
329 "-set" "Software" (emacs-version)))
330 '("-thumbnail" "%wx%h>" "png:%t"))
331 "Options for creating thumbnails according to the Thumbnail Managing Standard.
332 Available format specifiers are the same as in
333 `image-dired-cmd-create-thumbnail-options', with %m for file modification time."
335 :type
'(repeat (string :tag
"Argument"))
338 (defcustom image-dired-cmd-rotate-thumbnail-program
340 "Executable used to rotate thumbnail.
341 Used together with `image-dired-cmd-rotate-thumbnail-options'."
345 (defcustom image-dired-cmd-rotate-thumbnail-options
346 '("-rotate" "%d" "%t")
347 "Arguments of command used to rotate thumbnail image.
348 Used with `image-dired-cmd-rotate-thumbnail-program'.
349 Available format specifiers are: %d which is replaced by the
350 number of (positive) degrees to rotate the image, normally 90 or 270
351 \(for 90 degrees right and left), %t which is replaced by the file name
352 of the thumbnail file."
354 :type
'(repeat (string :tag
"Argument"))
357 (defcustom image-dired-cmd-rotate-original-program
359 "Executable used to rotate original image.
360 Used together with `image-dired-cmd-rotate-original-options'."
364 (defcustom image-dired-cmd-rotate-original-options
365 '("-rotate" "%d" "-copy" "all" "-outfile" "%t" "%o")
366 "Arguments of command used to rotate original image.
367 Used with `image-dired-cmd-rotate-original-program'.
368 Available format specifiers are: %d which is replaced by the
369 number of (positive) degrees to rotate the image, normally 90 or
370 270 \(for 90 degrees right and left), %o which is replaced by the
371 original image file name and %t which is replaced by
372 `image-dired-temp-image-file'."
374 :type
'(repeat (string :tag
"Argument"))
377 (defcustom image-dired-temp-rotate-image-file
378 (expand-file-name ".image-dired_rotate_temp" image-dired-dir
)
379 "Temporary file for rotate operations."
383 (defcustom image-dired-rotate-original-ask-before-overwrite t
384 "Confirm overwrite of original file after rotate operation.
385 If non-nil, ask user for confirmation before overwriting the
386 original file with `image-dired-temp-rotate-image-file'."
390 (defcustom image-dired-cmd-write-exif-data-program
392 "Program used to write EXIF data to image.
393 Used together with `image-dired-cmd-write-exif-data-options'."
397 (defcustom image-dired-cmd-write-exif-data-options
399 "Arguments of command used to write EXIF data.
400 Used with `image-dired-cmd-write-exif-data-program'.
401 Available format specifiers are: %f which is replaced by
402 the image file name, %t which is replaced by the tag name and %v
403 which is replaced by the tag value."
405 :type
'(repeat (string :tag
"Argument"))
408 (defcustom image-dired-cmd-read-exif-data-program
410 "Program used to read EXIF data to image.
411 Used together with `image-dired-cmd-read-exif-data-options'."
415 (defcustom image-dired-cmd-read-exif-data-options
416 '("-s" "-s" "-s" "-%t" "%f")
417 "Arguments of command used to read EXIF data.
418 Used with `image-dired-cmd-read-exif-data-program'.
419 Available format specifiers are: %f which is replaced
420 by the image file name and %t which is replaced by the tag name."
422 :type
'(repeat (string :tag
"Argument"))
425 (defcustom image-dired-gallery-hidden-tags
426 (list "private" "hidden" "pending")
427 "List of \"hidden\" tags.
428 Used by `image-dired-gallery-generate' to leave out \"hidden\" images."
429 :type
'(repeat string
)
432 (defcustom image-dired-thumb-size
434 ((eq 'standard image-dired-thumbnail-storage
) 128)
435 ((eq 'standard-large image-dired-thumbnail-storage
) 256)
437 "Size of thumbnails, in pixels.
438 This is the default size for both `image-dired-thumb-width'
439 and `image-dired-thumb-height'."
443 (defcustom image-dired-thumb-width image-dired-thumb-size
444 "Width of thumbnails, in pixels."
448 (defcustom image-dired-thumb-height image-dired-thumb-size
449 "Height of thumbnails, in pixels."
453 (defcustom image-dired-thumb-relief
2
454 "Size of button-like border around thumbnails."
458 (defcustom image-dired-thumb-margin
2
459 "Size of the margin around thumbnails.
460 This is where you see the cursor."
464 (defcustom image-dired-line-up-method
'dynamic
465 "Default method for line-up of thumbnails in thumbnail buffer.
466 Used by `image-dired-display-thumbs' and other functions that needs
467 to line-up thumbnails. Dynamic means to use the available width of
468 the window containing the thumbnail buffer, Fixed means to use
469 `image-dired-thumbs-per-row', Interactive is for asking the user,
470 and No line-up means that no automatic line-up will be done."
471 :type
'(choice :tag
"Default line-up method"
472 (const :tag
"Dynamic" dynamic
)
473 (const :tag
"Fixed" fixed
)
474 (const :tag
"Interactive" interactive
)
475 (const :tag
"No line-up" none
))
478 (defcustom image-dired-thumbs-per-row
3
479 "Number of thumbnails to display per row in thumb buffer."
483 (defcustom image-dired-display-window-width-correction
1
484 "Number to be used to correct image display window width.
485 Change if the default (1) does not work (i.e. if the image does not
490 (defcustom image-dired-display-window-height-correction
0
491 "Number to be used to correct image display window height.
492 Change if the default (0) does not work (i.e. if the image does not
497 (defcustom image-dired-track-movement t
498 "The current state of the tracking and mirroring.
499 For more information, see the documentation for
500 `image-dired-toggle-movement-tracking'."
504 (defcustom image-dired-append-when-browsing nil
505 "Append thumbnails in thumbnail buffer when browsing.
506 If non-nil, using `image-dired-next-line-and-display' and
507 `image-dired-previous-line-and-display' will leave a trail of thumbnail
508 images in the thumbnail buffer. If you enable this and want to clean
509 the thumbnail buffer because it is filled with too many thumbnails,
510 just call `image-dired-display-thumb' to display only the image at point.
511 This value can be toggled using `image-dired-toggle-append-browsing'."
515 (defcustom image-dired-dired-disp-props t
516 "If non-nil, display properties for dired file when browsing.
517 Used by `image-dired-next-line-and-display',
518 `image-dired-previous-line-and-display' and `image-dired-mark-and-display-next'.
519 If the database file is large, this can slow down image browsing in
520 dired and you might want to turn it off."
524 (defcustom image-dired-display-properties-format
"%b: %f (%t): %c"
525 "Display format for thumbnail properties.
526 %b is replaced with associated dired buffer name, %f with file name
527 \(without path) of original image file, %t with the list of tags and %c
532 (defcustom image-dired-external-viewer
533 ;; TODO: Use mailcap, dired-guess-shell-alist-default,
534 ;; dired-view-command-alist.
535 (cond ((executable-find "display"))
536 ((executable-find "xli"))
537 ((executable-find "qiv") "qiv -t"))
538 "Name of external viewer.
539 Including parameters. Used when displaying original image from
540 `image-dired-thumbnail-mode'."
544 (defcustom image-dired-main-image-directory
"~/pics/"
545 "Name of main image directory, if any.
546 Used by `image-dired-copy-with-exif-file-name'."
550 (defcustom image-dired-show-all-from-dir-max-files
50
551 "Maximum number of files to show using `image-dired-show-all-from-dir'
552 before warning the user."
556 (defmacro image-dired--with-db-file
(&rest body
)
557 "Run BODY in a temp buffer containing `image-dired-db-file'.
558 Return the last form in BODY."
559 (declare (indent 0) (debug t
))
561 (if (file-exists-p image-dired-db-file
)
562 (insert-file-contents image-dired-db-file
))
565 (defun image-dired-dir ()
566 "Return the current thumbnails directory (from variable `image-dired-dir').
567 Create the thumbnails directory if it does not exist."
568 (let ((image-dired-dir (file-name-as-directory
569 (expand-file-name image-dired-dir
))))
570 (unless (file-directory-p image-dired-dir
)
571 (make-directory image-dired-dir t
)
572 (message "Creating thumbnails directory"))
575 (defun image-dired-insert-image (file type relief margin
)
576 "Insert image FILE of image TYPE, using RELIEF and MARGIN, at point."
577 (let ((i `(image :type
,type
583 (defun image-dired-get-thumbnail-image (file)
584 "Return the image descriptor for a thumbnail of image file FILE."
585 (unless (string-match (image-file-name-regexp) file
)
586 (error "%s is not a valid image file" file
))
587 (let* ((thumb-file (image-dired-thumb-name file
))
588 (thumb-attr (file-attributes thumb-file
)))
589 (when (or (not thumb-attr
)
590 (time-less-p (nth 5 thumb-attr
)
591 (nth 5 (file-attributes file
))))
592 (image-dired-create-thumb file thumb-file
))
593 (create-image thumb-file
)
594 ;; (list 'image :type 'jpeg
596 ;; :relief image-dired-thumb-relief :margin image-dired-thumb-margin)
599 (defun image-dired-insert-thumbnail (file original-file-name
600 associated-dired-buffer
)
601 "Insert thumbnail image FILE.
602 Add text properties ORIGINAL-FILE-NAME and ASSOCIATED-DIRED-BUFFER."
605 (image-dired-insert-image file
606 ;; TODO: this should depend on the real file type
607 (if (memq image-dired-thumbnail-storage
608 '(standard standard-large
))
610 image-dired-thumb-relief
611 image-dired-thumb-margin
)
615 (list 'image-dired-thumbnail t
616 'original-file-name original-file-name
617 'associated-dired-buffer associated-dired-buffer
618 'tags
(image-dired-list-tags original-file-name
)
619 'mouse-face
'highlight
620 'comment
(image-dired-get-comment original-file-name
)))))
622 (defun image-dired-thumb-name (file)
623 "Return thumbnail file name for FILE.
624 Depending on the value of `image-dired-thumbnail-storage', the file
625 name will vary. For central thumbnail file storage, make a
626 MD5-hash of the image file's directory name and add that to make
627 the thumbnail file name unique. For per-directory storage, just
628 add a subdirectory. For standard storage, produce the file name
629 according to the Thumbnail Managing Standard."
630 (cond ((memq image-dired-thumbnail-storage
'(standard standard-large
))
631 (let* ((xdg (getenv "XDG_CACHE_HOME"))
632 (dir (if (and xdg
(file-name-absolute-p xdg
))
634 (thumbdir (cl-case image-dired-thumbnail-storage
635 (standard "thumbnails/normal")
636 (standard-large "thumbnails/large"))))
638 (concat (md5 (concat "file://" (expand-file-name file
))) ".png")
639 (expand-file-name thumbdir dir
))))
640 ((eq 'use-image-dired-dir image-dired-thumbnail-storage
)
641 (let* ((f (expand-file-name file
))
643 ;; Is MD5 hashes fast enough? The checksum of a
644 ;; thumbnail file name need not be that
645 ;; "cryptographically" good so a faster one could
647 (md5 (file-name-as-directory (file-name-directory f
)))))
648 (format "%s%s%s.thumb.%s"
649 (file-name-as-directory (expand-file-name (image-dired-dir)))
651 (if md5-hash
(concat "_" md5-hash
) "")
652 (file-name-extension f
))))
653 ((eq 'per-directory image-dired-thumbnail-storage
)
654 (let ((f (expand-file-name file
)))
655 (format "%s.image-dired/%s.thumb.%s"
656 (file-name-directory f
)
658 (file-name-extension f
))))))
660 (defun image-dired--check-executable-exists (executable)
661 (unless (executable-find (symbol-value executable
))
662 (error "Executable %S not found" executable
)))
664 (defun image-dired-thumb-size (dimension)
665 "Return thumb size depending on `image-dired-thumbnail-storage'.
666 DIMENSION should be either the symbol 'width or 'height."
668 ((eq 'standard image-dired-thumbnail-storage
) 128)
669 ((eq 'standard-large image-dired-thumbnail-storage
) 256)
670 (t (cl-ecase dimension
671 (width image-dired-thumb-width
)
672 (height image-dired-thumb-height
)))))
674 (defvar image-dired-queue nil
675 "List of items in the queue.
676 Each item has the form (ORIGINAL-FILE TARGET-FILE).")
678 (defvar image-dired-queue-active-jobs
0
679 "Number of active jobs in `image-dired-queue'.")
681 (defvar image-dired-queue-active-limit
2
682 "Maximum number of concurrent jobs permitted for generating images.
683 Increase at own risk.")
685 (defun image-dired-pngnq-thumb (spec)
686 "Quantize thumbnail described by format SPEC with pngnq(1)."
688 (apply #'start-process
"image-dired-pngnq" nil
689 image-dired-cmd-pngnq-program
690 (mapcar (lambda (arg) (format-spec arg spec
))
691 image-dired-cmd-pngnq-options
))))
692 (setf (process-sentinel process
)
693 (lambda (process status
)
694 (if (and (eq (process-status process
) 'exit
)
695 (zerop (process-exit-status process
)))
696 ;; Pass off to pngcrush, or just rename the
697 ;; THUMB-nq8.png file back to THUMB.png
698 (if (and image-dired-cmd-pngcrush-program
699 (executable-find image-dired-cmd-pngcrush-program
))
700 (image-dired-pngcrush-thumb spec
)
701 (let ((nq8 (cdr (assq ?q spec
)))
702 (thumb (cdr (assq ?t spec
))))
703 (rename-file nq8 thumb t
)))
704 (message "command %S %s" (process-command process
)
705 (replace-regexp-in-string "\n" "" status
)))))
708 (defun image-dired-pngcrush-thumb (spec)
709 "Optimize thumbnail described by format SPEC with pngcrush(1)."
710 ;; If pngnq wasn't run, then the THUMB-nq8.png file does not exist.
711 ;; pngcrush needs an infile and outfile, so we just copy THUMB to
712 ;; THUMB-nq8.png and use the latter as a temp file.
713 (when (not image-dired-cmd-pngnq-program
)
714 (let ((temp (cdr (assq ?q spec
)))
715 (thumb (cdr (assq ?t spec
))))
716 (copy-file thumb temp
)))
718 (apply #'start-process
"image-dired-pngcrush" nil
719 image-dired-cmd-pngcrush-program
720 (mapcar (lambda (arg) (format-spec arg spec
))
721 image-dired-cmd-pngcrush-options
))))
722 (setf (process-sentinel process
)
723 (lambda (process status
)
724 (unless (and (eq (process-status process
) 'exit
)
725 (zerop (process-exit-status process
)))
726 (message "command %S %s" (process-command process
)
727 (replace-regexp-in-string "\n" "" status
)))
728 (when (memq (process-status process
) '(exit signal
))
729 (let ((temp (cdr (assq ?q spec
))))
730 (delete-file temp
)))))
733 (defun image-dired-optipng-thumb (spec)
734 "Optimize thumbnail described by format SPEC with optipng(1)."
736 (apply #'start-process
"image-dired-optipng" nil
737 image-dired-cmd-optipng-program
738 (mapcar (lambda (arg) (format-spec arg spec
))
739 image-dired-cmd-optipng-options
))))
740 (setf (process-sentinel process
)
741 (lambda (process status
)
742 (unless (and (eq (process-status process
) 'exit
)
743 (zerop (process-exit-status process
)))
744 (message "command %S %s" (process-command process
)
745 (replace-regexp-in-string "\n" "" status
)))))
748 (defun image-dired-create-thumb-1 (original-file thumbnail-file
)
749 "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE."
750 (image-dired--check-executable-exists
751 'image-dired-cmd-create-thumbnail-program
)
752 (let* ((width (int-to-string (image-dired-thumb-size 'width
)))
753 (height (int-to-string (image-dired-thumb-size 'height
)))
754 (modif-time (format-time-string
755 "%s" (nth 5 (file-attributes original-file
))))
756 (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png"
763 (cons ?f original-file
)
764 (cons ?q thumbnail-nq8-file
)
765 (cons ?t thumbnail-file
)))
766 (thumbnail-dir (file-name-directory thumbnail-file
))
768 (when (not (file-exists-p thumbnail-dir
))
769 (message "Creating thumbnail directory")
770 (make-directory thumbnail-dir t
)
771 (set-file-modes thumbnail-dir
#o700
))
773 ;; Thumbnail file creation processes begin here and are marshaled
774 ;; in a queue by `image-dired-create-thumb'.
776 (apply #'start-process
"image-dired-create-thumbnail" nil
777 image-dired-cmd-create-thumbnail-program
779 (lambda (arg) (format-spec arg spec
))
780 (if (memq image-dired-thumbnail-storage
781 '(standard standard-large
))
782 image-dired-cmd-create-standard-thumbnail-options
783 image-dired-cmd-create-thumbnail-options
))))
785 (setf (process-sentinel process
)
786 (lambda (process status
)
787 ;; Trigger next in queue once a thumbnail has been created
788 (cl-decf image-dired-queue-active-jobs
)
789 (image-dired-thumb-queue-run)
790 (if (not (and (eq (process-status process
) 'exit
)
791 (zerop (process-exit-status process
))))
792 (message "Thumb could not be created for %s: %s"
793 (abbreviate-file-name original-file
)
794 (replace-regexp-in-string "\n" "" status
))
795 (set-file-modes thumbnail-file
#o600
)
796 (clear-image-cache thumbnail-file
)
797 ;; PNG thumbnail has been created since we are
798 ;; following the XDG thumbnail spec, so try to optimize
799 (when (memq image-dired-thumbnail-storage
800 '(standard standard-large
))
802 ((and image-dired-cmd-pngnq-program
803 (executable-find image-dired-cmd-pngnq-program
))
804 (image-dired-pngnq-thumb spec
))
805 ((and image-dired-cmd-pngcrush-program
806 (executable-find image-dired-cmd-pngcrush-program
))
807 (image-dired-pngcrush-thumb spec
))
808 ((and image-dired-cmd-optipng-program
809 (executable-find image-dired-cmd-optipng-program
))
810 (image-dired-optipng-thumb spec
)))))))
813 (defun image-dired-thumb-queue-run ()
814 "Run a queued job if one exists and not too many jobs are running.
815 Queued items live in `image-dired-queue'."
816 (while (and image-dired-queue
817 (< image-dired-queue-active-jobs
818 image-dired-queue-active-limit
))
819 (cl-incf image-dired-queue-active-jobs
)
820 (apply #'image-dired-create-thumb-1
(pop image-dired-queue
))))
822 (defun image-dired-create-thumb (original-file thumbnail-file
)
823 "Add a job for generating thumbnail to `image-dired-queue'."
824 (setq image-dired-queue
825 (nconc image-dired-queue
826 (list (list original-file thumbnail-file
))))
827 (run-at-time 0 nil
#'image-dired-thumb-queue-run
))
830 (defun image-dired-dired-toggle-marked-thumbs (&optional arg
)
831 "Toggle thumbnails in front of file names in the dired buffer.
832 If no marked file could be found, insert or hide thumbnails on the
833 current line. ARG, if non-nil, specifies the files to use instead
834 of the marked files. If ARG is an integer, use the next ARG (or
835 previous -ARG, if ARG<0) files."
837 (dired-map-over-marks
838 (let ((image-pos (dired-move-to-filename))
839 (image-file (dired-get-filename nil t
))
842 (when (and image-file
843 (string-match-p (image-file-name-regexp) image-file
))
844 (setq thumb-file
(image-dired-get-thumbnail-image image-file
))
845 ;; If image is not already added, then add it.
846 (let ((thumb-ov (cl-loop for ov in
(overlays-in (point) (1+ (point)))
847 if
(overlay-get ov
'thumb-file
) return ov
)))
849 (delete-overlay thumb-ov
)
850 (put-image thumb-file image-pos
)
852 (cl-loop for ov in
(overlays-in (point) (1+ (point)))
853 if
(overlay-get ov
'put-image
) return ov
))
854 (overlay-put overlay
'image-file image-file
)
855 (overlay-put overlay
'thumb-file thumb-file
)))))
856 arg
; Show or hide image on ARG next files.
857 'show-progress
) ; Update dired display after each image is updated.
858 (add-hook 'dired-after-readin-hook
859 'image-dired-dired-after-readin-hook nil t
))
861 (defun image-dired-dired-after-readin-hook ()
862 "Relocate existing thumbnail overlays in dired buffer after reverting.
863 Move them to their corresponding files if they still exist.
864 Otherwise, delete overlays."
865 (mapc (lambda (overlay)
866 (when (overlay-get overlay
'put-image
)
867 (let* ((image-file (overlay-get overlay
'image-file
))
868 (image-pos (dired-goto-file image-file
)))
870 (move-overlay overlay image-pos image-pos
)
871 (delete-overlay overlay
)))))
872 (overlays-in (point-min) (point-max))))
874 (defun image-dired-next-line-and-display ()
875 "Move to next dired line and display thumbnail image."
878 (image-dired-display-thumbs
879 t
(or image-dired-append-when-browsing nil
) t
)
880 (if image-dired-dired-disp-props
881 (image-dired-dired-display-properties)))
883 (defun image-dired-previous-line-and-display ()
884 "Move to previous dired line and display thumbnail image."
886 (dired-previous-line 1)
887 (image-dired-display-thumbs
888 t
(or image-dired-append-when-browsing nil
) t
)
889 (if image-dired-dired-disp-props
890 (image-dired-dired-display-properties)))
892 (defun image-dired-toggle-append-browsing ()
893 "Toggle `image-dired-append-when-browsing'."
895 (setq image-dired-append-when-browsing
896 (not image-dired-append-when-browsing
))
897 (message "Append browsing %s."
898 (if image-dired-append-when-browsing
902 (defun image-dired-mark-and-display-next ()
903 "Mark current file in dired and display next thumbnail image."
906 (image-dired-display-thumbs
907 t
(or image-dired-append-when-browsing nil
) t
)
908 (if image-dired-dired-disp-props
909 (image-dired-dired-display-properties)))
911 (defun image-dired-toggle-dired-display-properties ()
912 "Toggle `image-dired-dired-disp-props'."
914 (setq image-dired-dired-disp-props
915 (not image-dired-dired-disp-props
))
916 (message "Dired display properties %s."
917 (if image-dired-dired-disp-props
921 (defvar image-dired-thumbnail-buffer
"*image-dired*"
922 "Image-Dired's thumbnail buffer.")
924 (defun image-dired-create-thumbnail-buffer ()
925 "Create thumb buffer and set `image-dired-thumbnail-mode'."
926 (let ((buf (get-buffer-create image-dired-thumbnail-buffer
)))
927 (with-current-buffer buf
928 (setq buffer-read-only t
)
929 (if (not (eq major-mode
'image-dired-thumbnail-mode
))
930 (image-dired-thumbnail-mode)))
933 (defvar image-dired-display-image-buffer
"*image-dired-display-image*"
934 "Where larger versions of the images are display.")
936 (defun image-dired-create-display-image-buffer ()
937 "Create image display buffer and set `image-dired-display-image-mode'."
938 (let ((buf (get-buffer-create image-dired-display-image-buffer
)))
939 (with-current-buffer buf
940 (setq buffer-read-only t
)
941 (if (not (eq major-mode
'image-dired-display-image-mode
))
942 (image-dired-display-image-mode)))
945 (defvar image-dired-saved-window-configuration nil
946 "Saved window configuration.")
949 (defun image-dired-dired-with-window-configuration (dir &optional arg
)
950 "Open directory DIR and create a default window configuration.
952 Convenience command that:
954 - Opens dired in folder DIR
955 - Splits windows in most useful (?) way
956 - Set `truncate-lines' to t
958 After the command has finished, you would typically mark some
959 image files in dired and type
960 \\[image-dired-display-thumbs] (`image-dired-display-thumbs').
962 If called with prefix argument ARG, skip splitting of windows.
964 The current window configuration is saved and can be restored by
965 calling `image-dired-restore-window-configuration'."
966 (interactive "DDirectory: \nP")
967 (let ((buf (image-dired-create-thumbnail-buffer))
968 (buf2 (image-dired-create-display-image-buffer)))
969 (setq image-dired-saved-window-configuration
970 (current-window-configuration))
972 (delete-other-windows)
975 (setq truncate-lines t
)
978 (pop-to-buffer-same-window buf
)
979 (select-window (split-window-below))
980 (pop-to-buffer-same-window buf2
)
981 (other-window -
2)))))
983 (defun image-dired-restore-window-configuration ()
984 "Restore window configuration.
985 Restore any changes to the window configuration made by calling
986 `image-dired-dired-with-window-configuration'."
988 (if image-dired-saved-window-configuration
989 (set-window-configuration image-dired-saved-window-configuration
)
990 (message "No saved window configuration")))
993 (defun image-dired-display-thumbs (&optional arg append do-not-pop
)
994 "Display thumbnails of all marked files, in `image-dired-thumbnail-buffer'.
995 If a thumbnail image does not exist for a file, it is created on the
996 fly. With prefix argument ARG, display only thumbnail for file at
997 point (this is useful if you have marked some files but want to show
1000 Recommended usage is to split the current frame horizontally so that
1001 you have the dired buffer in the left window and the
1002 `image-dired-thumbnail-buffer' buffer in the right window.
1004 With optional argument APPEND, append thumbnail to thumbnail buffer
1005 instead of erasing it first.
1007 Optional argument DO-NOT-POP controls if `pop-to-buffer' should be
1008 used or not. If non-nil, use `display-buffer' instead of
1009 `pop-to-buffer'. This is used from functions like
1010 `image-dired-next-line-and-display' and
1011 `image-dired-previous-line-and-display' where we do not want the
1012 thumbnail buffer to be selected."
1014 (let ((buf (image-dired-create-thumbnail-buffer))
1015 thumb-name files dired-buf
)
1017 (setq files
(list (dired-get-filename)))
1018 (setq files
(dired-get-marked-files)))
1019 (setq dired-buf
(current-buffer))
1020 (with-current-buffer buf
1021 (let ((inhibit-read-only t
))
1024 (goto-char (point-max)))
1025 (dolist (curr-file files
)
1026 (setq thumb-name
(image-dired-thumb-name curr-file
))
1027 (when (not (file-exists-p thumb-name
))
1028 (image-dired-create-thumb curr-file thumb-name
))
1029 (image-dired-insert-thumbnail thumb-name curr-file dired-buf
)))
1031 (display-buffer buf
)
1032 (pop-to-buffer buf
))
1033 (cond ((eq 'dynamic image-dired-line-up-method
)
1034 (image-dired-line-up-dynamic))
1035 ((eq 'fixed image-dired-line-up-method
)
1036 (image-dired-line-up))
1037 ((eq 'interactive image-dired-line-up-method
)
1038 (image-dired-line-up-interactive))
1039 ((eq 'none image-dired-line-up-method
)
1042 (image-dired-line-up-dynamic))))))
1045 (defun image-dired-show-all-from-dir (dir)
1046 "Make a preview buffer for all images in DIR and display it.
1047 If the number of files in DIR matching `image-file-name-regexp'
1048 exceeds `image-dired-show-all-from-dir-max-files', a warning will be
1050 (interactive "DImage Dired: ")
1052 (dired-mark-files-regexp (image-file-name-regexp))
1053 (let ((files (dired-get-marked-files)))
1054 (if (or (<= (length files
) image-dired-show-all-from-dir-max-files
)
1055 (and (> (length files
) image-dired-show-all-from-dir-max-files
)
1058 "Directory contains more than %d image files. Proceed? "
1059 image-dired-show-all-from-dir-max-files
))))
1061 (image-dired-display-thumbs)
1062 (pop-to-buffer image-dired-thumbnail-buffer
))
1063 (message "Canceled."))))
1066 (defalias 'image-dired
'image-dired-show-all-from-dir
)
1069 (define-obsolete-function-alias 'tumme
'image-dired
"24.4")
1071 (defun image-dired-sane-db-file ()
1072 "Check if `image-dired-db-file' exists.
1073 If not, try to create it (including any parent directories).
1074 Signal error if there are problems creating it."
1075 (or (file-exists-p image-dired-db-file
)
1077 (unless (file-directory-p (setq dir
(file-name-directory
1078 image-dired-db-file
)))
1079 (make-directory dir t
))
1080 (with-current-buffer (setq buf
(create-file-buffer
1081 image-dired-db-file
))
1082 (write-file image-dired-db-file
))
1084 (file-exists-p image-dired-db-file
))
1085 (error "Could not create %s" image-dired-db-file
)))
1087 (defun image-dired-write-tags (file-tags)
1088 "Write file tags to database.
1089 Write each file and tag in FILE-TAGS to the database.
1090 FILE-TAGS is an alist in the following form:
1091 ((FILE . TAG) ... )"
1092 (image-dired-sane-db-file)
1094 (image-dired--with-db-file
1095 (setq buffer-file-name image-dired-db-file
)
1096 (dolist (elt file-tags
)
1097 (setq file
(car elt
)
1099 (goto-char (point-min))
1100 (if (search-forward-regexp (format "^%s.*$" file
) nil t
)
1104 (when (not (search-forward (format ";%s" tag
) end t
))
1106 (insert (format ";%s" tag
))))
1107 (goto-char (point-max))
1108 (insert (format "\n%s;%s" file tag
))))
1111 (defun image-dired-remove-tag (files tag
)
1112 "For all FILES, remove TAG from the image database."
1113 (image-dired-sane-db-file)
1114 (image-dired--with-db-file
1115 (setq buffer-file-name image-dired-db-file
)
1117 (unless (listp files
)
1119 (setq files
(list files
))
1120 (error "Files must be a string or a list of strings!")))
1121 (dolist (file files
)
1122 (goto-char (point-min))
1123 (when (search-forward-regexp (format "^%s" file
) nil t
)
1127 (when (search-forward-regexp (format "\\(;%s\\)" tag
) end t
)
1128 (delete-region (match-beginning 1) (match-end 1))
1129 ;; Check if file should still be in the database. If
1130 ;; it has no tags or comments, it will be removed.
1134 (when (not (search-forward ";" end t
))
1136 ;; If on empty line at end of buffer
1139 (delete-char -
1)))))))
1142 (defun image-dired-list-tags (file)
1143 "Read all tags for image FILE from the image database."
1144 (image-dired-sane-db-file)
1145 (image-dired--with-db-file
1146 (let (end (tags ""))
1147 (when (search-forward-regexp (format "^%s" file
) nil t
)
1151 (if (search-forward ";" end t
)
1152 (if (search-forward "comment:" end t
)
1153 (if (search-forward ";" end t
)
1154 (setq tags
(buffer-substring (point) end
)))
1155 (setq tags
(buffer-substring (point) end
)))))
1156 (split-string tags
";"))))
1159 (defun image-dired-tag-files (arg)
1160 "Tag marked file(s) in dired. With prefix ARG, tag file at point."
1162 (let ((tag (read-string "Tags to add (separate tags with a semicolon): "))
1165 (setq files
(list (dired-get-filename)))
1166 (setq files
(dired-get-marked-files)))
1167 (image-dired-write-tags
1173 (defun image-dired-tag-thumbnail ()
1174 "Tag current thumbnail."
1176 (let ((tag (read-string "Tags to add (separate tags with a semicolon): ")))
1177 (image-dired-write-tags (list (cons (image-dired-original-file-name) tag
))))
1178 (image-dired-update-property
1179 'tags
(image-dired-list-tags (image-dired-original-file-name))))
1182 (defun image-dired-delete-tag (arg)
1183 "Remove tag for selected file(s).
1184 With prefix argument ARG, remove tag from file at point."
1186 (let ((tag (read-string "Tag to remove: "))
1189 (setq files
(list (dired-get-filename)))
1190 (setq files
(dired-get-marked-files)))
1191 (image-dired-remove-tag files tag
)))
1193 (defun image-dired-tag-thumbnail-remove ()
1194 "Remove tag from thumbnail."
1196 (let ((tag (read-string "Tag to remove: ")))
1197 (image-dired-remove-tag (image-dired-original-file-name) tag
))
1198 (image-dired-update-property
1199 'tags
(image-dired-list-tags (image-dired-original-file-name))))
1201 (defun image-dired-original-file-name ()
1202 "Get original file name for thumbnail or display image at point."
1203 (get-text-property (point) 'original-file-name
))
1205 (defun image-dired-file-name-at-point ()
1206 "Get abbreviated file name for thumbnail or display image at point."
1207 (let ((f (image-dired-original-file-name)))
1209 (abbreviate-file-name f
))))
1211 (defun image-dired-associated-dired-buffer ()
1212 "Get associated dired buffer at point."
1213 (get-text-property (point) 'associated-dired-buffer
))
1215 (defun image-dired-get-buffer-window (buf)
1216 "Return window where buffer BUF is."
1217 (get-window-with-predicate
1219 (equal (window-buffer window
) buf
))
1222 (defun image-dired-track-original-file ()
1223 "Track the original file in the associated dired buffer.
1224 See documentation for `image-dired-toggle-movement-tracking'.
1225 Interactive use only useful if `image-dired-track-movement' is nil."
1227 (let* ((dired-buf (image-dired-associated-dired-buffer))
1228 (file-name (image-dired-original-file-name))
1229 (window (image-dired-get-buffer-window dired-buf
)))
1230 (and (buffer-live-p dired-buf
) file-name
1231 (with-current-buffer dired-buf
1232 (if (not (dired-goto-file file-name
))
1233 (message "Could not track file")
1234 (if window
(set-window-point window
(point))))))))
1236 (defun image-dired-toggle-movement-tracking ()
1237 "Turn on and off `image-dired-track-movement'.
1238 Tracking of the movements between thumbnail and dired buffer so that
1239 they are \"mirrored\" in the dired buffer. When this is on, moving
1240 around in the thumbnail or dired buffer will find the matching
1241 position in the other buffer."
1243 (setq image-dired-track-movement
(not image-dired-track-movement
))
1244 (message "Tracking %s" (if image-dired-track-movement
"on" "off")))
1246 (defun image-dired-track-thumbnail ()
1247 "Track current dired file's thumb in `image-dired-thumbnail-buffer'.
1248 This is almost the same as what `image-dired-track-original-file' does,
1249 but the other way around."
1250 (let ((file (dired-get-filename))
1251 prop-val found window
)
1252 (when (get-buffer image-dired-thumbnail-buffer
)
1253 (with-current-buffer image-dired-thumbnail-buffer
1254 (goto-char (point-min))
1255 (while (and (not (eobp))
1257 (if (and (setq prop-val
1258 (get-text-property (point) 'original-file-name
))
1259 (string= prop-val file
))
1264 (if (setq window
(image-dired-thumbnail-window))
1265 (set-window-point window
(point)))
1266 (image-dired-display-thumb-properties))))))
1268 (defun image-dired-dired-next-line (&optional arg
)
1269 "Call `dired-next-line', then track thumbnail.
1270 This can safely replace `dired-next-line'.
1271 With prefix argument, move ARG lines."
1273 (dired-next-line (or arg
1))
1274 (if image-dired-track-movement
1275 (image-dired-track-thumbnail)))
1277 (defun image-dired-dired-previous-line (&optional arg
)
1278 "Call `dired-previous-line', then track thumbnail.
1279 This can safely replace `dired-previous-line'.
1280 With prefix argument, move ARG lines."
1282 (dired-previous-line (or arg
1))
1283 (if image-dired-track-movement
1284 (image-dired-track-thumbnail)))
1286 (defun image-dired-forward-image (&optional arg
)
1287 "Move to next image and display properties.
1288 Optional prefix ARG says how many images to move; default is one
1291 (let (pos (steps (or arg
1)))
1293 (if (and (not (eobp))
1296 (while (and (not (eobp))
1297 (not (image-dired-image-at-point-p)))
1300 (image-dired-image-at-point-p)))
1302 (error "At last image"))))
1303 (when image-dired-track-movement
1304 (image-dired-track-original-file))
1305 (image-dired-display-thumb-properties))
1307 (defun image-dired-backward-image (&optional arg
)
1308 "Move to previous image and display properties.
1309 Optional prefix ARG says how many images to move; default is one
1312 (let (pos (steps (or arg
1)))
1314 (if (and (not (bobp))
1317 (while (and (not (bobp))
1318 (not (image-dired-image-at-point-p)))
1321 (image-dired-image-at-point-p)))
1323 (error "At first image"))))
1324 (when image-dired-track-movement
1325 (image-dired-track-original-file))
1326 (image-dired-display-thumb-properties))
1328 (defun image-dired-next-line ()
1329 "Move to next line and display properties."
1331 (let ((goal-column (current-column)))
1333 (move-to-column goal-column
))
1334 ;; If we end up in an empty spot, back up to the next thumbnail.
1335 (if (not (image-dired-image-at-point-p))
1336 (image-dired-backward-image))
1337 (if image-dired-track-movement
1338 (image-dired-track-original-file))
1339 (image-dired-display-thumb-properties))
1342 (defun image-dired-previous-line ()
1343 "Move to previous line and display properties."
1345 (let ((goal-column (current-column)))
1347 (move-to-column goal-column
))
1348 ;; If we end up in an empty spot, back up to the next
1349 ;; thumbnail. This should only happen if the user deleted a
1350 ;; thumbnail and did not refresh, so it is not very common. But we
1351 ;; can handle it in a good manner, so why not?
1352 (if (not (image-dired-image-at-point-p))
1353 (image-dired-backward-image))
1354 (if image-dired-track-movement
1355 (image-dired-track-original-file))
1356 (image-dired-display-thumb-properties))
1358 (defun image-dired-format-properties-string (buf file props comment
)
1359 "Format display properties.
1360 BUF is the associated dired buffer, FILE is the original image file
1361 name, PROPS is a stringified list of tags and COMMENT is the image file's
1364 image-dired-display-properties-format
1366 (cons ?b
(or buf
""))
1368 (cons ?t
(or props
""))
1369 (cons ?c
(or comment
"")))))
1371 (defun image-dired-display-thumb-properties ()
1372 "Display thumbnail properties in the echo area."
1374 (let ((file-name (file-name-nondirectory (image-dired-original-file-name)))
1375 (dired-buf (buffer-name (image-dired-associated-dired-buffer)))
1376 (props (mapconcat #'identity
(get-text-property (point) 'tags
) ", "))
1377 (comment (get-text-property (point) 'comment
))
1378 (message-log-max nil
))
1381 (image-dired-format-properties-string
1387 (defun image-dired-dired-file-marked-p ()
1388 "Check whether file on current line is marked or not."
1391 (not (looking-at "^ .*$"))))
1393 (defun image-dired-modify-mark-on-thumb-original-file (command)
1394 "Modify mark in dired buffer.
1395 COMMAND is one of `mark' for marking file in dired, `unmark' for
1396 unmarking file in dired or `flag' for flagging file for delete in
1398 (let ((file-name (image-dired-original-file-name))
1399 (dired-buf (image-dired-associated-dired-buffer)))
1400 (if (not (and dired-buf file-name
))
1401 (message "No image, or image with correct properties, at point.")
1402 (with-current-buffer dired-buf
1403 (message "%s" file-name
)
1404 (if (dired-goto-file file-name
)
1405 (cond ((eq command
'mark
) (dired-mark 1))
1406 ((eq command
'unmark
) (dired-unmark 1))
1407 ((eq command
'toggle
)
1408 (if (image-dired-dired-file-marked-p)
1411 ((eq command
'flag
) (dired-flag-file-deletion 1))))))))
1413 (defun image-dired-mark-thumb-original-file ()
1414 "Mark original image file in associated dired buffer."
1416 (image-dired-modify-mark-on-thumb-original-file 'mark
)
1417 (image-dired-forward-image))
1419 (defun image-dired-unmark-thumb-original-file ()
1420 "Unmark original image file in associated dired buffer."
1422 (image-dired-modify-mark-on-thumb-original-file 'unmark
)
1423 (image-dired-forward-image))
1425 (defun image-dired-flag-thumb-original-file ()
1426 "Flag original image file for deletion in associated dired buffer."
1428 (image-dired-modify-mark-on-thumb-original-file 'flag
)
1429 (image-dired-forward-image))
1431 (defun image-dired-toggle-mark-thumb-original-file ()
1432 "Toggle mark on original image file in associated dired buffer."
1434 (image-dired-modify-mark-on-thumb-original-file 'toggle
))
1436 (defun image-dired-jump-original-dired-buffer ()
1437 "Jump to the dired buffer associated with the current image file.
1438 You probably want to use this together with
1439 `image-dired-track-original-file'."
1441 (let ((buf (image-dired-associated-dired-buffer))
1443 (setq window
(image-dired-get-buffer-window buf
))
1446 (if (not (equal (selected-frame) (setq frame
(window-frame window
))))
1447 (select-frame-set-input-focus frame
))
1448 (select-window window
))
1449 (message "Associated dired buffer not visible"))))
1452 (defun image-dired-jump-thumbnail-buffer ()
1453 "Jump to thumbnail buffer."
1455 (let ((window (image-dired-thumbnail-window))
1459 (if (not (equal (selected-frame) (setq frame
(window-frame window
))))
1460 (select-frame-set-input-focus frame
))
1461 (select-window window
))
1462 (message "Thumbnail buffer not visible"))))
1464 (defvar image-dired-thumbnail-mode-line-up-map
1465 (let ((map (make-sparse-keymap)))
1466 ;; map it to "g" so that the user can press it more quickly
1467 (define-key map
"g" 'image-dired-line-up-dynamic
)
1468 ;; "f" for "fixed" number of thumbs per row
1469 (define-key map
"f" 'image-dired-line-up
)
1470 ;; "i" for "interactive"
1471 (define-key map
"i" 'image-dired-line-up-interactive
)
1473 "Keymap for line-up commands in `image-dired-thumbnail-mode'.")
1475 (defvar image-dired-thumbnail-mode-tag-map
1476 (let ((map (make-sparse-keymap)))
1477 ;; map it to "t" so that the user can press it more quickly
1478 (define-key map
"t" 'image-dired-tag-thumbnail
)
1480 (define-key map
"r" 'image-dired-tag-thumbnail-remove
)
1482 "Keymap for tag commands in `image-dired-thumbnail-mode'.")
1484 (defvar image-dired-thumbnail-mode-map
1485 (let ((map (make-sparse-keymap)))
1486 (define-key map
[right] 'image-dired-forward-image)
1487 (define-key map [left] 'image-dired-backward-image)
1488 (define-key map [up] 'image-dired-previous-line)
1489 (define-key map [down] 'image-dired-next-line)
1490 (define-key map "\C-f" 'image-dired-forward-image)
1491 (define-key map "\C-b" 'image-dired-backward-image)
1492 (define-key map "\C-p" 'image-dired-previous-line)
1493 (define-key map "\C-n" 'image-dired-next-line)
1495 (define-key map "d" 'image-dired-flag-thumb-original-file)
1496 (define-key map [delete] 'image-dired-flag-thumb-original-file)
1497 (define-key map "m" 'image-dired-mark-thumb-original-file)
1498 (define-key map "u" 'image-dired-unmark-thumb-original-file)
1499 (define-key map "." 'image-dired-track-original-file)
1500 (define-key map [tab] 'image-dired-jump-original-dired-buffer)
1503 (define-key map "g" image-dired-thumbnail-mode-line-up-map)
1505 (define-key map "t" image-dired-thumbnail-mode-tag-map)
1507 (define-key map "\C-m" 'image-dired-display-thumbnail-original-image)
1508 (define-key map [C-return] 'image-dired-thumbnail-display-external)
1510 (define-key map "l" 'image-dired-rotate-thumbnail-left)
1511 (define-key map "r" 'image-dired-rotate-thumbnail-right)
1512 (define-key map "L" 'image-dired-rotate-original-left)
1513 (define-key map "R" 'image-dired-rotate-original-right)
1515 (define-key map "D" 'image-dired-thumbnail-set-image-description)
1516 (define-key map "\C-d" 'image-dired-delete-char)
1517 (define-key map " " 'image-dired-display-next-thumbnail-original)
1518 (define-key map (kbd "DEL") 'image-dired-display-previous-thumbnail-original)
1519 (define-key map "c" 'image-dired-comment-thumbnail)
1522 (define-key map [mouse-2] 'image-dired-mouse-display-image)
1523 (define-key map [mouse-1] 'image-dired-mouse-select-thumbnail)
1524 ;; Seems I must first set C-down-mouse-1 to undefined, or else it
1525 ;; will trigger the buffer menu. If I try to instead bind
1526 ;; C-down-mouse-1 to `image-dired-mouse-toggle-mark', I get a message
1527 ;; about C-mouse-1 not being defined afterwards. Annoying, but I
1528 ;; probably do not completely understand mouse events.
1529 (define-key map [C-down-mouse-1] 'undefined)
1530 (define-key map [C-mouse-1] 'image-dired-mouse-toggle-mark)
1533 (easy-menu-define nil map
1534 "Menu for `image-dired-thumbnail-mode'."
1536 ["Quit" quit-window]
1537 ["Delete thumbnail from buffer" image-dired-delete-char]
1538 ["Remove tag from thumbnail" image-dired-tag-thumbnail-remove]
1539 ["Tag thumbnail" image-dired-tag-thumbnail]
1540 ["Comment thumbnail" image-dired-comment-thumbnail]
1541 ["Refresh thumb" image-dired-refresh-thumb]
1542 ["Dynamic line up" image-dired-line-up-dynamic]
1543 ["Line up thumbnails" image-dired-line-up]
1545 ["Rotate thumbnail left" image-dired-rotate-thumbnail-left]
1546 ["Rotate thumbnail right" image-dired-rotate-thumbnail-right]
1547 ["Rotate original left" image-dired-rotate-original-left]
1548 ["Rotate original right" image-dired-rotate-original-right]
1550 ["Toggle movement tracking on/off" image-dired-toggle-movement-tracking]
1552 ["Jump to dired buffer" image-dired-jump-original-dired-buffer]
1553 ["Track original" image-dired-track-original-file]
1555 ["Flag original for deletion" image-dired-flag-thumb-original-file]
1556 ["Unmark original" image-dired-unmark-thumb-original-file]
1557 ["Mark original" image-dired-mark-thumb-original-file]
1559 ["Display in external viewer" image-dired-thumbnail-display-external]
1560 ["Display image" image-dired-display-thumbnail-original-image]))
1562 "Keymap for `image-dired-thumbnail-mode'.")
1564 (defvar image-dired-display-image-mode-map
1565 (let ((map (make-sparse-keymap)))
1566 ;; `image-mode-map' has bindings that do not make sense in image-dired
1567 ;; (set-keymap-parent map image-mode-map)
1568 (define-key map "f" 'image-dired-display-current-image-full)
1569 (define-key map "s" 'image-dired-display-current-image-sized)
1570 (define-key map "g" nil)
1572 ;; Useful bindings from `image-mode-map'
1573 (define-key map [remap forward-char] 'image-forward-hscroll)
1574 (define-key map [remap backward-char] 'image-backward-hscroll)
1575 (define-key map [remap right-char] 'image-forward-hscroll)
1576 (define-key map [remap left-char] 'image-backward-hscroll)
1577 (define-key map [remap previous-line] 'image-previous-line)
1578 (define-key map [remap next-line] 'image-next-line)
1579 (define-key map [remap scroll-up] 'image-scroll-up)
1580 (define-key map [remap scroll-down] 'image-scroll-down)
1581 (define-key map [remap scroll-up-command] 'image-scroll-up)
1582 (define-key map [remap scroll-down-command] 'image-scroll-down)
1583 (define-key map [remap scroll-left] 'image-scroll-left)
1584 (define-key map [remap scroll-right] 'image-scroll-right)
1585 (define-key map [remap move-beginning-of-line] 'image-bol)
1586 (define-key map [remap move-end-of-line] 'image-eol)
1587 (define-key map [remap beginning-of-buffer] 'image-bob)
1588 (define-key map [remap end-of-buffer] 'image-eob)
1590 (easy-menu-define nil map
1591 "Menu for `image-dired-display-image-mode-map'."
1593 ["Quit" quit-window]
1594 ["Display original, sized to fit" image-dired-display-current-image-sized]
1595 ["Display original, full size" image-dired-display-current-image-full]))
1597 "Keymap for `image-dired-display-image-mode'.")
1599 (defun image-dired-display-current-image-full ()
1600 "Display current image in full size."
1602 (let ((file (image-dired-original-file-name)))
1605 (image-dired-display-image file t)
1606 (message "Full size image displayed"))
1607 (error "No original file name at point"))))
1609 (defun image-dired-display-current-image-sized ()
1610 "Display current image in sized to fit window dimensions."
1612 (let ((file (image-dired-original-file-name)))
1615 (image-dired-display-image file)
1616 (message "Fitted image displayed"))
1617 (error "No original file name at point"))))
1619 (define-derived-mode image-dired-thumbnail-mode
1620 special-mode "image-dired-thumbnail"
1621 "Browse and manipulate thumbnail images using dired.
1622 Use `image-dired-minor-mode' to get a nice setup."
1624 (buffer-disable-undo)
1625 (add-hook 'file-name-at-point-functions 'image-dired-file-name-at-point nil t))
1627 (define-derived-mode image-dired-display-image-mode
1628 special-mode "image-dired-image-display"
1629 "Mode for displaying and manipulating original image.
1630 Resized or in full-size."
1632 (buffer-disable-undo)
1633 (image-mode-setup-winprops)
1634 (setq cursor-type nil)
1635 (add-hook 'file-name-at-point-functions 'image-dired-file-name-at-point nil t))
1637 (defvar image-dired-minor-mode-map
1638 (let ((map (make-sparse-keymap)))
1639 ;; (set-keymap-parent map dired-mode-map)
1640 ;; Hijack previous and next line movement. Let C-p and C-b be
1642 (define-key map "p" 'image-dired-dired-previous-line)
1643 (define-key map "n" 'image-dired-dired-next-line)
1644 (define-key map [up] 'image-dired-dired-previous-line)
1645 (define-key map [down] 'image-dired-dired-next-line)
1647 (define-key map (kbd "C-S-n") 'image-dired-next-line-and-display)
1648 (define-key map (kbd "C-S-p") 'image-dired-previous-line-and-display)
1649 (define-key map (kbd "C-S-m") 'image-dired-mark-and-display-next)
1651 (define-key map "\C-td" 'image-dired-display-thumbs)
1652 (define-key map [tab] 'image-dired-jump-thumbnail-buffer)
1653 (define-key map "\C-ti" 'image-dired-dired-display-image)
1654 (define-key map "\C-tx" 'image-dired-dired-display-external)
1655 (define-key map "\C-ta" 'image-dired-display-thumbs-append)
1656 (define-key map "\C-t." 'image-dired-display-thumb)
1657 (define-key map "\C-tc" 'image-dired-dired-comment-files)
1658 (define-key map "\C-tf" 'image-dired-mark-tagged-files)
1661 (easy-menu-define nil map
1662 "Menu for `image-dired-minor-mode'."
1664 ["Copy with EXIF file name" image-dired-copy-with-exif-file-name]
1665 ["Comment files" image-dired-dired-comment-files]
1666 ["Mark tagged files" image-dired-mark-tagged-files]
1667 ["Jump to thumbnail buffer" image-dired-jump-thumbnail-buffer]
1669 ["Toggle movement tracking" image-dired-toggle-movement-tracking]
1670 ["Toggle append browsing" image-dired-toggle-append-browsing]
1671 ["Toggle display properties" image-dired-toggle-dired-display-properties]
1673 ["Display in external viewer" image-dired-dired-display-external]
1674 ["Display image" image-dired-dired-display-image]
1675 ["Display this thumbnail" image-dired-display-thumb]
1676 ["Display thumbnails append" image-dired-display-thumbs-append]
1678 ["Create thumbnails for marked files" image-dired-create-thumbs]
1680 ["Mark and display next" image-dired-mark-and-display-next]
1681 ["Display thumb for previous file" image-dired-previous-line-and-display]
1682 ["Display thumb for next file" image-dired-next-line-and-display]))
1684 "Keymap for `image-dired-minor-mode'.")
1687 (define-minor-mode image-dired-minor-mode
1688 "Setup easy-to-use keybindings for the commands to be used in dired mode.
1689 Note that n, p and <down> and <up> will be hijacked and bound to
1690 `image-dired-dired-x-line'."
1691 :keymap image-dired-minor-mode-map)
1694 (define-obsolete-function-alias 'image-dired-setup-dired-keybindings 'image-dired-minor-mode
1697 (declare-function clear-image-cache "image.c" (&optional filter))
1699 (defun image-dired-create-thumbs (&optional arg)
1700 "Create thumbnail images for all marked files in dired.
1701 With prefix argument ARG, create thumbnails even if they already exist
1702 \(i.e. use this to refresh your thumbnails)."
1705 (dolist (curr-file (dired-get-marked-files))
1706 (setq thumb-name (image-dired-thumb-name curr-file))
1707 ;; If the user overrides the exist check, we must clear the
1708 ;; image cache so that if the user wants to display the
1709 ;; thumbnail, it is not fetched from cache.
1711 (clear-image-cache (expand-file-name thumb-name)))
1712 (when (or (not (file-exists-p thumb-name))
1714 (image-dired-create-thumb curr-file thumb-name)))))
1716 (defvar image-dired-slideshow-timer nil
1719 (defvar image-dired-slideshow-count 0
1720 "Keeping track on number of images in slideshow.")
1722 (defvar image-dired-slideshow-times 0
1723 "Number of pictures to display in slideshow.")
1725 (defun image-dired-slideshow-step ()
1726 "Step to next file, if `image-dired-slideshow-times' has not been reached."
1727 (if (< image-dired-slideshow-count image-dired-slideshow-times)
1729 (message "%s" (1+ image-dired-slideshow-count))
1730 (setq image-dired-slideshow-count (1+ image-dired-slideshow-count))
1731 (image-dired-next-line-and-display))
1732 (image-dired-slideshow-stop)))
1734 (defun image-dired-slideshow-start ()
1736 Ask user for number of images to show and the delay in between."
1738 (setq image-dired-slideshow-count 0)
1739 (setq image-dired-slideshow-times (string-to-number (read-string "How many: ")))
1740 (let ((repeat (string-to-number
1742 "Delay, in seconds. Decimals are accepted : " "1"))))
1743 (setq image-dired-slideshow-timer
1746 'image-dired-slideshow-step))))
1748 (defun image-dired-slideshow-stop ()
1751 (cancel-timer image-dired-slideshow-timer))
1753 (defun image-dired-delete-char ()
1754 "Remove current thumbnail from thumbnail buffer and line up."
1756 (let ((inhibit-read-only t))
1758 (when (= (following-char) ?\s)
1762 (defun image-dired-display-thumbs-append ()
1763 "Append thumbnails to `image-dired-thumbnail-buffer'."
1765 (image-dired-display-thumbs nil t t))
1768 (defun image-dired-display-thumb ()
1769 "Shorthand for `image-dired-display-thumbs' with prefix argument."
1771 (image-dired-display-thumbs t nil t))
1773 (defun image-dired-line-up ()
1774 "Line up thumbnails according to `image-dired-thumbs-per-row'.
1775 See also `image-dired-line-up-dynamic'."
1777 (let ((inhibit-read-only t))
1778 (goto-char (point-min))
1779 (while (and (not (image-dired-image-at-point-p))
1784 (while (and (not (image-dired-image-at-point-p))
1787 (goto-char (point-min))
1791 (if (= image-dired-thumbs-per-row 1)
1794 (setq count (1+ count))
1795 (when (and (= count (- image-dired-thumbs-per-row 1))
1800 (goto-char (point-min))))
1802 (defun image-dired-line-up-dynamic ()
1803 "Line up thumbnails images dynamically.
1804 Calculate how many thumbnails fit."
1806 (let* ((char-width (frame-char-width))
1807 (width (image-dired-window-width-pixels (image-dired-thumbnail-window)))
1808 (image-dired-thumbs-per-row
1810 (+ (* 2 image-dired-thumb-relief)
1811 (* 2 image-dired-thumb-margin)
1812 (image-dired-thumb-size 'width)
1814 (image-dired-line-up)))
1816 (defun image-dired-line-up-interactive ()
1817 "Line up thumbnails interactively.
1818 Ask user how many thumbnails should be displayed per row."
1820 (let ((image-dired-thumbs-per-row
1821 (string-to-number (read-string "How many thumbs per row: "))))
1822 (if (not (> image-dired-thumbs-per-row 0))
1823 (message "Number must be greater than 0")
1824 (image-dired-line-up))))
1826 (defun image-dired-thumbnail-display-external ()
1827 "Display original image for thumbnail at point using external viewer."
1829 (let ((file (image-dired-original-file-name)))
1830 (if (not (image-dired-image-at-point-p))
1831 (message "No thumbnail at point")
1833 (message "No original file name found")
1834 (start-process "image-dired-thumb-external" nil
1835 image-dired-external-viewer file)))))
1838 (defun image-dired-dired-display-external ()
1839 "Display file at point using an external viewer."
1841 (let ((file (dired-get-filename)))
1842 (start-process "image-dired-external" nil
1843 image-dired-external-viewer file)))
1845 (defun image-dired-window-width-pixels (window)
1846 "Calculate WINDOW width in pixels."
1847 (* (window-width window) (frame-char-width)))
1849 (defun image-dired-window-height-pixels (window)
1850 "Calculate WINDOW height in pixels."
1851 ;; Note: The mode-line consumes one line
1852 (* (- (window-height window) 1) (frame-char-height)))
1854 (defun image-dired-display-window ()
1855 "Return window where `image-dired-display-image-buffer' is visible."
1856 (get-window-with-predicate
1858 (equal (buffer-name (window-buffer window)) image-dired-display-image-buffer))
1861 (defun image-dired-thumbnail-window ()
1862 "Return window where `image-dired-thumbnail-buffer' is visible."
1863 (get-window-with-predicate
1865 (equal (buffer-name (window-buffer window)) image-dired-thumbnail-buffer))
1868 (defun image-dired-associated-dired-buffer-window ()
1869 "Return window where associated dired buffer is visible."
1871 (if (image-dired-image-at-point-p)
1873 (setq buf (image-dired-associated-dired-buffer))
1874 (get-window-with-predicate
1876 (equal (window-buffer window) buf))))
1877 (error "No thumbnail image at point"))))
1879 (defun image-dired-display-window-width (window)
1880 "Return width, in pixels, of WINDOW."
1881 (- (image-dired-window-width-pixels window)
1882 image-dired-display-window-width-correction))
1884 (defun image-dired-display-window-height (window)
1885 "Return height, in pixels, of WINDOW."
1886 (- (image-dired-window-height-pixels window)
1887 image-dired-display-window-height-correction))
1889 (defun image-dired-display-image (file &optional original-size)
1890 "Display image FILE in image buffer.
1891 Use this when you want to display the image, semi sized, in a new
1892 window. The image is sized to fit the display window (using a
1893 temporary file, don't worry). Because of this, it will not be as
1894 quick as opening it directly, but on most modern systems it
1895 should feel snappy enough.
1897 If optional argument ORIGINAL-SIZE is non-nil, display image in its
1899 (image-dired--check-executable-exists
1900 'image-dired-cmd-create-temp-image-program)
1901 (let ((new-file (expand-file-name image-dired-temp-image-file))
1902 (window (image-dired-display-window))
1904 (setq file (expand-file-name file))
1905 (if (not original-size)
1908 (cons ?p image-dired-cmd-create-temp-image-program)
1909 (cons ?w (image-dired-display-window-width window))
1910 (cons ?h (image-dired-display-window-height window))
1912 (cons ?t new-file)))
1914 (apply #'call-process
1915 image-dired-cmd-create-temp-image-program nil nil nil
1917 (lambda (arg) (format-spec arg spec))
1918 image-dired-cmd-create-temp-image-options))))
1919 (when (not (zerop ret))
1920 (error "Could not resize image")))
1921 (setq image-type (image-type-from-file-name file))
1922 (copy-file file new-file t))
1923 (with-current-buffer (image-dired-create-display-image-buffer)
1924 (let ((inhibit-read-only t))
1927 (image-dired-insert-image image-dired-temp-image-file image-type 0 0)
1928 (goto-char (point-min))
1929 (set-window-vscroll window 0)
1930 (set-window-hscroll window 0)
1931 (image-dired-update-property 'original-file-name file)))))
1933 (defun image-dired-display-thumbnail-original-image (&optional arg)
1934 "Display current thumbnail's original image in display buffer.
1935 See documentation for `image-dired-display-image' for more information.
1936 With prefix argument ARG, display image in its original size."
1938 (let ((file (image-dired-original-file-name)))
1939 (if (not (string-equal major-mode "image-dired-thumbnail-mode"))
1940 (message "Not in image-dired-thumbnail-mode")
1941 (if (not (image-dired-image-at-point-p))
1942 (message "No thumbnail at point")
1944 (message "No original file name found")
1945 (image-dired-create-display-image-buffer)
1946 (display-buffer image-dired-display-image-buffer)
1947 (image-dired-display-image file arg))))))
1951 (defun image-dired-dired-display-image (&optional arg)
1952 "Display current image file.
1953 See documentation for `image-dired-display-image' for more information.
1954 With prefix argument ARG, display image in its original size."
1956 (image-dired-create-display-image-buffer)
1957 (display-buffer image-dired-display-image-buffer)
1958 (image-dired-display-image (dired-get-filename) arg))
1960 (defun image-dired-image-at-point-p ()
1961 "Return true if there is an image-dired thumbnail at point."
1962 (get-text-property (point) 'image-dired-thumbnail))
1964 (defun image-dired-rotate-thumbnail (degrees)
1965 "Rotate thumbnail DEGREES degrees."
1966 (image-dired--check-executable-exists
1967 'image-dired-cmd-rotate-thumbnail-program)
1968 (if (not (image-dired-image-at-point-p))
1969 (message "No thumbnail at point")
1970 (let* ((file (image-dired-thumb-name (image-dired-original-file-name)))
1971 (thumb (expand-file-name file))
1972 (spec (list (cons ?d degrees) (cons ?t thumb))))
1973 (apply #'call-process image-dired-cmd-rotate-thumbnail-program nil nil nil
1974 (mapcar (lambda (arg) (format-spec arg spec))
1975 image-dired-cmd-rotate-thumbnail-options))
1976 (clear-image-cache thumb))))
1978 (defun image-dired-rotate-thumbnail-left ()
1979 "Rotate thumbnail left (counter clockwise) 90 degrees.
1980 The result of the rotation is displayed in the image display area
1981 and a confirmation is needed before the original image files is
1982 overwritten. This confirmation can be turned off using
1983 `image-dired-rotate-original-ask-before-overwrite'."
1985 (image-dired-rotate-thumbnail "270"))
1987 (defun image-dired-rotate-thumbnail-right ()
1988 "Rotate thumbnail counter right (clockwise) 90 degrees.
1989 The result of the rotation is displayed in the image display area
1990 and a confirmation is needed before the original image files is
1991 overwritten. This confirmation can be turned off using
1992 `image-dired-rotate-original-ask-before-overwrite'."
1994 (image-dired-rotate-thumbnail "90"))
1996 (defun image-dired-refresh-thumb ()
1997 "Force creation of new image for current thumbnail."
1999 (let* ((file (image-dired-original-file-name))
2000 (thumb (expand-file-name (image-dired-thumb-name file))))
2001 (clear-image-cache (expand-file-name thumb))
2002 (image-dired-create-thumb file thumb)))
2004 (defun image-dired-rotate-original (degrees)
2005 "Rotate original image DEGREES degrees."
2006 (image-dired--check-executable-exists
2007 'image-dired-cmd-rotate-original-program)
2008 (if (not (image-dired-image-at-point-p))
2009 (message "No image at point")
2010 (let* ((file (image-dired-original-file-name))
2014 (cons ?o (expand-file-name file))
2015 (cons ?t image-dired-temp-rotate-image-file))))
2016 (unless (eq 'jpeg (image-type file))
2017 (error "Only JPEG images can be rotated!"))
2018 (if (not (= 0 (apply #'call-process image-dired-cmd-rotate-original-program
2020 (mapcar (lambda (arg) (format-spec arg spec))
2021 image-dired-cmd-rotate-original-options))))
2022 (error "Could not rotate image")
2023 (image-dired-display-image image-dired-temp-rotate-image-file)
2024 (if (or (and image-dired-rotate-original-ask-before-overwrite
2026 "Rotate to temp file OK. Overwrite original image? "))
2027 (not image-dired-rotate-original-ask-before-overwrite))
2029 (copy-file image-dired-temp-rotate-image-file file t)
2030 (image-dired-refresh-thumb))
2031 (image-dired-display-image file))))))
2033 (defun image-dired-rotate-original-left ()
2034 "Rotate original image left (counter clockwise) 90 degrees."
2036 (image-dired-rotate-original "270"))
2038 (defun image-dired-rotate-original-right ()
2039 "Rotate original image right (clockwise) 90 degrees."
2041 (image-dired-rotate-original "90"))
2043 (defun image-dired-get-exif-file-name (file)
2044 "Use the image's EXIF information to return a unique file name.
2045 The file name should be unique as long as you do not take more than
2046 one picture per second. The original file name is suffixed at the end
2047 for traceability. The format of the returned file name is
2048 YYYY_MM_DD_HH_MM_DD_ORIG_FILE_NAME.jpg. Used from
2049 `image-dired-copy-with-exif-file-name'."
2050 (let (data no-exif-data-found)
2051 (if (not (eq 'jpeg (image-type (expand-file-name file))))
2052 (setq no-exif-data-found t
2053 data (format-time-string
2055 (file-attribute-modification-time
2056 (file-attributes (expand-file-name file)))))
2057 (setq data (image-dired-get-exif-data (expand-file-name file)
2058 "DateTimeOriginal")))
2059 (while (string-match "[ :]" data)
2060 (setq data (replace-match "_" nil nil data)))
2061 (format "%s%s%s" data
2062 (if no-exif-data-found
2065 (file-name-nondirectory file))))
2067 (defun image-dired-thumbnail-set-image-description ()
2068 "Set the ImageDescription EXIF tag for the original image.
2069 If the image already has a value for this tag, it is used as the
2070 default value at the prompt."
2072 (if (not (image-dired-image-at-point-p))
2073 (message "No thumbnail at point")
2074 (let* ((file (image-dired-original-file-name))
2075 (old-value (image-dired-get-exif-data file "ImageDescription")))
2077 (image-dired-set-exif-data file "ImageDescription"
2078 (read-string "Value of ImageDescription: "
2080 (message "Successfully wrote ImageDescription tag.")
2081 (error "Could not write ImageDescription tag")))))
2083 (defun image-dired-set-exif-data (file tag-name tag-value)
2084 "In FILE, set EXIF tag TAG-NAME to value TAG-VALUE."
2085 (image-dired--check-executable-exists
2086 'image-dired-cmd-write-exif-data-program)
2089 (cons ?f (expand-file-name file))
2091 (cons ?v tag-value))))
2092 (apply #'call-process image-dired-cmd-write-exif-data-program nil nil nil
2093 (mapcar (lambda (arg) (format-spec arg spec))
2094 image-dired-cmd-write-exif-data-options))))
2096 (defun image-dired-get-exif-data (file tag-name)
2097 "From FILE, return EXIF tag TAG-NAME."
2098 (image-dired--check-executable-exists
2099 'image-dired-cmd-read-exif-data-program)
2100 (let ((buf (get-buffer-create "*image-dired-get-exif-data*"))
2101 (spec (list (cons ?f file) (cons ?t tag-name)))
2103 (with-current-buffer buf
2104 (delete-region (point-min) (point-max))
2105 (if (not (eq (apply #'call-process image-dired-cmd-read-exif-data-program
2108 (lambda (arg) (format-spec arg spec))
2109 image-dired-cmd-read-exif-data-options))
2111 (error "Could not get EXIF tag")
2112 (goto-char (point-min))
2113 ;; Clean buffer from newlines and carriage returns before
2114 ;; getting final info
2115 (while (search-forward-regexp "[\n\r]" nil t)
2116 (replace-match "" nil t))
2117 (setq tag-value (buffer-substring (point-min) (point-max)))))
2120 (defun image-dired-copy-with-exif-file-name ()
2121 "Copy file with unique name to main image directory.
2122 Copy current or all marked files in dired to a new file in your
2123 main image directory, using a file name generated by
2124 `image-dired-get-exif-file-name'. A typical usage for this if when
2125 copying images from a digital camera into the image directory.
2127 Typically, you would open up the folder with the incoming
2128 digital images, mark the files to be copied, and execute this
2129 function. The result is a couple of new files in
2130 `image-dired-main-image-directory' called
2131 2005_05_08_12_52_00_dscn0319.jpg,
2132 2005_05_08_14_27_45_dscn0320.jpg etc."
2135 (files (dired-get-marked-files)))
2140 (file-name-as-directory
2141 (expand-file-name image-dired-main-image-directory))
2142 (image-dired-get-exif-file-name curr-file)))
2143 (message "Copying %s to %s" curr-file new-name)
2144 (copy-file curr-file new-name))
2147 (defun image-dired-display-next-thumbnail-original ()
2148 "In thumbnail buffer, move to next thumbnail and display the image."
2150 (image-dired-forward-image)
2151 (image-dired-display-thumbnail-original-image))
2153 (defun image-dired-display-previous-thumbnail-original ()
2154 "Move to previous thumbnail and display image."
2156 (image-dired-backward-image)
2157 (image-dired-display-thumbnail-original-image))
2159 (defun image-dired-write-comments (file-comments)
2160 "Write file comments to database.
2161 Write file comments to one or more files.
2162 FILE-COMMENTS is an alist on the following form:
2163 ((FILE . COMMENT) ... )"
2164 (image-dired-sane-db-file)
2165 (let (end comment-beg-pos comment-end-pos file comment)
2166 (image-dired--with-db-file
2167 (setq buffer-file-name image-dired-db-file)
2168 (dolist (elt file-comments)
2169 (setq file (car elt)
2171 (goto-char (point-min))
2172 (if (search-forward-regexp (format "^%s.*$" file) nil t)
2176 ;; Delete old comment, if any
2177 (when (search-forward ";comment:" end t)
2178 (setq comment-beg-pos (match-beginning 0))
2179 ;; Any tags after the comment?
2180 (if (search-forward ";" end t)
2181 (setq comment-end-pos (- (point) 1))
2182 (setq comment-end-pos end))
2183 ;; Delete comment tag and comment
2184 (delete-region comment-beg-pos comment-end-pos))
2185 ;; Insert new comment
2187 (unless (search-forward ";" end t)
2190 (insert (format "comment:%s;" comment)))
2191 ;; File does not exist in database - add it.
2192 (goto-char (point-max))
2193 (insert (format "\n%s;comment:%s" file comment))))
2196 (defun image-dired-update-property (prop value)
2197 "Update text property PROP with value VALUE at point."
2198 (let ((inhibit-read-only t))
2200 (point) (1+ (point))
2205 (defun image-dired-dired-comment-files ()
2206 "Add comment to current or marked files in dired."
2208 (let ((comment (image-dired-read-comment)))
2209 (image-dired-write-comments
2212 (cons curr-file comment))
2213 (dired-get-marked-files)))))
2215 (defun image-dired-comment-thumbnail ()
2216 "Add comment to current thumbnail in thumbnail buffer."
2218 (let* ((file (image-dired-original-file-name))
2219 (comment (image-dired-read-comment file)))
2220 (image-dired-write-comments (list (cons file comment)))
2221 (image-dired-update-property 'comment comment))
2222 (image-dired-display-thumb-properties))
2224 (defun image-dired-read-comment (&optional file)
2225 "Read comment for an image.
2226 Optionally use old comment from FILE as initial value."
2230 (if file (image-dired-get-comment file)))))
2233 (defun image-dired-get-comment (file)
2234 "Get comment for file FILE."
2235 (image-dired-sane-db-file)
2236 (image-dired--with-db-file
2237 (let (end comment-beg-pos comment-end-pos comment)
2238 (when (search-forward-regexp (format "^%s" file) nil t)
2242 (when (search-forward ";comment:" end t)
2243 (setq comment-beg-pos (point))
2244 (if (search-forward ";" end t)
2245 (setq comment-end-pos (- (point) 1))
2246 (setq comment-end-pos end))
2247 (setq comment (buffer-substring
2248 comment-beg-pos comment-end-pos))))
2252 (defun image-dired-mark-tagged-files ()
2253 "Use regexp to mark files with matching tag.
2254 A `tag' is a keyword, a piece of meta data, associated with an
2255 image file and stored in image-dired's database file. This command
2256 lets you input a regexp and this will be matched against all tags
2257 on all image files in the database file. The files that have a
2258 matching tag will be marked in the dired buffer."
2260 (image-dired-sane-db-file)
2261 (let ((tag (read-string "Mark tagged files (regexp): "))
2264 (image-dired--with-db-file
2266 (while (search-forward-regexp
2267 (concat "\\(^[^;\n]+\\);.*" tag ".*$") nil t)
2268 (push (match-string 1) files)))
2270 (dolist (curr-file files)
2271 ;; I tried using `dired-mark-files-regexp' but it was waaaay to
2272 ;; slow. Don't bother about hits found in other directories
2273 ;; than the current one.
2274 (when (string= (file-name-as-directory
2275 (expand-file-name default-directory))
2276 (file-name-as-directory
2277 (file-name-directory curr-file)))
2278 (setq curr-file (file-name-nondirectory curr-file))
2279 (goto-char (point-min))
2280 (when (search-forward-regexp (format "\\s %s$" curr-file) nil t)
2281 (setq hits (+ hits 1))
2283 (message "%d files with matching tag marked." hits)))
2285 (defun image-dired-mouse-display-image (event)
2286 "Use mouse EVENT, call `image-dired-display-image' to display image.
2287 Track this in associated dired buffer if `image-dired-track-movement' is
2290 (mouse-set-point event)
2291 (goto-char (posn-point (event-end event)))
2292 (let ((file (image-dired-original-file-name)))
2294 (if image-dired-track-movement
2295 (image-dired-track-original-file))
2296 (image-dired-create-display-image-buffer)
2297 (display-buffer image-dired-display-image-buffer)
2298 (image-dired-display-image file))))
2300 (defun image-dired-mouse-select-thumbnail (event)
2301 "Use mouse EVENT to select thumbnail image.
2302 Track this in associated dired buffer if `image-dired-track-movement' is
2305 (mouse-set-point event)
2306 (goto-char (posn-point (event-end event)))
2307 (if image-dired-track-movement
2308 (image-dired-track-original-file))
2309 (image-dired-display-thumb-properties))
2311 (defun image-dired-mouse-toggle-mark (event)
2312 "Use mouse EVENT to toggle dired mark for thumbnail.
2313 Track this in associated dired buffer if `image-dired-track-movement' is
2316 (mouse-set-point event)
2317 (goto-char (posn-point (event-end event)))
2318 (if image-dired-track-movement
2319 (image-dired-track-original-file))
2320 (image-dired-toggle-mark-thumb-original-file))
2322 (defun image-dired-dired-display-properties ()
2323 "Display properties for dired file in the echo area."
2325 (let* ((file (dired-get-filename))
2326 (file-name (file-name-nondirectory file))
2327 (dired-buf (buffer-name (current-buffer)))
2328 (props (mapconcat #'identity (image-dired-list-tags file) ", "))
2329 (comment (image-dired-get-comment file))
2330 (message-log-max nil))
2333 (image-dired-format-properties-string
2339 (defvar image-dired-tag-file-list nil
2340 "List to store tag-file structure.")
2342 (defvar image-dired-file-tag-list nil
2343 "List to store file-tag structure.")
2345 (defvar image-dired-file-comment-list nil
2346 "List to store file comments.")
2348 (defun image-dired-add-to-tag-file-list (tag file)
2349 "Add relation between TAG and FILE."
2351 (if image-dired-tag-file-list
2352 (if (setq curr (assoc tag image-dired-tag-file-list))
2353 (if (not (member file curr))
2354 (setcdr curr (cons file (cdr curr))))
2355 (setcdr image-dired-tag-file-list
2356 (cons (list tag file) (cdr image-dired-tag-file-list))))
2357 (setq image-dired-tag-file-list (list (list tag file))))))
2359 (defun image-dired-add-to-tag-file-lists (tag file)
2360 "Helper function used from `image-dired-create-gallery-lists'.
2362 Add TAG to FILE in one list and FILE to TAG in the other.
2364 Lisp structures look like the following:
2366 image-dired-file-tag-list:
2368 ((\"filename1\" \"tag1\" \"tag2\" \"tag3\" ...)
2369 (\"filename2\" \"tag1\" \"tag2\" \"tag3\" ...)
2372 image-dired-tag-file-list:
2374 ((\"tag1\" \"filename1\" \"filename2\" \"filename3\" ...)
2375 (\"tag2\" \"filename1\" \"filename2\" \"filename3\" ...)
2377 ;; Add tag to file list
2379 (if image-dired-file-tag-list
2380 (if (setq curr (assoc file image-dired-file-tag-list))
2381 (setcdr curr (cons tag (cdr curr)))
2382 (setcdr image-dired-file-tag-list
2383 (cons (list file tag) (cdr image-dired-file-tag-list))))
2384 (setq image-dired-file-tag-list (list (list file tag))))
2385 ;; Add file to tag list
2386 (if image-dired-tag-file-list
2387 (if (setq curr (assoc tag image-dired-tag-file-list))
2388 (if (not (member file curr))
2389 (setcdr curr (cons file (cdr curr))))
2390 (setcdr image-dired-tag-file-list
2391 (cons (list tag file) (cdr image-dired-tag-file-list))))
2392 (setq image-dired-tag-file-list (list (list tag file))))))
2394 (defun image-dired-add-to-file-comment-list (file comment)
2395 "Helper function used from `image-dired-create-gallery-lists'.
2397 For FILE, add COMMENT to list.
2399 Lisp structure looks like the following:
2401 image-dired-file-comment-list:
2403 ((\"filename1\" . \"comment1\")
2404 (\"filename2\" . \"comment2\")
2406 (if image-dired-file-comment-list
2407 (if (not (assoc file image-dired-file-comment-list))
2408 (setcdr image-dired-file-comment-list
2409 (cons (cons file comment)
2410 (cdr image-dired-file-comment-list))))
2411 (setq image-dired-file-comment-list (list (cons file comment)))))
2413 (defun image-dired-create-gallery-lists ()
2414 "Create temporary lists used by `image-dired-gallery-generate'."
2415 (image-dired-sane-db-file)
2416 (image-dired--with-db-file
2417 (let (end beg file row-tags)
2418 (setq image-dired-tag-file-list nil)
2419 (setq image-dired-file-tag-list nil)
2420 (setq image-dired-file-comment-list nil)
2421 (goto-char (point-min))
2422 (while (search-forward-regexp "^." nil t)
2427 (unless (search-forward ";" end nil)
2428 (error "Something is really wrong, check format of database"))
2429 (setq row-tags (split-string
2430 (buffer-substring beg end) ";"))
2431 (setq file (car row-tags))
2432 (dolist (x (cdr row-tags))
2433 (if (not (string-match "^comment:\\(.*\\)" x))
2434 (image-dired-add-to-tag-file-lists x file)
2435 (image-dired-add-to-file-comment-list file (match-string 1 x)))))))
2436 ;; Sort tag-file list
2437 (setq image-dired-tag-file-list
2438 (sort image-dired-tag-file-list
2440 (string< (car x) (car y))))))
2442 (defun image-dired-hidden-p (file)
2443 "Return t if image FILE has a \"hidden\" tag."
2444 (cl-loop for tag in (cdr (assoc file image-dired-file-tag-list))
2445 if (member tag image-dired-gallery-hidden-tags) return t))
2447 (defun image-dired-gallery-generate ()
2448 "Generate gallery pages.
2449 First we create a couple of Lisp structures from the database to make
2450 it easier to generate, then HTML-files are created in
2451 `image-dired-gallery-dir'."
2453 (if (eq 'per-directory image-dired-thumbnail-storage)
2454 (error "Currently, gallery generation is not supported \
2455 when using per-directory thumbnail file storage"))
2456 (image-dired-create-gallery-lists)
2457 (let ((tags image-dired-tag-file-list)
2458 (index-file (format "%s/index.html" image-dired-gallery-dir))
2460 comment file-tags tag-link tag-link-list)
2461 ;; Make sure gallery root exist
2462 (if (file-exists-p image-dired-gallery-dir)
2463 (if (not (file-directory-p image-dired-gallery-dir))
2464 (error "Variable image-dired-gallery-dir is not a directory"))
2465 (make-directory image-dired-gallery-dir))
2467 (with-temp-file index-file
2468 (if (file-exists-p index-file)
2469 (insert-file-contents index-file))
2471 (insert " <body>\n")
2472 (insert " <h2>Image-Dired Gallery</h2>\n")
2473 (insert (format "<p>\n Gallery generated %s\n <p>\n"
2474 (current-time-string)))
2475 (insert " <h3>Tag index</h3>\n")
2477 ;; Pre-generate list of all tag links
2479 (setq tag (car curr))
2480 (when (not (member tag image-dired-gallery-hidden-tags))
2481 (setq tag-link (format "<a href=\"%d.html\">%s</a>" count tag))
2484 (append tag-link-list (list (cons tag tag-link))))
2485 (setq tag-link-list (list (cons tag tag-link))))
2486 (setq count (1+ count))))
2488 ;; Main loop where we generated thumbnail pages per tag
2490 (setq tag (car curr))
2491 ;; Don't display hidden tags
2492 (when (not (member tag image-dired-gallery-hidden-tags))
2493 ;; Insert link to tag page in index
2494 (insert (format " %s<br>\n" (cdr (assoc tag tag-link-list))))
2495 ;; Open per-tag file
2496 (setq tag-file (format "%s/%s.html" image-dired-gallery-dir count))
2497 (with-temp-file tag-file
2498 (if (file-exists-p tag-file)
2499 (insert-file-contents tag-file))
2502 (insert " <body>\n")
2503 (insert " <p><a href=\"index.html\">Index</a></p>\n")
2504 (insert (format " <h2>Images with tag "%s"</h2>" tag))
2505 ;; Main loop for files per tag page
2506 (dolist (file (cdr curr))
2507 (unless (image-dired-hidden-p file)
2508 ;; Insert thumbnail with link to full image
2510 (format "<a href=\"%s/%s\"><img src=\"%s/%s\"%s></a>\n"
2511 image-dired-gallery-image-root-url
2512 (file-name-nondirectory file)
2513 image-dired-gallery-thumb-image-root-url
2514 (file-name-nondirectory (image-dired-thumb-name file)) file))
2515 ;; Insert comment, if any
2516 (if (setq comment (cdr (assoc file image-dired-file-comment-list)))
2517 (insert (format "<br>\n%s<br>\n" comment))
2519 ;; Insert links to other tags, if any
2521 (setq file-tags (assoc file image-dired-file-tag-list))) 2)
2523 (dolist (extra-tag file-tags)
2524 ;; Only insert if not file name or the main tag
2525 (if (and (not (equal extra-tag tag))
2526 (not (equal extra-tag file)))
2528 (format "%s " (cdr (assoc extra-tag tag-link-list))))))
2529 (insert "]<br>\n"))))
2530 (insert " <p><a href=\"index.html\">Index</a></p>\n")
2531 (insert " </body>\n")
2532 (insert "</html>\n"))
2533 (setq count (1+ count))))
2534 (insert " </body>\n")
2535 (insert "</html>"))))
2537 (defvar image-dired-widget-list nil
2538 "List to keep track of meta data in edit buffer.")
2540 (declare-function widget-forward "wid-edit" (arg))
2543 (defun image-dired-dired-edit-comment-and-tags ()
2544 "Edit comment and tags of current or marked image files.
2545 Edit comment and tags for all marked image files in an
2548 (setq image-dired-widget-list nil)
2550 (let ((files (dired-get-marked-files)))
2551 (pop-to-buffer-same-window "*Image-Dired Edit Meta Data*")
2552 (kill-all-local-variables)
2553 (make-local-variable 'widget-example-repeat)
2554 (let ((inhibit-read-only t))
2557 ;; Some help for the user.
2559 "\nEdit comments and tags for each image. Separate multiple tags
2560 with a comma. Move forward between fields using TAB or RET.
2561 Move to the previous field using backtab (S-TAB). Save by
2562 activating the Save button at the bottom of the form or cancel
2563 the operation by activating the Cancel button.\n\n")
2564 ;; Here comes all images and a comment and tag field for each
2566 (let (thumb-file img comment-widget tag-widget)
2568 (dolist (file files)
2570 (setq thumb-file (image-dired-thumb-name file)
2571 img (create-image thumb-file))
2574 (widget-insert "\n\nComment: ")
2575 (setq comment-widget
2576 (widget-create 'editable-field
2579 :value (or (image-dired-get-comment file) "")))
2580 (widget-insert "\nTags: ")
2582 (widget-create 'editable-field
2585 :value (or (mapconcat
2587 (image-dired-list-tags file)
2589 ;; Save information in all widgets so that we can use it when
2590 ;; the user saves the form.
2591 (setq image-dired-widget-list
2592 (append image-dired-widget-list
2593 (list (list file comment-widget tag-widget))))
2594 (widget-insert "\n\n")))
2596 ;; Footer with Save and Cancel button.
2597 (widget-insert "\n")
2598 (widget-create 'push-button
2600 (lambda (&rest _ignore)
2601 (image-dired-save-information-from-widgets)
2606 (widget-create 'push-button
2608 (lambda (&rest _ignore)
2610 (message "Operation canceled."))
2612 (widget-insert "\n")
2613 (use-local-map widget-keymap)
2615 ;; Jump to the first widget.
2616 (widget-forward 1)))
2618 (defun image-dired-save-information-from-widgets ()
2619 "Save information found in `image-dired-widget-list'.
2620 Use the information in `image-dired-widget-list' to save comments and
2621 tags to their respective image file. Internal function used by
2622 `image-dired-dired-edit-comment-and-tags'."
2623 (let (file comment tag-string tag-list lst)
2624 (image-dired-write-comments
2627 (setq file (car widget)
2628 comment (widget-value (cadr widget)))
2629 (cons file comment))
2630 image-dired-widget-list))
2631 (image-dired-write-tags
2632 (dolist (widget image-dired-widget-list lst)
2633 (setq file (car widget)
2634 tag-string (widget-value (car (cddr widget)))
2635 tag-list (split-string tag-string ","))
2636 (dolist (tag tag-list)
2637 (push (cons file tag) lst))))))
2639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2640 ;;;;;;;;; TEST-SECTION ;;;;;;;;;;;
2641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2643 ;; (defvar image-dired-dir-max-size 12300000)
2645 ;; (defun image-dired-test-clean-old-files ()
2646 ;; "Clean `image-dired-dir' from old thumbnail files.
2647 ;; \"Oldness\" measured using last access time. If the total size of all
2648 ;; thumbnail files in `image-dired-dir' is larger than 'image-dired-dir-max-size',
2649 ;; old files are deleted until the max size is reached."
2654 ;; (let ((fattribs (file-attributes f)))
2655 ;; ;; Get last access time and file size
2656 ;; `(,(nth 4 fattribs) ,(nth 7 fattribs) ,f)))
2657 ;; (directory-files (image-dired-dir) t ".+\\.thumb\\..+$"))
2658 ;; ;; Sort function. Compare time between two files.
2660 ;; (time-less-p (car l1) (car l2)))))
2661 ;; (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files))))
2662 ;; (while (> dirsize image-dired-dir-max-size)
2664 ;; (format "Size of thumbnail directory: %d, delete old file %s? "
2665 ;; dirsize (cadr (cdar files))))
2666 ;; (delete-file (cadr (cdar files)))
2667 ;; (setq dirsize (- dirsize (car (cdar files))))
2668 ;; (setq files (cdr files)))))
2670 ;;;;;;;;;;;;;;;;;;;;;;,
2672 ;; (defun dired-speedbar-buttons (dired-buffer)
2673 ;; (when (and (boundp 'image-dired-use-speedbar)
2674 ;; image-dired-use-speedbar)
2675 ;; (let ((filename (with-current-buffer dired-buffer
2676 ;; (dired-get-filename))))
2677 ;; (when (and (not (string-equal filename (buffer-string)))
2678 ;; (string-match (image-file-name-regexp) filename))
2680 ;; (insert (propertize
2683 ;; (image-dired-get-thumbnail-image filename)))))))
2685 ;; (setq image-dired-use-speedbar t)
2687 (provide 'image-dired)
2689 ;;; image-dired.el ends here