diff options
| author | Chong Yidong | 2007-04-22 13:44:05 +0000 |
|---|---|---|
| committer | Chong Yidong | 2007-04-22 13:44:05 +0000 |
| commit | f7c84295eeb67e17686fb765c91a331998715211 (patch) | |
| tree | 560befa3b3f9185b956fb06c55024c7099b85196 | |
| parent | 615aef6ed0b9b337b3329d24af78de73557094a8 (diff) | |
| download | emacs-f7c84295eeb67e17686fb765c91a331998715211.tar.gz emacs-f7c84295eeb67e17686fb765c91a331998715211.zip | |
Rename from "thumbnails.el"; all instances of "thumbnails" changed to
"image-dired".
| -rw-r--r-- | lisp/image-dired.el | 2597 |
1 files changed, 2597 insertions, 0 deletions
diff --git a/lisp/image-dired.el b/lisp/image-dired.el new file mode 100644 index 00000000000..ed330410d88 --- /dev/null +++ b/lisp/image-dired.el | |||
| @@ -0,0 +1,2597 @@ | |||
| 1 | ;;; image-dired.el --- use dired to browse and manipulate your images | ||
| 2 | ;; | ||
| 3 | ;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. | ||
| 4 | ;; | ||
| 5 | ;; Version: 0.4.11 | ||
| 6 | ;; Keywords: multimedia | ||
| 7 | ;; Author: Mathias Dahl <mathias.rem0veth1s.dahl@gmail.com> | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | |||
| 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 2, or (at your option) | ||
| 14 | ;; any later version. | ||
| 15 | |||
| 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. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
| 24 | ;; Boston, MA 02110-1301, USA. | ||
| 25 | |||
| 26 | ;;; Commentary: | ||
| 27 | ;; | ||
| 28 | ;; BACKGROUND | ||
| 29 | ;; ========== | ||
| 30 | ;; | ||
| 31 | ;; I needed a program to browse, organize and tag my pictures. I got | ||
| 32 | ;; tired of the old gallery program I used as it did not allow | ||
| 33 | ;; multi-file operations easily. Also, it put things out of my | ||
| 34 | ;; control. Image viewing programs I tested did not allow multi-file | ||
| 35 | ;; operations or did not do what I wanted it to. | ||
| 36 | ;; | ||
| 37 | ;; So, I got the idea to use the wonderful functionality of Emacs and | ||
| 38 | ;; `dired' to do it. It would allow me to do almost anything I wanted, | ||
| 39 | ;; which is basically just to browse all my pictures in an easy way, | ||
| 40 | ;; letting me manipulate and tag them in various ways. `dired' already | ||
| 41 | ;; provide all the file handling and navigation facilities; I only | ||
| 42 | ;; needed to add some functions to display the images. | ||
| 43 | ;; | ||
| 44 | ;; I briefly tried out thumbs.el, and although it seemed more | ||
| 45 | ;; powerful than this package, it did not work the way I wanted to. It | ||
| 46 | ;; was too slow to created thumbnails of all files in a directory (I | ||
| 47 | ;; currently keep all my 2000+ images in the same directory) and | ||
| 48 | ;; browsing the thumbnail buffer was slow too. image-dired.el will not | ||
| 49 | ;; create thumbnails until they are needed and the browsing is done | ||
| 50 | ;; quickly and easily in dired. I copied a great deal of ideas and | ||
| 51 | ;; code from there though... :) | ||
| 52 | ;; | ||
| 53 | ;; `image-dired' stores the thumbnail files in `image-dired-dir' | ||
| 54 | ;; using the file name format ORIGNAME.thumb.ORIGEXT. For example | ||
| 55 | ;; ~/.emacs.d/image-dired/myimage01.thumb.jpg. The "database" is for | ||
| 56 | ;; now just a plain text file with the following format: | ||
| 57 | ;; | ||
| 58 | ;; file-name-non-directory;comment:comment-text;tag1;tag2;tag3;...;tagN | ||
| 59 | ;; | ||
| 60 | ;; | ||
| 61 | ;; PREREQUISITES | ||
| 62 | ;; ============= | ||
| 63 | ;; | ||
| 64 | ;; * The ImageMagick package. Currently, `convert' and `mogrify' are | ||
| 65 | ;; used. Find it here: http://www.imagemagick.org. | ||
| 66 | ;; | ||
| 67 | ;; * For non-lossy rotation of JPEG images, the JpegTRAN program is | ||
| 68 | ;; needed. | ||
| 69 | ;; | ||
| 70 | ;; * For `image-dired-get-exif-data' and `image-dired-write-exif-data' to work, | ||
| 71 | ;; the command line tool `exiftool' is needed. It can be found here: | ||
| 72 | ;; http://www.sno.phy.queensu.ca/~phil/exiftool/. These two functions | ||
| 73 | ;; are, among other things, used for writing comments to image files | ||
| 74 | ;; using `image-dired-thumbnail-set-image-description' and to create | ||
| 75 | ;; "unique" file names using `image-dired-get-exif-file-name' (used by | ||
| 76 | ;; `image-dired-copy-with-exif-file-name'). | ||
| 77 | ;; | ||
| 78 | ;; | ||
| 79 | ;; USAGE | ||
| 80 | ;; ===== | ||
| 81 | ;; | ||
| 82 | ;; This information has been moved to the manual. Type `C-h r' to open | ||
| 83 | ;; the Emacs manual and go to the node Thumbnails by typing `g | ||
| 84 | ;; Thumbnails RET'. | ||
| 85 | ;; | ||
| 86 | ;; Quickstart: M-x image-dired RET DIRNAME RET | ||
| 87 | ;; | ||
| 88 | ;; where DIRNAME is a directory containing image files. | ||
| 89 | ;; | ||
| 90 | ;; LIMITATIONS | ||
| 91 | ;; =========== | ||
| 92 | ;; | ||
| 93 | ;; * Supports all image formats that Emacs and convert supports, but | ||
| 94 | ;; the thumbnails are hard-coded to JPEG format. | ||
| 95 | ;; | ||
| 96 | ;; * WARNING: The "database" format used might be changed so keep a | ||
| 97 | ;; backup of `image-dired-db-file' when testing new versions. | ||
| 98 | ;; | ||
| 99 | ;; | ||
| 100 | ;; TODO | ||
| 101 | ;; ==== | ||
| 102 | ;; | ||
| 103 | ;; * Support gallery creation when using per-directory thumbnail | ||
| 104 | ;; storage. | ||
| 105 | ;; | ||
| 106 | ;; * Some sort of auto-rotate function based on rotate info in the | ||
| 107 | ;; EXIF data. | ||
| 108 | ;; | ||
| 109 | ;; * Check if exiftool exist before trying to call it to give a better | ||
| 110 | ;; error message. | ||
| 111 | ;; | ||
| 112 | ;; * Investigate if it is possible to also write the tags to the image | ||
| 113 | ;; files. | ||
| 114 | ;; | ||
| 115 | ;; * From thumbs.el: Add an option for clean-up/max-size functionality | ||
| 116 | ;; for thumbnail directory. | ||
| 117 | ;; | ||
| 118 | ;; * From thumbs.el: Add setroot function. | ||
| 119 | ;; | ||
| 120 | ;; * From thumbs.el: Add image resizing, if useful (image-dired's automatic | ||
| 121 | ;; "image fit" might be enough) | ||
| 122 | ;; | ||
| 123 | ;; * From thumbs.el: Add the "modify" commands (emboss, negate, | ||
| 124 | ;; monochrome etc). | ||
| 125 | ;; | ||
| 126 | ;; * Asynchronous creation of thumbnails. | ||
| 127 | ;; | ||
| 128 | ;; * Add `image-dired-display-thumbs-ring' and functions to cycle that. Find | ||
| 129 | ;; out which is best, saving old batch just before inserting new, or | ||
| 130 | ;; saving the current batch in the ring when inserting it. Adding it | ||
| 131 | ;; probably needs rewriting `image-dired-display-thumbs' to be more general. | ||
| 132 | ;; | ||
| 133 | ;; * Find some way of toggling on and off really nice keybindings in | ||
| 134 | ;; dired (for example, using C-n or <down> instead of C-S-n). Richard | ||
| 135 | ;; suggested that we could keep C-t as prefix for image-dired commands | ||
| 136 | ;; as it is currently not used in dired. He also suggested that | ||
| 137 | ;; `dired-next-line' and `dired-previous-line' figure out if | ||
| 138 | ;; image-dired is enabled in the current buffer and, if it is, call | ||
| 139 | ;; `image-dired-dired-next-line' and | ||
| 140 | ;; `image-dired-dired-previous-line', respectively. Update: This is | ||
| 141 | ;; partly done; some bindings have now been added to dired. | ||
| 142 | ;; | ||
| 143 | ;; * Enhanced gallery creation with basic CSS-support and pagination | ||
| 144 | ;; of tag pages with many pictures. | ||
| 145 | ;; | ||
| 146 | ;; * Rewrite `image-dired-modify-mark-on-thumb-original-file' to be | ||
| 147 | ;; less ugly. | ||
| 148 | ;; | ||
| 149 | ;; * In some way keep track of buffers and windows and stuff so that | ||
| 150 | ;; it works as the user expects. | ||
| 151 | ;; | ||
| 152 | ;; * More/better documentation | ||
| 153 | ;; | ||
| 154 | ;; | ||
| 155 | ;;; Code: | ||
| 156 | |||
| 157 | (require 'dired) | ||
| 158 | (require 'format-spec) | ||
| 159 | (require 'widget) | ||
| 160 | |||
| 161 | (eval-when-compile | ||
| 162 | (require 'wid-edit)) | ||
| 163 | |||
| 164 | (defgroup image-dired nil | ||
| 165 | "Use dired to browse your images as thumbnails, and more." | ||
| 166 | :prefix "image-dired-" | ||
| 167 | :group 'multimedia) | ||
| 168 | |||
| 169 | (defcustom image-dired-dir "~/.emacs.d/image-dired/" | ||
| 170 | "Directory where thumbnail images are stored." | ||
| 171 | :type 'string | ||
| 172 | :group 'image-dired) | ||
| 173 | |||
| 174 | (defcustom image-dired-thumbnail-storage 'use-image-dired-dir | ||
| 175 | "How to store image-dired's thumbnail files. | ||
| 176 | Image-Dired can store thumbnail files in one of two ways and this is | ||
| 177 | controlled by this variable. \"Use image-dired dir\" means that the | ||
| 178 | thumbnails are stored in a central directory. \"Per directory\" | ||
| 179 | means that each thumbnail is stored in a subdirectory called | ||
| 180 | \".image-dired\" in the same directory where the image file is. | ||
| 181 | \"Thumbnail Managing Standard\" means that the thumbnails are | ||
| 182 | stored and generated according to the Thumbnail Managing Standard | ||
| 183 | that allows sharing of thumbnails across different programs." | ||
| 184 | :type '(choice :tag "How to store thumbnail files" | ||
| 185 | (const :tag "Thumbnail Managing Standard" standard) | ||
| 186 | (const :tag "Use image-dired-dir" use-image-dired-dir) | ||
| 187 | (const :tag "Per-directory" per-directory)) | ||
| 188 | :group 'image-dired) | ||
| 189 | |||
| 190 | (defcustom image-dired-db-file "~/.emacs.d/image-dired/.image-dired_db" | ||
| 191 | "Database file where file names and their associated tags are stored." | ||
| 192 | :type 'string | ||
| 193 | :group 'image-dired) | ||
| 194 | |||
| 195 | (defcustom image-dired-temp-image-file "~/.emacs.d/image-dired/.image-dired_temp" | ||
| 196 | "Name of temporary image file used by various commands." | ||
| 197 | :type 'string | ||
| 198 | :group 'image-dired) | ||
| 199 | |||
| 200 | (defcustom image-dired-gallery-dir "~/.emacs.d/image-dired/.image-dired_gallery" | ||
| 201 | "Directory to store generated gallery html pages. | ||
| 202 | This path needs to be \"shared\" to the public so that it can access | ||
| 203 | the index.html page that image-dired creates." | ||
| 204 | :type 'string | ||
| 205 | :group 'image-dired) | ||
| 206 | |||
| 207 | (defcustom image-dired-gallery-image-root-url | ||
| 208 | "http://your.own.server/image-diredpics" | ||
| 209 | "URL where the full size images are to be found. | ||
| 210 | Note that this path has to be configured in your web server. Image-Dired | ||
| 211 | expects to find pictures in this directory." | ||
| 212 | :type 'string | ||
| 213 | :group 'image-dired) | ||
| 214 | |||
| 215 | (defcustom image-dired-gallery-thumb-image-root-url | ||
| 216 | "http://your.own.server/image-diredthumbs" | ||
| 217 | "URL where the thumbnail images are to be found. | ||
| 218 | Note that this path has to be configured in your web server. Image-Dired | ||
| 219 | expects to find pictures in this directory." | ||
| 220 | :type 'string | ||
| 221 | :group 'image-dired) | ||
| 222 | |||
| 223 | (defcustom image-dired-cmd-create-thumbnail-program | ||
| 224 | "convert" | ||
| 225 | "Executable used to create thumbnail. | ||
| 226 | Used together with `image-dired-cmd-create-thumbnail-options'." | ||
| 227 | :type 'string | ||
| 228 | :group 'image-dired) | ||
| 229 | |||
| 230 | (defcustom image-dired-cmd-create-thumbnail-options | ||
| 231 | "%p -size %wx%h \"%f\" -resize %wx%h +profile \"*\" jpeg:\"%t\"" | ||
| 232 | "Format of command used to create thumbnail image. | ||
| 233 | Available options are %p which is replaced by | ||
| 234 | `image-dired-cmd-create-thumbnail-program', %w which is replaced by | ||
| 235 | `image-dired-thumb-width', %h which is replaced by `image-dired-thumb-height', | ||
| 236 | %f which is replaced by the file name of the original image and %t | ||
| 237 | which is replaced by the file name of the thumbnail file." | ||
| 238 | :type 'string | ||
| 239 | :group 'image-dired) | ||
| 240 | |||
| 241 | (defcustom image-dired-cmd-create-temp-image-program | ||
| 242 | "convert" | ||
| 243 | "Executable used to create temporary image. | ||
| 244 | Used together with `image-dired-cmd-create-temp-image-options'." | ||
| 245 | :type 'string | ||
| 246 | :group 'image-dired) | ||
| 247 | |||
| 248 | (defcustom image-dired-cmd-create-temp-image-options | ||
| 249 | "%p -size %wx%h \"%f\" -resize %wx%h +profile \"*\" jpeg:\"%t\"" | ||
| 250 | "Format of command used to create temporary image for display window. | ||
| 251 | Available options are %p which is replaced by | ||
| 252 | `image-dired-cmd-create-temp-image-program', %w and %h which is replaced by | ||
| 253 | the calculated max size for width and height in the image display window, | ||
| 254 | %f which is replaced by the file name of the original image and %t which | ||
| 255 | is replaced by the file name of the temporary file." | ||
| 256 | :type 'string | ||
| 257 | :group 'image-dired) | ||
| 258 | |||
| 259 | (defcustom image-dired-cmd-pngnq-program (executable-find "pngnq") | ||
| 260 | "The file name of the `pngnq' program. | ||
| 261 | It quantizes colors of PNG images down to 256 colors." | ||
| 262 | :type '(choice (const :tag "Not Set" nil) string) | ||
| 263 | :group 'image-dired) | ||
| 264 | |||
| 265 | (defcustom image-dired-cmd-pngcrush-program (executable-find "pngcrush") | ||
| 266 | "The file name of the `pngcrush' program. | ||
| 267 | It optimizes the compression of PNG images. Also it adds PNG textual chunks | ||
| 268 | with the information required by the Thumbnail Managing Standard." | ||
| 269 | :type '(choice (const :tag "Not Set" nil) string) | ||
| 270 | :group 'image-dired) | ||
| 271 | |||
| 272 | (defcustom image-dired-cmd-create-standard-thumbnail-command | ||
| 273 | (concat | ||
| 274 | image-dired-cmd-create-thumbnail-program " " | ||
| 275 | "-size %wx%h \"%f\" " | ||
| 276 | (unless (or image-dired-cmd-pngcrush-program image-dired-cmd-pngnq-program) | ||
| 277 | (concat | ||
| 278 | "-set \"Thumb::MTime\" \"%m\" " | ||
| 279 | "-set \"Thumb::URI\" \"file://%f\" " | ||
| 280 | "-set \"Description\" \"Thumbnail of file://%f\" " | ||
| 281 | "-set \"Software\" \"" (emacs-version) "\" ")) | ||
| 282 | "-thumbnail %wx%h png:\"%t\"" | ||
| 283 | (if image-dired-cmd-pngnq-program | ||
| 284 | (concat | ||
| 285 | " ; " image-dired-cmd-pngnq-program " -f \"%t\"" | ||
| 286 | (unless image-dired-cmd-pngcrush-program | ||
| 287 | " ; mv %q %t"))) | ||
| 288 | (if image-dired-cmd-pngcrush-program | ||
| 289 | (concat | ||
| 290 | (unless image-dired-cmd-pngcrush-program | ||
| 291 | " ; cp %t %q") | ||
| 292 | " ; " image-dired-cmd-pngcrush-program " -q " | ||
| 293 | "-text b \"Description\" \"Thumbnail of file://%f\" " | ||
| 294 | "-text b \"Software\" \"" (emacs-version) "\" " | ||
| 295 | ;; "-text b \"Thumb::Image::Height\" \"%oh\" " | ||
| 296 | ;; "-text b \"Thumb::Image::Mimetype\" \"%mime\" " | ||
| 297 | ;; "-text b \"Thumb::Image::Width\" \"%ow\" " | ||
| 298 | "-text b \"Thumb::MTime\" \"%m\" " | ||
| 299 | ;; "-text b \"Thumb::Size\" \"%b\" " | ||
| 300 | "-text b \"Thumb::URI\" \"file://%f\" " | ||
| 301 | "%q %t" | ||
| 302 | " ; rm %q"))) | ||
| 303 | "Command to create thumbnails according to the Thumbnail Managing Standard." | ||
| 304 | :type 'string | ||
| 305 | :group 'image-dired) | ||
| 306 | |||
| 307 | (defcustom image-dired-cmd-rotate-thumbnail-program | ||
| 308 | "mogrify" | ||
| 309 | "Executable used to rotate thumbnail. | ||
| 310 | Used together with `image-dired-cmd-rotate-thumbnail-options'." | ||
| 311 | :type 'string | ||
| 312 | :group 'image-dired) | ||
| 313 | |||
| 314 | (defcustom image-dired-cmd-rotate-thumbnail-options | ||
| 315 | "%p -rotate %d \"%t\"" | ||
| 316 | "Format of command used to rotate thumbnail image. | ||
| 317 | Available options are %p which is replaced by | ||
| 318 | `image-dired-cmd-rotate-thumbnail-program', %d which is replaced by the | ||
| 319 | number of (positive) degrees to rotate the image, normally 90 or 270 | ||
| 320 | \(for 90 degrees right and left), %t which is replaced by the file name | ||
| 321 | of the thumbnail file." | ||
| 322 | :type 'string | ||
| 323 | :group 'image-dired) | ||
| 324 | |||
| 325 | (defcustom image-dired-cmd-rotate-original-program | ||
| 326 | "jpegtran" | ||
| 327 | "Executable used to rotate original image. | ||
| 328 | Used together with `image-dired-cmd-rotate-original-options'." | ||
| 329 | :type 'string | ||
| 330 | :group 'image-dired) | ||
| 331 | |||
| 332 | (defcustom image-dired-cmd-rotate-original-options | ||
| 333 | "%p -rotate %d -copy all -outfile %t \"%o\"" | ||
| 334 | "Format of command used to rotate original image. | ||
| 335 | Available options are %p which is replaced by | ||
| 336 | `image-dired-cmd-rotate-original-program', %d which is replaced by the | ||
| 337 | number of (positive) degrees to rotate the image, normally 90 or | ||
| 338 | 270 \(for 90 degrees right and left), %o which is replaced by the | ||
| 339 | original image file name and %t which is replaced by | ||
| 340 | `image-dired-temp-image-file'." | ||
| 341 | :type 'string | ||
| 342 | :group 'image-dired) | ||
| 343 | |||
| 344 | (defcustom image-dired-temp-rotate-image-file | ||
| 345 | "~/.emacs.d/image-dired/.image-dired_rotate_temp" | ||
| 346 | "Temporary file for rotate operations." | ||
| 347 | :type 'string | ||
| 348 | :group 'image-dired) | ||
| 349 | |||
| 350 | (defcustom image-dired-rotate-original-ask-before-overwrite t | ||
| 351 | "Confirm overwrite of original file after rotate operation. | ||
| 352 | If non-nil, ask user for confirmation before overwriting the | ||
| 353 | original file with `image-dired-temp-rotate-image-file'." | ||
| 354 | :type 'boolean | ||
| 355 | :group 'image-dired) | ||
| 356 | |||
| 357 | (defcustom image-dired-cmd-write-exif-data-program | ||
| 358 | "exiftool" | ||
| 359 | "Program used to write EXIF data to image. | ||
| 360 | Used together with `image-dired-cmd-write-exif-data-options'." | ||
| 361 | :type 'string | ||
| 362 | :group 'image-dired) | ||
| 363 | |||
| 364 | (defcustom image-dired-cmd-write-exif-data-options | ||
| 365 | "%p -%t=\"%v\" \"%f\"" | ||
| 366 | "Format of command used to write EXIF data. | ||
| 367 | Available options are %p which is replaced by | ||
| 368 | `image-dired-cmd-write-exif-data-program', %f which is replaced by the | ||
| 369 | image file name, %t which is replaced by the tag name and %v | ||
| 370 | which is replaced by the tag value." | ||
| 371 | :type 'string | ||
| 372 | :group 'image-dired) | ||
| 373 | |||
| 374 | (defcustom image-dired-cmd-read-exif-data-program | ||
| 375 | "exiftool" | ||
| 376 | "Program used to read EXIF data to image. | ||
| 377 | Used together with `image-dired-cmd-read-exif-data-program-options'." | ||
| 378 | :type 'string | ||
| 379 | :group 'image-dired) | ||
| 380 | |||
| 381 | (defcustom image-dired-cmd-read-exif-data-options | ||
| 382 | "%p -s -s -s -%t \"%f\"" | ||
| 383 | "Format of command used to read EXIF data. | ||
| 384 | Available options are %p which is replaced by | ||
| 385 | `image-dired-cmd-write-exif-data-options', %f which is replaced | ||
| 386 | by the image file name and %t which is replaced by the tag name." | ||
| 387 | :type 'string | ||
| 388 | :group 'image-dired) | ||
| 389 | |||
| 390 | (defcustom image-dired-gallery-hidden-tags | ||
| 391 | (list "private" "hidden" "pending") | ||
| 392 | "List of \"hidden\" tags. | ||
| 393 | Used by `image-dired-gallery-generate' to leave out \"hidden\" images." | ||
| 394 | :type '(repeat string) | ||
| 395 | :group 'image-dired) | ||
| 396 | |||
| 397 | (defcustom image-dired-thumb-size (if (eq 'standard image-dired-thumbnail-storage) 128 100) | ||
| 398 | "Size of thumbnails, in pixels. | ||
| 399 | This is the default size for both `image-dired-thumb-width' and `image-dired-thumb-height'." | ||
| 400 | :type 'integer | ||
| 401 | :group 'image-dired) | ||
| 402 | |||
| 403 | (defcustom image-dired-thumb-width image-dired-thumb-size | ||
| 404 | "Width of thumbnails, in pixels." | ||
| 405 | :type 'integer | ||
| 406 | :group 'image-dired) | ||
| 407 | |||
| 408 | (defcustom image-dired-thumb-height image-dired-thumb-size | ||
| 409 | "Height of thumbnails, in pixels." | ||
| 410 | :type 'integer | ||
| 411 | :group 'image-dired) | ||
| 412 | |||
| 413 | (defcustom image-dired-thumb-relief 2 | ||
| 414 | "Size of button-like border around thumbnails." | ||
| 415 | :type 'integer | ||
| 416 | :group 'image-dired) | ||
| 417 | |||
| 418 | (defcustom image-dired-thumb-margin 2 | ||
| 419 | "Size of the margin around thumbnails. | ||
| 420 | This is where you see the cursor." | ||
| 421 | :type 'integer | ||
| 422 | :group 'image-dired) | ||
| 423 | |||
| 424 | (defcustom image-dired-line-up-method 'dynamic | ||
| 425 | "Default method for line-up of thumbnails in thumbnail buffer. | ||
| 426 | Used by `image-dired-display-thumbs' and other functions that needs to | ||
| 427 | line-up thumbnails. Dynamic means to use the available width of the | ||
| 428 | window containing the thumbnail buffer, Fixed means to use | ||
| 429 | `image-dired-thumbs-per-row', Interactive is for asking the user, and No | ||
| 430 | line-up means that no automatic line-up will be done." | ||
| 431 | :type '(choice :tag "Default line-up method" | ||
| 432 | (const :tag "Dynamic" dynamic) | ||
| 433 | (const :tag "Fixed" fixed) | ||
| 434 | (const :tag "Interactive" interactive) | ||
| 435 | (const :tag "No line-up" none)) | ||
| 436 | :group 'image-dired) | ||
| 437 | |||
| 438 | (defcustom image-dired-thumbs-per-row 3 | ||
| 439 | "Number of thumbnails to display per row in thumb buffer." | ||
| 440 | :type 'integer | ||
| 441 | :group 'image-dired) | ||
| 442 | |||
| 443 | (defcustom image-dired-display-window-width-correction 1 | ||
| 444 | "Number to be used to correct image display window width. | ||
| 445 | Change if the default (1) does not work (i.e. if the image does not | ||
| 446 | completely fit)." | ||
| 447 | :type 'integer | ||
| 448 | :group 'image-dired) | ||
| 449 | |||
| 450 | (defcustom image-dired-display-window-height-correction 0 | ||
| 451 | "Number to be used to correct image display window height. | ||
| 452 | Change if the default (0) does not work (i.e. if the image does not | ||
| 453 | completely fit)." | ||
| 454 | :type 'integer | ||
| 455 | :group 'image-dired) | ||
| 456 | |||
| 457 | (defcustom image-dired-track-movement t | ||
| 458 | "The current state of the tracking and mirroring. | ||
| 459 | For more information, see the documentation for | ||
| 460 | `image-dired-toggle-movement-tracking'." | ||
| 461 | :type 'boolean | ||
| 462 | :group 'image-dired) | ||
| 463 | |||
| 464 | (defcustom image-dired-append-when-browsing nil | ||
| 465 | "Append thumbnails in thumbnail buffer when browsing. | ||
| 466 | If non-nil, using `image-dired-next-line-and-display' and | ||
| 467 | `image-dired-previous-line-and-display' will leave a trail of thumbnail | ||
| 468 | images in the thumbnail buffer. If you enable this and want to clean | ||
| 469 | the thumbnail buffer because it is filled with too many thumbmnails, | ||
| 470 | just call `image-dired-display-thumb' to display only the image at point. | ||
| 471 | This value can be toggled using `image-dired-toggle-append-browsing'." | ||
| 472 | :type 'boolean | ||
| 473 | :group 'image-dired) | ||
| 474 | |||
| 475 | (defcustom image-dired-dired-disp-props t | ||
| 476 | "If non-nil, display properties for dired file when browsing. | ||
| 477 | Used by `image-dired-next-line-and-display', | ||
| 478 | `image-dired-previous-line-and-display' and `image-dired-mark-and-display-next'. | ||
| 479 | If the database file is large, this can slow down image browsing in | ||
| 480 | dired and you might want to turn it off." | ||
| 481 | :type 'boolean | ||
| 482 | :group 'image-dired) | ||
| 483 | |||
| 484 | (defcustom image-dired-display-properties-format "%b: %f (%t): %c" | ||
| 485 | "Display format for thumbnail properties. | ||
| 486 | %b is replaced with associated dired buffer name, %f with file name | ||
| 487 | \(without path) of original image file, %t with the list of tags and %c | ||
| 488 | with the comment." | ||
| 489 | :type 'string | ||
| 490 | :group 'image-dired) | ||
| 491 | |||
| 492 | (defcustom image-dired-external-viewer | ||
| 493 | ;; TODO: Use mailcap, dired-guess-shell-alist-default, | ||
| 494 | ;; dired-view-command-alist. | ||
| 495 | (cond ((executable-find "display")) | ||
| 496 | ((executable-find "xli")) | ||
| 497 | ((executable-find "qiv") "qiv -t")) | ||
| 498 | "Name of external viewer. | ||
| 499 | Including parameters. Used when displaying original image from | ||
| 500 | `image-dired-thumbnail-mode'." | ||
| 501 | :type 'string | ||
| 502 | :group 'image-dired) | ||
| 503 | |||
| 504 | (defcustom image-dired-main-image-directory "~/pics/" | ||
| 505 | "Name of main image directory, if any. | ||
| 506 | Used by `image-dired-copy-with-exif-file-name'." | ||
| 507 | :type 'string | ||
| 508 | :group 'image-dired) | ||
| 509 | |||
| 510 | (defcustom image-dired-show-all-from-dir-max-files 50 | ||
| 511 | "Maximum number of files to show using `image-dired-show-all-from-dir'. | ||
| 512 | before warning the user." | ||
| 513 | :type 'integer | ||
| 514 | :group 'image-dired) | ||
| 515 | |||
| 516 | (defun image-dired-dir () | ||
| 517 | "Return the current thumbnails directory (from variable `image-dired-dir'). | ||
| 518 | Create the thumbnails directory if it does not exist." | ||
| 519 | (let ((image-dired-dir (file-name-as-directory | ||
| 520 | (expand-file-name image-dired-dir)))) | ||
| 521 | (unless (file-directory-p image-dired-dir) | ||
| 522 | (make-directory image-dired-dir t) | ||
| 523 | (message "Creating thumbnails directory")) | ||
| 524 | image-dired-dir)) | ||
| 525 | |||
| 526 | (defun image-dired-insert-image (file type relief margin) | ||
| 527 | "Insert image FILE of image TYPE, using RELIEF and MARGIN, at point." | ||
| 528 | |||
| 529 | (let ((i `(image :type ,type | ||
| 530 | :file ,file | ||
| 531 | :relief ,relief | ||
| 532 | :margin ,margin))) | ||
| 533 | (insert-image i))) | ||
| 534 | |||
| 535 | (defun image-dired-get-thumbnail-image (file) | ||
| 536 | "Return the image descriptor for a thumbnail of image file FILE." | ||
| 537 | (unless (string-match (image-file-name-regexp) file) | ||
| 538 | (error "%s is not a valid image file" file)) | ||
| 539 | (let ((thumb-file (image-dired-thumb-name file))) | ||
| 540 | (unless (and (file-exists-p thumb-file) | ||
| 541 | (<= (float-time (nth 5 (file-attributes file))) | ||
| 542 | (float-time (nth 5 (file-attributes thumb-file))))) | ||
| 543 | (image-dired-create-thumb file thumb-file)) | ||
| 544 | (create-image thumb-file) | ||
| 545 | ;; (list 'image :type 'jpeg | ||
| 546 | ;; :file thumb-file | ||
| 547 | ;; :relief image-dired-thumb-relief :margin image-dired-thumb-margin) | ||
| 548 | )) | ||
| 549 | |||
| 550 | (defun image-dired-insert-thumbnail (file original-file-name | ||
| 551 | associated-dired-buffer) | ||
| 552 | "Insert thumbnail image FILE. | ||
| 553 | Add text properties ORIGINAL-FILE-NAME and ASSOCIATED-DIRED-BUFFER." | ||
| 554 | (let (beg end) | ||
| 555 | (setq beg (point)) | ||
| 556 | (image-dired-insert-image file | ||
| 557 | ;; TODO: this should depend on the real file type | ||
| 558 | (if (eq 'standard image-dired-thumbnail-storage) | ||
| 559 | 'png 'jpeg) | ||
| 560 | image-dired-thumb-relief | ||
| 561 | image-dired-thumb-margin) | ||
| 562 | (setq end (point)) | ||
| 563 | (add-text-properties | ||
| 564 | beg end | ||
| 565 | (list 'image-dired-thumbnail t | ||
| 566 | 'original-file-name original-file-name | ||
| 567 | 'associated-dired-buffer associated-dired-buffer | ||
| 568 | 'tags (image-dired-list-tags original-file-name) | ||
| 569 | 'mouse-face 'highlight | ||
| 570 | 'comment (image-dired-get-comment original-file-name))))) | ||
| 571 | |||
| 572 | (defun image-dired-thumb-name (file) | ||
| 573 | "Return thumbnail file name for FILE. | ||
| 574 | Depending on the value of `image-dired-thumbnail-storage', the file | ||
| 575 | name will vary. For central thumbnail file storage, make a | ||
| 576 | MD5-hash of the image file's directory name and add that to make | ||
| 577 | the thumbnail file name unique. For per-directory storage, just | ||
| 578 | add a subdirectory. For standard storage, produce the file name | ||
| 579 | according to the Thumbnail Managing Standard." | ||
| 580 | (cond ((eq 'standard image-dired-thumbnail-storage) | ||
| 581 | (expand-file-name | ||
| 582 | (concat "~/.thumbnails/normal/" | ||
| 583 | (md5 (concat "file://" (expand-file-name file))) ".png"))) | ||
| 584 | ((eq 'use-image-dired-dir image-dired-thumbnail-storage) | ||
| 585 | (let* ((f (expand-file-name file)) | ||
| 586 | (md5-hash | ||
| 587 | ;; Is MD5 hashes fast enough? The checksum of a | ||
| 588 | ;; thumbnail file name need not be that | ||
| 589 | ;; "cryptographically" good so a faster one could | ||
| 590 | ;; be used here. | ||
| 591 | (md5 (file-name-as-directory (file-name-directory f))))) | ||
| 592 | (format "%s%s%s.thumb.%s" | ||
| 593 | (file-name-as-directory (expand-file-name (image-dired-dir))) | ||
| 594 | (file-name-sans-extension (file-name-nondirectory f)) | ||
| 595 | (if md5-hash (concat "_" md5-hash) "") | ||
| 596 | (file-name-extension f)))) | ||
| 597 | ((eq 'per-directory image-dired-thumbnail-storage) | ||
| 598 | (let ((f (expand-file-name file))) | ||
| 599 | (format "%s.image-dired/%s.thumb.%s" | ||
| 600 | (file-name-directory f) | ||
| 601 | (file-name-sans-extension (file-name-nondirectory f)) | ||
| 602 | (file-name-extension f)))))) | ||
| 603 | |||
| 604 | (defun image-dired-create-thumb (original-file thumbnail-file) | ||
| 605 | "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE." | ||
| 606 | (let* ((width (int-to-string image-dired-thumb-width)) | ||
| 607 | (height (int-to-string image-dired-thumb-height)) | ||
| 608 | (modif-time (format "%.0f" (float-time (nth 5 (file-attributes | ||
| 609 | original-file))))) | ||
| 610 | (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png" | ||
| 611 | thumbnail-file)) | ||
| 612 | (command | ||
| 613 | (format-spec | ||
| 614 | (if (eq 'standard image-dired-thumbnail-storage) | ||
| 615 | image-dired-cmd-create-standard-thumbnail-command | ||
| 616 | image-dired-cmd-create-thumbnail-options) | ||
| 617 | (list | ||
| 618 | (cons ?p image-dired-cmd-create-thumbnail-program) | ||
| 619 | (cons ?w width) | ||
| 620 | (cons ?h height) | ||
| 621 | (cons ?m modif-time) | ||
| 622 | (cons ?f original-file) | ||
| 623 | (cons ?q thumbnail-nq8-file) | ||
| 624 | (cons ?t thumbnail-file)))) | ||
| 625 | thumbnail-dir) | ||
| 626 | (when (not (file-exists-p | ||
| 627 | (setq thumbnail-dir (file-name-directory thumbnail-file)))) | ||
| 628 | (message "Creating thumbnail directory.") | ||
| 629 | (make-directory thumbnail-dir)) | ||
| 630 | (call-process shell-file-name nil nil nil shell-command-switch command))) | ||
| 631 | |||
| 632 | ;;;###autoload | ||
| 633 | (defun image-dired-dired-insert-marked-thumbs () | ||
| 634 | "Insert thumbnails before file names of marked files in the dired buffer." | ||
| 635 | (interactive) | ||
| 636 | (dired-map-over-marks | ||
| 637 | (let* ((image-pos (dired-move-to-filename)) | ||
| 638 | (image-file (dired-get-filename)) | ||
| 639 | (thumb-file (image-dired-get-thumbnail-image image-file)) | ||
| 640 | overlay) | ||
| 641 | ;; If image is not already added, then add it. | ||
| 642 | (unless (delq nil (mapcar (lambda (o) (overlay-get o 'put-image)) | ||
| 643 | ;; Can't use (overlays-at (point)), BUG? | ||
| 644 | (overlays-in (point) (1+ (point))))) | ||
| 645 | (put-image thumb-file image-pos) | ||
| 646 | (setq | ||
| 647 | overlay | ||
| 648 | (car (delq nil (mapcar (lambda (o) (and (overlay-get o 'put-image) o)) | ||
| 649 | (overlays-in (point) (1+ (point))))))) | ||
| 650 | (overlay-put overlay 'image-file image-file) | ||
| 651 | (overlay-put overlay 'thumb-file thumb-file))) | ||
| 652 | nil) | ||
| 653 | (add-hook 'dired-after-readin-hook 'image-dired-dired-after-readin-hook nil t)) | ||
| 654 | |||
| 655 | (defun image-dired-dired-after-readin-hook () | ||
| 656 | "Relocate existing thumbnail overlays in dired buffer after reverting. | ||
| 657 | Move them to their corresponding files if they are still exist. | ||
| 658 | Otherwise, delete overlays." | ||
| 659 | (mapc (lambda (overlay) | ||
| 660 | (when (overlay-get overlay 'put-image) | ||
| 661 | (let* ((image-file (overlay-get overlay 'image-file)) | ||
| 662 | (image-pos (dired-goto-file image-file))) | ||
| 663 | (if image-pos | ||
| 664 | (move-overlay overlay image-pos image-pos) | ||
| 665 | (delete-overlay overlay))))) | ||
| 666 | (overlays-in (point-min) (point-max)))) | ||
| 667 | |||
| 668 | (defun image-dired-next-line-and-display () | ||
| 669 | "Move to next dired line and display thumbnail image." | ||
| 670 | (interactive) | ||
| 671 | (dired-next-line 1) | ||
| 672 | (image-dired-display-thumbs | ||
| 673 | t (or image-dired-append-when-browsing nil) t) | ||
| 674 | (if image-dired-dired-disp-props | ||
| 675 | (image-dired-dired-display-properties))) | ||
| 676 | |||
| 677 | (defun image-dired-previous-line-and-display () | ||
| 678 | "Move to previous dired line and display thumbnail image." | ||
| 679 | (interactive) | ||
| 680 | (dired-previous-line 1) | ||
| 681 | (image-dired-display-thumbs | ||
| 682 | t (or image-dired-append-when-browsing nil) t) | ||
| 683 | (if image-dired-dired-disp-props | ||
| 684 | (image-dired-dired-display-properties))) | ||
| 685 | |||
| 686 | (defun image-dired-toggle-append-browsing () | ||
| 687 | "Toggle `image-dired-append-when-browsing'." | ||
| 688 | (interactive) | ||
| 689 | (setq image-dired-append-when-browsing | ||
| 690 | (not image-dired-append-when-browsing)) | ||
| 691 | (message "Append browsing %s." | ||
| 692 | (if image-dired-append-when-browsing | ||
| 693 | "on" | ||
| 694 | "off"))) | ||
| 695 | |||
| 696 | (defun image-dired-mark-and-display-next () | ||
| 697 | "Mark current file in dired and display next thumbnail image." | ||
| 698 | (interactive) | ||
| 699 | (dired-mark 1) | ||
| 700 | (image-dired-display-thumbs | ||
| 701 | t (or image-dired-append-when-browsing nil) t) | ||
| 702 | (if image-dired-dired-disp-props | ||
| 703 | (image-dired-dired-display-properties))) | ||
| 704 | |||
| 705 | (defun image-dired-toggle-dired-display-properties () | ||
| 706 | "Toggle `image-dired-dired-disp-props'." | ||
| 707 | (interactive) | ||
| 708 | (setq image-dired-dired-disp-props | ||
| 709 | (not image-dired-dired-disp-props)) | ||
| 710 | (message "Dired display properties %s." | ||
| 711 | (if image-dired-dired-disp-props | ||
| 712 | "on" | ||
| 713 | "off"))) | ||
| 714 | |||
| 715 | (defvar image-dired-thumbnail-buffer "*image-dired*" | ||
| 716 | "Image-Dired's thumbnail buffer.") | ||
| 717 | |||
| 718 | (defun image-dired-create-thumbnail-buffer () | ||
| 719 | "Create thumb buffer and set `image-dired-thumbnail-mode'." | ||
| 720 | (let ((buf (get-buffer-create image-dired-thumbnail-buffer))) | ||
| 721 | (with-current-buffer buf | ||
| 722 | (setq buffer-read-only t) | ||
| 723 | (if (not (eq major-mode 'image-dired-thumbnail-mode)) | ||
| 724 | (image-dired-thumbnail-mode))) | ||
| 725 | buf)) | ||
| 726 | |||
| 727 | (defvar image-dired-display-image-buffer "*image-dired-display-image*" | ||
| 728 | "Where larger versions of the images are display.") | ||
| 729 | |||
| 730 | (defun image-dired-create-display-image-buffer () | ||
| 731 | "Create image display buffer and set `image-dired-display-image-mode'." | ||
| 732 | (let ((buf (get-buffer-create image-dired-display-image-buffer))) | ||
| 733 | (with-current-buffer buf | ||
| 734 | (setq buffer-read-only t) | ||
| 735 | (if (not (eq major-mode 'image-dired-display-image-mode)) | ||
| 736 | (image-dired-display-image-mode))) | ||
| 737 | buf)) | ||
| 738 | |||
| 739 | (defvar image-dired-saved-window-configuration nil | ||
| 740 | "Saved window configuration.") | ||
| 741 | |||
| 742 | ;;;###autoload | ||
| 743 | (defun image-dired-dired-with-window-configuration (dir &optional arg) | ||
| 744 | "Open directory DIR and create a default window configuration. | ||
| 745 | |||
| 746 | Convenience command that: | ||
| 747 | |||
| 748 | - Opens dired in folder DIR | ||
| 749 | - Splits windows in most useful (?) way | ||
| 750 | - Set `truncate-lines' to t | ||
| 751 | |||
| 752 | After the command has finished, you would typically mark some | ||
| 753 | image files in dired and type | ||
| 754 | \\[image-dired-display-thumbs] (`image-dired-display-thumbs'). | ||
| 755 | |||
| 756 | If called with prefix argument ARG, skip splitting of windows. | ||
| 757 | |||
| 758 | The current window configuration is saved and can be restored by | ||
| 759 | calling `image-dired-restore-window-configuration'." | ||
| 760 | (interactive "DDirectory: \nP") | ||
| 761 | (let ((buf (image-dired-create-thumbnail-buffer)) | ||
| 762 | (buf2 (image-dired-create-display-image-buffer))) | ||
| 763 | (setq image-dired-saved-window-configuration | ||
| 764 | (current-window-configuration)) | ||
| 765 | (dired dir) | ||
| 766 | (delete-other-windows) | ||
| 767 | (when (not arg) | ||
| 768 | (split-window-horizontally) | ||
| 769 | (setq truncate-lines t) | ||
| 770 | (save-excursion | ||
| 771 | (other-window 1) | ||
| 772 | (switch-to-buffer buf) | ||
| 773 | (split-window-vertically) | ||
| 774 | (other-window 1) | ||
| 775 | (switch-to-buffer buf2) | ||
| 776 | (other-window -2))))) | ||
| 777 | |||
| 778 | (defun image-dired-restore-window-configuration () | ||
| 779 | "Restore window configuration. | ||
| 780 | Restore any changes to the window configuration made by calling | ||
| 781 | `image-dired-dired-with-window-configuration'." | ||
| 782 | (interactive) | ||
| 783 | (if image-dired-saved-window-configuration | ||
| 784 | (set-window-configuration image-dired-saved-window-configuration) | ||
| 785 | (message "No saved window configuration"))) | ||
| 786 | |||
| 787 | ;;;###autoload | ||
| 788 | (defun image-dired-display-thumbs (&optional arg append do-not-pop) | ||
| 789 | "Display thumbnails of all marked files, in `image-dired-thumbnail-buffer'. | ||
| 790 | If a thumbnail image does not exist for a file, it is created on the | ||
| 791 | fly. With prefix argument ARG, display only thumbnail for file at | ||
| 792 | point (this is useful if you have marked some files but want to show | ||
| 793 | another one). | ||
| 794 | |||
| 795 | Recommended usage is to split the current frame horizontally so that | ||
| 796 | you have the dired buffer in the left window and the | ||
| 797 | `image-dired-thumbnail-buffer' buffer in the right window. | ||
| 798 | |||
| 799 | With optional argument APPEND, append thumbnail to thumbnail buffer | ||
| 800 | instead of erasing it first. | ||
| 801 | |||
| 802 | Option argument DO-NOT-POP controls if `pop-to-buffer' should be | ||
| 803 | used or not. If non-nil, use `display-buffer' instead of | ||
| 804 | `pop-to-buffer'. This is used from functions like | ||
| 805 | `image-dired-next-line-and-display' and | ||
| 806 | `image-dired-previous-line-and-display' where we do not want the | ||
| 807 | thumbnail buffer to be selected." | ||
| 808 | (interactive "P") | ||
| 809 | (let ((buf (image-dired-create-thumbnail-buffer)) | ||
| 810 | curr-file thumb-name files count dired-buf beg) | ||
| 811 | (if arg | ||
| 812 | (setq files (list (dired-get-filename))) | ||
| 813 | (setq files (dired-get-marked-files))) | ||
| 814 | (setq dired-buf (current-buffer)) | ||
| 815 | (with-current-buffer buf | ||
| 816 | (let ((inhibit-read-only t)) | ||
| 817 | (if (not append) | ||
| 818 | (erase-buffer) | ||
| 819 | (goto-char (point-max))) | ||
| 820 | (mapcar | ||
| 821 | (lambda (curr-file) | ||
| 822 | (setq thumb-name (image-dired-thumb-name curr-file)) | ||
| 823 | (if (and (not (file-exists-p thumb-name)) | ||
| 824 | (not (= 0 (image-dired-create-thumb curr-file thumb-name)))) | ||
| 825 | (message "Thumb could not be created for file %s" curr-file) | ||
| 826 | (image-dired-insert-thumbnail thumb-name curr-file dired-buf))) | ||
| 827 | files)) | ||
| 828 | (cond ((eq 'dynamic image-dired-line-up-method) | ||
| 829 | (image-dired-line-up-dynamic)) | ||
| 830 | ((eq 'fixed image-dired-line-up-method) | ||
| 831 | (image-dired-line-up)) | ||
| 832 | ((eq 'interactive image-dired-line-up-method) | ||
| 833 | (image-dired-line-up-interactive)) | ||
| 834 | ((eq 'none image-dired-line-up-method) | ||
| 835 | nil) | ||
| 836 | (t | ||
| 837 | (image-dired-line-up-dynamic)))) | ||
| 838 | (if do-not-pop | ||
| 839 | (display-buffer image-dired-thumbnail-buffer) | ||
| 840 | (pop-to-buffer image-dired-thumbnail-buffer)))) | ||
| 841 | |||
| 842 | ;;;###autoload | ||
| 843 | (defun image-dired-show-all-from-dir (dir) | ||
| 844 | "Make a preview buffer for all images in DIR and display it. | ||
| 845 | If the number of files in DIR matching `image-file-name-regexp' | ||
| 846 | exceeds `image-dired-show-all-from-dir-max-files', a warning will be | ||
| 847 | displayed." | ||
| 848 | (interactive "DDir: ") | ||
| 849 | (dired dir) | ||
| 850 | (dired-mark-files-regexp (image-file-name-regexp)) | ||
| 851 | (let ((files (dired-get-marked-files))) | ||
| 852 | (if (or (<= (length files) image-dired-show-all-from-dir-max-files) | ||
| 853 | (and (> (length files) image-dired-show-all-from-dir-max-files) | ||
| 854 | (y-or-n-p | ||
| 855 | (format | ||
| 856 | "Directory contains more than %d image files. Proceed? " | ||
| 857 | image-dired-show-all-from-dir-max-files)))) | ||
| 858 | (progn | ||
| 859 | (image-dired-display-thumbs) | ||
| 860 | (pop-to-buffer image-dired-thumbnail-buffer)) | ||
| 861 | (message "Cancelled.")))) | ||
| 862 | |||
| 863 | ;;;###autoload | ||
| 864 | (defalias 'image-dired 'image-dired-show-all-from-dir) | ||
| 865 | |||
| 866 | ;;;###autoload | ||
| 867 | (defalias 'tumme 'image-dired-show-all-from-dir) | ||
| 868 | |||
| 869 | (defun image-dired-write-tags (file-tags) | ||
| 870 | "Write file tags to database. | ||
| 871 | Write each file and tag in FILE-TAGS to the database. FILE-TAGS | ||
| 872 | is an alist in the following form: | ||
| 873 | ((FILE . TAG) ... )" | ||
| 874 | (let (end file tag) | ||
| 875 | (with-temp-file image-dired-db-file | ||
| 876 | (insert-file-contents image-dired-db-file) | ||
| 877 | (dolist (elt file-tags) | ||
| 878 | (setq file (car elt) | ||
| 879 | tag (cdr elt)) | ||
| 880 | (goto-char (point-min)) | ||
| 881 | (if (search-forward-regexp (format "^%s.*$" file) nil t) | ||
| 882 | (progn | ||
| 883 | (setq end (point)) | ||
| 884 | (beginning-of-line) | ||
| 885 | (when (not (search-forward (format ";%s" tag) end t)) | ||
| 886 | (end-of-line) | ||
| 887 | (insert (format ";%s" tag)))) | ||
| 888 | (goto-char (point-max)) | ||
| 889 | (insert (format "\n%s;%s" file tag))))))) | ||
| 890 | |||
| 891 | (defun image-dired-remove-tag (files tag) | ||
| 892 | "For all FILES, remove TAG from the image database." | ||
| 893 | (save-excursion | ||
| 894 | (let (end buf start) | ||
| 895 | (setq buf (find-file image-dired-db-file)) | ||
| 896 | (if (not (listp files)) | ||
| 897 | (if (stringp files) | ||
| 898 | (setq files (list files)) | ||
| 899 | (error "Files must be a string or a list of strings!"))) | ||
| 900 | (mapcar | ||
| 901 | (lambda (file) | ||
| 902 | (goto-char (point-min)) | ||
| 903 | (when (search-forward-regexp | ||
| 904 | (format "^%s" file) nil t) | ||
| 905 | (end-of-line) | ||
| 906 | (setq end (point)) | ||
| 907 | (beginning-of-line) | ||
| 908 | (when (search-forward-regexp (format "\\(;%s\\)" tag) end t) | ||
| 909 | (delete-region (match-beginning 1) (match-end 1)) | ||
| 910 | ;; Check if file should still be in the database. If | ||
| 911 | ;; it has no tags or comments, it will be removed. | ||
| 912 | (end-of-line) | ||
| 913 | (setq end (point)) | ||
| 914 | (beginning-of-line) | ||
| 915 | (when (not (search-forward ";" end t)) | ||
| 916 | (kill-line 1) | ||
| 917 | ;; If on empty line at end of buffer | ||
| 918 | (when (and (eobp) | ||
| 919 | (looking-at "^$")) | ||
| 920 | (delete-backward-char 1)))))) | ||
| 921 | files) | ||
| 922 | (save-buffer) | ||
| 923 | (kill-buffer buf)))) | ||
| 924 | |||
| 925 | (defun image-dired-list-tags (file) | ||
| 926 | "Read all tags for image FILE from the image database." | ||
| 927 | (save-excursion | ||
| 928 | (let (end buf (tags "")) | ||
| 929 | (setq buf (find-file image-dired-db-file)) | ||
| 930 | (goto-char (point-min)) | ||
| 931 | (when (search-forward-regexp | ||
| 932 | (format "^%s" file) nil t) | ||
| 933 | (end-of-line) | ||
| 934 | (setq end (point)) | ||
| 935 | (beginning-of-line) | ||
| 936 | (if (search-forward ";" end t) | ||
| 937 | (if (search-forward "comment:" end t) | ||
| 938 | (if (search-forward ";" end t) | ||
| 939 | (setq tags (buffer-substring (point) end))) | ||
| 940 | (setq tags (buffer-substring (point) end))))) | ||
| 941 | (kill-buffer buf) | ||
| 942 | (split-string tags ";")))) | ||
| 943 | |||
| 944 | ;;;###autoload | ||
| 945 | (defun image-dired-tag-files (arg) | ||
| 946 | "Tag marked file(s) in dired. With prefix ARG, tag file at point." | ||
| 947 | (interactive "P") | ||
| 948 | (let ((tag (read-string "Tags to add (separate tags with a semicolon): ")) | ||
| 949 | curr-file files) | ||
| 950 | (if arg | ||
| 951 | (setq files (list (dired-get-filename))) | ||
| 952 | (setq files (dired-get-marked-files))) | ||
| 953 | (image-dired-write-tags | ||
| 954 | (mapcar | ||
| 955 | (lambda (x) | ||
| 956 | (cons x tag)) | ||
| 957 | files)))) | ||
| 958 | |||
| 959 | (defun image-dired-tag-thumbnail () | ||
| 960 | "Tag current thumbnail." | ||
| 961 | (interactive) | ||
| 962 | (let ((tag (read-string "Tags to add (separate tags with a semicolon): "))) | ||
| 963 | (image-dired-write-tags (list (cons (image-dired-original-file-name) tag)))) | ||
| 964 | (image-dired-update-property | ||
| 965 | 'tags (image-dired-list-tags (image-dired-original-file-name)))) | ||
| 966 | |||
| 967 | ;;;###autoload | ||
| 968 | (defun image-dired-delete-tag (arg) | ||
| 969 | "Remove tag for selected file(s). | ||
| 970 | With prefix argument ARG, remove tag from file at point." | ||
| 971 | (interactive "P") | ||
| 972 | (let ((tag (read-string "Tag to remove: ")) | ||
| 973 | files) | ||
| 974 | (if arg | ||
| 975 | (setq files (list (dired-get-filename))) | ||
| 976 | (setq files (dired-get-marked-files))) | ||
| 977 | (image-dired-remove-tag files tag))) | ||
| 978 | |||
| 979 | (defun image-dired-tag-thumbnail-remove () | ||
| 980 | "Remove tag from thumbnail." | ||
| 981 | (interactive) | ||
| 982 | (let ((tag (read-string "Tag to remove: "))) | ||
| 983 | (image-dired-remove-tag (image-dired-original-file-name) tag)) | ||
| 984 | (image-dired-update-property | ||
| 985 | 'tags (image-dired-list-tags (image-dired-original-file-name)))) | ||
| 986 | |||
| 987 | (defun image-dired-original-file-name () | ||
| 988 | "Get original file name for thumbnail or display image at point." | ||
| 989 | (get-text-property (point) 'original-file-name)) | ||
| 990 | |||
| 991 | (defun image-dired-associated-dired-buffer () | ||
| 992 | "Get associated dired buffer at point." | ||
| 993 | (get-text-property (point) 'associated-dired-buffer)) | ||
| 994 | |||
| 995 | (defun image-dired-get-buffer-window (buf) | ||
| 996 | "Return window where buffer BUF is." | ||
| 997 | (get-window-with-predicate | ||
| 998 | (lambda (window) | ||
| 999 | (equal (window-buffer window) buf)) | ||
| 1000 | nil t)) | ||
| 1001 | |||
| 1002 | (defun image-dired-track-original-file () | ||
| 1003 | "Track the original file in the associated dired buffer. | ||
| 1004 | See documentation for `image-dired-toggle-movement-tracking'. Interactive | ||
| 1005 | use only useful if `image-dired-track-movement' is nil." | ||
| 1006 | (interactive) | ||
| 1007 | (let ((old-buf (current-buffer)) | ||
| 1008 | (dired-buf (image-dired-associated-dired-buffer)) | ||
| 1009 | (file-name (image-dired-original-file-name))) | ||
| 1010 | (when (and (buffer-live-p dired-buf) file-name) | ||
| 1011 | (setq file-name (file-name-nondirectory file-name)) | ||
| 1012 | (set-buffer dired-buf) | ||
| 1013 | (goto-char (point-min)) | ||
| 1014 | (if (not (search-forward file-name nil t)) | ||
| 1015 | (message "Could not track file") | ||
| 1016 | (dired-move-to-filename) | ||
| 1017 | (set-window-point | ||
| 1018 | (image-dired-get-buffer-window dired-buf) (point))) | ||
| 1019 | (set-buffer old-buf)))) | ||
| 1020 | |||
| 1021 | (defun image-dired-toggle-movement-tracking () | ||
| 1022 | "Turn on and off `image-dired-track-movement'. | ||
| 1023 | Tracking of the movements between thumbnail and dired buffer so that | ||
| 1024 | they are \"mirrored\" in the dired buffer. When this is on, moving | ||
| 1025 | around in the thumbnail or dired buffer will find the matching | ||
| 1026 | position in the other buffer." | ||
| 1027 | (interactive) | ||
| 1028 | (setq image-dired-track-movement (not image-dired-track-movement)) | ||
| 1029 | (message "Tracking %s" (if image-dired-track-movement "on" "off"))) | ||
| 1030 | |||
| 1031 | (defun image-dired-track-thumbnail () | ||
| 1032 | "Track current dired file's thumb in `image-dired-thumbnail-buffer'. | ||
| 1033 | This is almost the same as what `image-dired-track-original-file' does, but | ||
| 1034 | the other way around." | ||
| 1035 | (let ((file (dired-get-filename)) | ||
| 1036 | (old-buf (current-buffer)) | ||
| 1037 | prop-val found) | ||
| 1038 | (when (get-buffer image-dired-thumbnail-buffer) | ||
| 1039 | (set-buffer image-dired-thumbnail-buffer) | ||
| 1040 | (goto-char (point-min)) | ||
| 1041 | (while (and (not (eobp)) | ||
| 1042 | (not found)) | ||
| 1043 | (if (and (setq prop-val | ||
| 1044 | (get-text-property (point) 'original-file-name)) | ||
| 1045 | (string= prop-val file)) | ||
| 1046 | (setq found t)) | ||
| 1047 | (if (not found) | ||
| 1048 | (forward-char 1))) | ||
| 1049 | (when found | ||
| 1050 | (set-window-point | ||
| 1051 | (image-dired-thumbnail-window) (point)) | ||
| 1052 | (image-dired-display-thumb-properties)) | ||
| 1053 | (set-buffer old-buf)))) | ||
| 1054 | |||
| 1055 | (defun image-dired-dired-next-line (&optional arg) | ||
| 1056 | "Call `dired-next-line', then track thumbnail. | ||
| 1057 | This can safely replace `dired-next-line'. With prefix argument, move | ||
| 1058 | ARG lines." | ||
| 1059 | (interactive "P") | ||
| 1060 | (dired-next-line (or arg 1)) | ||
| 1061 | (if image-dired-track-movement | ||
| 1062 | (image-dired-track-thumbnail))) | ||
| 1063 | |||
| 1064 | (defun image-dired-dired-previous-line (&optional arg) | ||
| 1065 | "Call `dired-previous-line', then track thumbnail. | ||
| 1066 | This can safely replace `dired-previous-line'. With prefix argument, | ||
| 1067 | move ARG lines." | ||
| 1068 | (interactive "P") | ||
| 1069 | (dired-previous-line (or arg 1)) | ||
| 1070 | (if image-dired-track-movement | ||
| 1071 | (image-dired-track-thumbnail))) | ||
| 1072 | |||
| 1073 | (defun image-dired-forward-image (&optional arg) | ||
| 1074 | "Move to next image and display properties. | ||
| 1075 | Optional prefix ARG says how many images to move; default is one | ||
| 1076 | image." | ||
| 1077 | (interactive "p") | ||
| 1078 | (let (pos (steps (or arg 1))) | ||
| 1079 | (dotimes (i steps) | ||
| 1080 | (if (and (not (eobp)) | ||
| 1081 | (save-excursion | ||
| 1082 | (forward-char) | ||
| 1083 | (while (and (not (eobp)) | ||
| 1084 | (not (image-dired-image-at-point-p))) | ||
| 1085 | (forward-char)) | ||
| 1086 | (setq pos (point)) | ||
| 1087 | (image-dired-image-at-point-p))) | ||
| 1088 | (goto-char pos) | ||
| 1089 | (error "At last image")))) | ||
| 1090 | (when image-dired-track-movement | ||
| 1091 | (image-dired-track-original-file)) | ||
| 1092 | (image-dired-display-thumb-properties)) | ||
| 1093 | |||
| 1094 | (defun image-dired-backward-image (&optional arg) | ||
| 1095 | "Move to previous image and display properties. | ||
| 1096 | Optional prefix ARG says how many images to move; default is one | ||
| 1097 | image." | ||
| 1098 | (interactive "p") | ||
| 1099 | (let (pos (steps (or arg 1))) | ||
| 1100 | (dotimes (i steps) | ||
| 1101 | (if (and (not (bobp)) | ||
| 1102 | (save-excursion | ||
| 1103 | (backward-char) | ||
| 1104 | (while (and (not (bobp)) | ||
| 1105 | (not (image-dired-image-at-point-p))) | ||
| 1106 | (backward-char)) | ||
| 1107 | (setq pos (point)) | ||
| 1108 | (image-dired-image-at-point-p))) | ||
| 1109 | (goto-char pos) | ||
| 1110 | (error "At first image")))) | ||
| 1111 | (when image-dired-track-movement | ||
| 1112 | (image-dired-track-original-file)) | ||
| 1113 | (image-dired-display-thumb-properties)) | ||
| 1114 | |||
| 1115 | (defun image-dired-next-line () | ||
| 1116 | "Move to next line and display properties." | ||
| 1117 | (interactive) | ||
| 1118 | (next-line 1) | ||
| 1119 | ;; If we end up in an empty spot, back up to the next thumbnail. | ||
| 1120 | (if (not (image-dired-image-at-point-p)) | ||
| 1121 | (image-dired-backward-image)) | ||
| 1122 | (if image-dired-track-movement | ||
| 1123 | (image-dired-track-original-file)) | ||
| 1124 | (image-dired-display-thumb-properties)) | ||
| 1125 | |||
| 1126 | |||
| 1127 | (defun image-dired-previous-line () | ||
| 1128 | "Move to previous line and display properties." | ||
| 1129 | (interactive) | ||
| 1130 | (previous-line 1) | ||
| 1131 | ;; If we end up in an empty spot, back up to the next | ||
| 1132 | ;; thumbnail. This should only happen if the user deleted a | ||
| 1133 | ;; thumbnail and did not refresh, so it is not very common. But we | ||
| 1134 | ;; can handle it in a good manner, so why not? | ||
| 1135 | (if (not (image-dired-image-at-point-p)) | ||
| 1136 | (image-dired-backward-image)) | ||
| 1137 | (if image-dired-track-movement | ||
| 1138 | (image-dired-track-original-file)) | ||
| 1139 | (image-dired-display-thumb-properties)) | ||
| 1140 | |||
| 1141 | (defun image-dired-format-properties-string (buf file props comment) | ||
| 1142 | "Format display properties. | ||
| 1143 | BUF is the associated dired buffer, FILE is the original image file | ||
| 1144 | name, PROPS is a list of tags and COMMENT is the image files's | ||
| 1145 | comment." | ||
| 1146 | (format-spec | ||
| 1147 | image-dired-display-properties-format | ||
| 1148 | (list | ||
| 1149 | (cons ?b (or buf "")) | ||
| 1150 | (cons ?f file) | ||
| 1151 | (cons ?t (or (princ props) "")) | ||
| 1152 | (cons ?c (or comment ""))))) | ||
| 1153 | |||
| 1154 | (defun image-dired-display-thumb-properties () | ||
| 1155 | "Display thumbnail properties in the echo area." | ||
| 1156 | (if (not (eobp)) | ||
| 1157 | (let ((file-name (file-name-nondirectory (image-dired-original-file-name))) | ||
| 1158 | (dired-buf (buffer-name (image-dired-associated-dired-buffer))) | ||
| 1159 | (props (mapconcat | ||
| 1160 | 'princ | ||
| 1161 | (get-text-property (point) 'tags) | ||
| 1162 | ", ")) | ||
| 1163 | (comment (get-text-property (point) 'comment))) | ||
| 1164 | (if file-name | ||
| 1165 | (message | ||
| 1166 | (image-dired-format-properties-string | ||
| 1167 | dired-buf | ||
| 1168 | file-name | ||
| 1169 | props | ||
| 1170 | comment)))))) | ||
| 1171 | |||
| 1172 | (defun image-dired-dired-file-marked-p () | ||
| 1173 | "Check whether file on current line is marked or not." | ||
| 1174 | (save-excursion | ||
| 1175 | (beginning-of-line) | ||
| 1176 | (not (looking-at "^ .*$")))) | ||
| 1177 | |||
| 1178 | (defun image-dired-modify-mark-on-thumb-original-file (command) | ||
| 1179 | "Modify mark in dired buffer. | ||
| 1180 | This is quite ugly but I don't know how to implemented in a better | ||
| 1181 | way. COMMAND is one of 'mark for marking file in dired, 'unmark for | ||
| 1182 | unmarking file in dired or 'flag for flagging file for delete in | ||
| 1183 | dired." | ||
| 1184 | (let ((file-name (image-dired-original-file-name)) | ||
| 1185 | (dired-buf (image-dired-associated-dired-buffer))) | ||
| 1186 | (if (not (and dired-buf file-name)) | ||
| 1187 | (message "No image, or image with correct properties, at point.") | ||
| 1188 | (with-current-buffer dired-buf | ||
| 1189 | (message file-name) | ||
| 1190 | (setq file-name (file-name-nondirectory file-name)) | ||
| 1191 | (goto-char (point-min)) | ||
| 1192 | (if (search-forward file-name nil t) | ||
| 1193 | (cond ((eq command 'mark) (dired-mark 1)) | ||
| 1194 | ((eq command 'unmark) (dired-unmark 1)) | ||
| 1195 | ((eq command 'toggle) | ||
| 1196 | (if (image-dired-dired-file-marked-p) | ||
| 1197 | (dired-unmark 1) | ||
| 1198 | (dired-mark 1))) | ||
| 1199 | ((eq command 'flag) (dired-flag-file-deletion 1)))))))) | ||
| 1200 | |||
| 1201 | (defun image-dired-mark-thumb-original-file () | ||
| 1202 | "Mark original image file in associated dired buffer." | ||
| 1203 | (interactive) | ||
| 1204 | (image-dired-modify-mark-on-thumb-original-file 'mark) | ||
| 1205 | (image-dired-forward-image)) | ||
| 1206 | |||
| 1207 | (defun image-dired-unmark-thumb-original-file () | ||
| 1208 | "Unmark original image file in associated dired buffer." | ||
| 1209 | (interactive) | ||
| 1210 | (image-dired-modify-mark-on-thumb-original-file 'unmark) | ||
| 1211 | (image-dired-forward-image)) | ||
| 1212 | |||
| 1213 | (defun image-dired-flag-thumb-original-file () | ||
| 1214 | "Flag original image file for deletion in associated dired buffer." | ||
| 1215 | (interactive) | ||
| 1216 | (image-dired-modify-mark-on-thumb-original-file 'flag) | ||
| 1217 | (image-dired-forward-image)) | ||
| 1218 | |||
| 1219 | (defun image-dired-toggle-mark-thumb-original-file () | ||
| 1220 | "Toggle mark on original image file in associated dired buffer." | ||
| 1221 | (interactive) | ||
| 1222 | (image-dired-modify-mark-on-thumb-original-file 'toggle)) | ||
| 1223 | |||
| 1224 | (defun image-dired-jump-original-dired-buffer () | ||
| 1225 | "Jump to the dired buffer associated with the current image file. | ||
| 1226 | You probably want to use this together with | ||
| 1227 | `image-dired-track-original-file'." | ||
| 1228 | (interactive) | ||
| 1229 | (let ((buf (image-dired-associated-dired-buffer)) | ||
| 1230 | window frame) | ||
| 1231 | (setq window (image-dired-get-buffer-window buf)) | ||
| 1232 | (if window | ||
| 1233 | (progn | ||
| 1234 | (if (not (equal (selected-frame) (setq frame (window-frame window)))) | ||
| 1235 | (select-frame-set-input-focus frame)) | ||
| 1236 | (select-window window)) | ||
| 1237 | (message "Associated dired buffer not visible")))) | ||
| 1238 | |||
| 1239 | ;;;###autoload | ||
| 1240 | (defun image-dired-jump-thumbnail-buffer () | ||
| 1241 | "Jump to thumbnail buffer." | ||
| 1242 | (interactive) | ||
| 1243 | (let ((window (image-dired-thumbnail-window)) | ||
| 1244 | frame) | ||
| 1245 | (if window | ||
| 1246 | (progn | ||
| 1247 | (if (not (equal (selected-frame) (setq frame (window-frame window)))) | ||
| 1248 | (select-frame-set-input-focus frame)) | ||
| 1249 | (select-window window)) | ||
| 1250 | (message "Thumbnail buffer not visible")))) | ||
| 1251 | |||
| 1252 | (defvar image-dired-thumbnail-mode-map (make-sparse-keymap) | ||
| 1253 | "Keymap for `image-dired-thumbnail-mode'.") | ||
| 1254 | |||
| 1255 | (defvar image-dired-thumbnail-mode-line-up-map (make-sparse-keymap) | ||
| 1256 | "Keymap for line-up commands in `image-dired-thumbnail-mode'.") | ||
| 1257 | |||
| 1258 | (defvar image-dired-thumbnail-mode-tag-map (make-sparse-keymap) | ||
| 1259 | "Keymap for tag commands in `image-dired-thumbnail-mode'.") | ||
| 1260 | |||
| 1261 | (defun image-dired-define-thumbnail-mode-keymap () | ||
| 1262 | "Define keymap for `image-dired-thumbnail-mode'." | ||
| 1263 | |||
| 1264 | ;; Keys | ||
| 1265 | (define-key image-dired-thumbnail-mode-map [right] 'image-dired-forward-image) | ||
| 1266 | (define-key image-dired-thumbnail-mode-map [left] 'image-dired-backward-image) | ||
| 1267 | (define-key image-dired-thumbnail-mode-map [up] 'image-dired-previous-line) | ||
| 1268 | (define-key image-dired-thumbnail-mode-map [down] 'image-dired-next-line) | ||
| 1269 | (define-key image-dired-thumbnail-mode-map "\C-f" 'image-dired-forward-image) | ||
| 1270 | (define-key image-dired-thumbnail-mode-map "\C-b" 'image-dired-backward-image) | ||
| 1271 | (define-key image-dired-thumbnail-mode-map "\C-p" 'image-dired-previous-line) | ||
| 1272 | (define-key image-dired-thumbnail-mode-map "\C-n" 'image-dired-next-line) | ||
| 1273 | |||
| 1274 | (define-key image-dired-thumbnail-mode-map "d" 'image-dired-flag-thumb-original-file) | ||
| 1275 | (define-key image-dired-thumbnail-mode-map [delete] | ||
| 1276 | 'image-dired-flag-thumb-original-file) | ||
| 1277 | (define-key image-dired-thumbnail-mode-map "m" 'image-dired-mark-thumb-original-file) | ||
| 1278 | (define-key image-dired-thumbnail-mode-map "u" 'image-dired-unmark-thumb-original-file) | ||
| 1279 | (define-key image-dired-thumbnail-mode-map "." 'image-dired-track-original-file) | ||
| 1280 | (define-key image-dired-thumbnail-mode-map [tab] 'image-dired-jump-original-dired-buffer) | ||
| 1281 | |||
| 1282 | ;; add line-up map | ||
| 1283 | (define-key image-dired-thumbnail-mode-map "g" image-dired-thumbnail-mode-line-up-map) | ||
| 1284 | |||
| 1285 | ;; map it to "g" so that the user can press it more quickly | ||
| 1286 | (define-key image-dired-thumbnail-mode-line-up-map "g" 'image-dired-line-up-dynamic) | ||
| 1287 | ;; "f" for "fixed" number of thumbs per row | ||
| 1288 | (define-key image-dired-thumbnail-mode-line-up-map "f" 'image-dired-line-up) | ||
| 1289 | ;; "i" for "interactive" | ||
| 1290 | (define-key image-dired-thumbnail-mode-line-up-map "i" 'image-dired-line-up-interactive) | ||
| 1291 | |||
| 1292 | ;; add tag map | ||
| 1293 | (define-key image-dired-thumbnail-mode-map "t" image-dired-thumbnail-mode-tag-map) | ||
| 1294 | |||
| 1295 | ;; map it to "t" so that the user can press it more quickly | ||
| 1296 | (define-key image-dired-thumbnail-mode-tag-map "t" 'image-dired-tag-thumbnail) | ||
| 1297 | ;; "r" for "remove" | ||
| 1298 | (define-key image-dired-thumbnail-mode-tag-map "r" 'image-dired-tag-thumbnail-remove) | ||
| 1299 | |||
| 1300 | (define-key image-dired-thumbnail-mode-map "\C-m" | ||
| 1301 | 'image-dired-display-thumbnail-original-image) | ||
| 1302 | (define-key image-dired-thumbnail-mode-map [C-return] | ||
| 1303 | 'image-dired-thumbnail-display-external) | ||
| 1304 | |||
| 1305 | (define-key image-dired-thumbnail-mode-map "l" 'image-dired-rotate-thumbnail-left) | ||
| 1306 | (define-key image-dired-thumbnail-mode-map "r" 'image-dired-rotate-thumbnail-right) | ||
| 1307 | |||
| 1308 | (define-key image-dired-thumbnail-mode-map "L" 'image-dired-rotate-original-left) | ||
| 1309 | (define-key image-dired-thumbnail-mode-map "R" 'image-dired-rotate-original-right) | ||
| 1310 | |||
| 1311 | (define-key image-dired-thumbnail-mode-map "D" | ||
| 1312 | 'image-dired-thumbnail-set-image-description) | ||
| 1313 | |||
| 1314 | (define-key image-dired-thumbnail-mode-map "\C-d" 'image-dired-delete-char) | ||
| 1315 | (define-key image-dired-thumbnail-mode-map " " | ||
| 1316 | 'image-dired-display-next-thumbnail-original) | ||
| 1317 | (define-key image-dired-thumbnail-mode-map | ||
| 1318 | (kbd "DEL") 'image-dired-display-previous-thumbnail-original) | ||
| 1319 | (define-key image-dired-thumbnail-mode-map "c" 'image-dired-comment-thumbnail) | ||
| 1320 | (define-key image-dired-thumbnail-mode-map "q" 'image-dired-kill-buffer-and-window) | ||
| 1321 | |||
| 1322 | ;; Mouse | ||
| 1323 | (define-key image-dired-thumbnail-mode-map [mouse-2] 'image-dired-mouse-display-image) | ||
| 1324 | (define-key image-dired-thumbnail-mode-map [mouse-1] 'image-dired-mouse-select-thumbnail) | ||
| 1325 | |||
| 1326 | ;; Seems I must first set C-down-mouse-1 to undefined, or else it | ||
| 1327 | ;; will trigger the buffer menu. If I try to instead bind | ||
| 1328 | ;; C-down-mouse-1 to `image-dired-mouse-toggle-mark', I get a message | ||
| 1329 | ;; about C-mouse-1 not being defined afterwards. Annoying, but I | ||
| 1330 | ;; probably do not completely understand mouse events. | ||
| 1331 | |||
| 1332 | (define-key image-dired-thumbnail-mode-map [C-down-mouse-1] 'undefined) | ||
| 1333 | (define-key image-dired-thumbnail-mode-map [C-mouse-1] 'image-dired-mouse-toggle-mark) | ||
| 1334 | |||
| 1335 | ;; Menu | ||
| 1336 | (define-key image-dired-thumbnail-mode-map [menu-bar image-dired] | ||
| 1337 | (cons "Image-Dired" (make-sparse-keymap "Image-Dired"))) | ||
| 1338 | |||
| 1339 | (define-key image-dired-thumbnail-mode-map | ||
| 1340 | [menu-bar image-dired image-dired-kill-buffer-and-window] | ||
| 1341 | '("Quit" . image-dired-kill-buffer-and-window)) | ||
| 1342 | |||
| 1343 | (define-key image-dired-thumbnail-mode-map | ||
| 1344 | [menu-bar image-dired image-dired-delete-char] | ||
| 1345 | '("Delete thumbnail from buffer" . image-dired-delete-char)) | ||
| 1346 | |||
| 1347 | (define-key image-dired-thumbnail-mode-map | ||
| 1348 | [menu-bar image-dired image-dired-tag-thumbnail-remove] | ||
| 1349 | '("Remove tag from thumbnail" . image-dired-tag-thumbnail-remove)) | ||
| 1350 | |||
| 1351 | (define-key image-dired-thumbnail-mode-map | ||
| 1352 | [menu-bar image-dired image-dired-tag-thumbnail] | ||
| 1353 | '("Tag thumbnail" . image-dired-tag-thumbnail)) | ||
| 1354 | |||
| 1355 | (define-key image-dired-thumbnail-mode-map | ||
| 1356 | [menu-bar image-dired image-dired-comment-thumbnail] | ||
| 1357 | '("Comment thumbnail" . image-dired-comment-thumbnail)) | ||
| 1358 | |||
| 1359 | (define-key image-dired-thumbnail-mode-map | ||
| 1360 | [menu-bar image-dired image-dired-refresh-thumb] | ||
| 1361 | '("Refresh thumb" . image-dired-refresh-thumb)) | ||
| 1362 | (define-key image-dired-thumbnail-mode-map | ||
| 1363 | [menu-bar image-dired image-dired-line-up-dynamic] | ||
| 1364 | '("Dynamic line up" . image-dired-line-up-dynamic)) | ||
| 1365 | (define-key image-dired-thumbnail-mode-map | ||
| 1366 | [menu-bar image-dired image-dired-line-up] | ||
| 1367 | '("Line up thumbnails" . image-dired-line-up)) | ||
| 1368 | |||
| 1369 | (define-key image-dired-thumbnail-mode-map | ||
| 1370 | [menu-bar image-dired image-dired-rotate-thumbnail-left] | ||
| 1371 | '("Rotate thumbnail left" . image-dired-rotate-thumbnail-left)) | ||
| 1372 | (define-key image-dired-thumbnail-mode-map | ||
| 1373 | [menu-bar image-dired image-dired-rotate-thumbnail-right] | ||
| 1374 | '("Rotate thumbnail right" . image-dired-rotate-thumbnail-right)) | ||
| 1375 | |||
| 1376 | (define-key image-dired-thumbnail-mode-map | ||
| 1377 | [menu-bar image-dired image-dired-rotate-original-left] | ||
| 1378 | '("Rotate original left" . image-dired-rotate-original-left)) | ||
| 1379 | (define-key image-dired-thumbnail-mode-map | ||
| 1380 | [menu-bar image-dired image-dired-rotate-original-right] | ||
| 1381 | '("Rotate original right" . image-dired-rotate-original-right)) | ||
| 1382 | |||
| 1383 | (define-key image-dired-thumbnail-mode-map | ||
| 1384 | [menu-bar image-dired image-dired-toggle-movement-tracking] | ||
| 1385 | '("Toggle movement tracking on/off" . image-dired-toggle-movement-tracking)) | ||
| 1386 | |||
| 1387 | (define-key image-dired-thumbnail-mode-map | ||
| 1388 | [menu-bar image-dired image-dired-jump-original-dired-buffer] | ||
| 1389 | '("Jump to dired buffer" . image-dired-jump-original-dired-buffer)) | ||
| 1390 | (define-key image-dired-thumbnail-mode-map | ||
| 1391 | [menu-bar image-dired image-dired-track-original-file] | ||
| 1392 | '("Track original" . image-dired-track-original-file)) | ||
| 1393 | |||
| 1394 | (define-key image-dired-thumbnail-mode-map | ||
| 1395 | [menu-bar image-dired image-dired-flag-thumb-original-file] | ||
| 1396 | '("Flag original for deletion" . image-dired-flag-thumb-original-file)) | ||
| 1397 | (define-key image-dired-thumbnail-mode-map | ||
| 1398 | [menu-bar image-dired image-dired-unmark-thumb-original-file] | ||
| 1399 | '("Unmark original" . image-dired-unmark-thumb-original-file)) | ||
| 1400 | (define-key image-dired-thumbnail-mode-map | ||
| 1401 | [menu-bar image-dired image-dired-mark-thumb-original-file] | ||
| 1402 | '("Mark original" . image-dired-mark-thumb-original-file)) | ||
| 1403 | |||
| 1404 | (define-key image-dired-thumbnail-mode-map | ||
| 1405 | [menu-bar image-dired image-dired-thumbnail-display-external] | ||
| 1406 | '("Display in external viewer" . image-dired-thumbnail-display-external)) | ||
| 1407 | (define-key image-dired-thumbnail-mode-map | ||
| 1408 | [menu-bar image-dired image-dired-display-thumbnail-original-image] | ||
| 1409 | '("Display image" . image-dired-display-thumbnail-original-image))) | ||
| 1410 | |||
| 1411 | (defvar image-dired-display-image-mode-map (make-sparse-keymap) | ||
| 1412 | "Keymap for `image-dired-display-image-mode'.") | ||
| 1413 | |||
| 1414 | (defun image-dired-define-display-image-mode-keymap () | ||
| 1415 | "Define keymap for `image-dired-display-image-mode'." | ||
| 1416 | |||
| 1417 | ;; Keys | ||
| 1418 | (define-key image-dired-display-image-mode-map "q" 'image-dired-kill-buffer-and-window) | ||
| 1419 | |||
| 1420 | (define-key image-dired-display-image-mode-map "f" | ||
| 1421 | 'image-dired-display-current-image-full) | ||
| 1422 | |||
| 1423 | (define-key image-dired-display-image-mode-map "s" | ||
| 1424 | 'image-dired-display-current-image-sized) | ||
| 1425 | |||
| 1426 | ;; Menu | ||
| 1427 | (define-key image-dired-display-image-mode-map [menu-bar image-dired] | ||
| 1428 | (cons "Image-Dired" (make-sparse-keymap "Image-Dired"))) | ||
| 1429 | |||
| 1430 | (define-key image-dired-display-image-mode-map | ||
| 1431 | [menu-bar image-dired image-dired-kill-buffer-and-window] | ||
| 1432 | '("Quit" . image-dired-kill-buffer-and-window)) | ||
| 1433 | |||
| 1434 | (define-key image-dired-display-image-mode-map | ||
| 1435 | [menu-bar image-dired image-dired-display-current-image-sized] | ||
| 1436 | '("Display original, sized to fit" . image-dired-display-current-image-sized)) | ||
| 1437 | |||
| 1438 | (define-key image-dired-display-image-mode-map | ||
| 1439 | [menu-bar image-dired image-dired-display-current-image-full] | ||
| 1440 | '("Display original, full size" . image-dired-display-current-image-full)) | ||
| 1441 | |||
| 1442 | ) | ||
| 1443 | |||
| 1444 | (defun image-dired-display-current-image-full () | ||
| 1445 | "Display current image in full size." | ||
| 1446 | (interactive) | ||
| 1447 | (let ((file (image-dired-original-file-name))) | ||
| 1448 | (if file | ||
| 1449 | (progn | ||
| 1450 | (image-dired-display-image file t) | ||
| 1451 | (message "Full size image displayed")) | ||
| 1452 | (error "No original file name at point")))) | ||
| 1453 | |||
| 1454 | (defun image-dired-display-current-image-sized () | ||
| 1455 | "Display current image in sized to fit window dimensions." | ||
| 1456 | (interactive) | ||
| 1457 | (let ((file (image-dired-original-file-name))) | ||
| 1458 | (if file | ||
| 1459 | (progn | ||
| 1460 | (image-dired-display-image file) | ||
| 1461 | (message "Full size image displayed")) | ||
| 1462 | (error "No original file name at point")))) | ||
| 1463 | |||
| 1464 | (define-derived-mode image-dired-thumbnail-mode | ||
| 1465 | fundamental-mode "image-dired-thumbnail" | ||
| 1466 | "Browse and manipulate thumbnail images using dired. | ||
| 1467 | Use `image-dired-dired' and `image-dired-setup-dired-keybindings' to get a | ||
| 1468 | nice setup to start with." | ||
| 1469 | (image-dired-define-thumbnail-mode-keymap) | ||
| 1470 | (message "image-dired-thumbnail-mode enabled")) | ||
| 1471 | |||
| 1472 | (define-derived-mode image-dired-display-image-mode | ||
| 1473 | fundamental-mode "image-dired-image-display" | ||
| 1474 | "Mode for displaying and manipulating original image. | ||
| 1475 | Resized or in full-size." | ||
| 1476 | (image-dired-define-display-image-mode-keymap) | ||
| 1477 | (message "image-dired-display-image-mode enabled")) | ||
| 1478 | |||
| 1479 | ;;;###autoload | ||
| 1480 | (defun image-dired-setup-dired-keybindings () | ||
| 1481 | "Setup easy-to-use keybindings for the commands to be used in dired mode. | ||
| 1482 | Note that n, p and <down> and <up> will be hijacked and bound to | ||
| 1483 | `image-dired-dired-x-line'." | ||
| 1484 | (interactive) | ||
| 1485 | |||
| 1486 | ;; Hijack previous and next line movement. Let C-p and C-b be | ||
| 1487 | ;; though... | ||
| 1488 | |||
| 1489 | (define-key dired-mode-map "p" 'image-dired-dired-previous-line) | ||
| 1490 | (define-key dired-mode-map "n" 'image-dired-dired-next-line) | ||
| 1491 | (define-key dired-mode-map [up] 'image-dired-dired-previous-line) | ||
| 1492 | (define-key dired-mode-map [down] 'image-dired-dired-next-line) | ||
| 1493 | |||
| 1494 | (define-key dired-mode-map (kbd "C-S-n") 'image-dired-next-line-and-display) | ||
| 1495 | (define-key dired-mode-map (kbd "C-S-p") 'image-dired-previous-line-and-display) | ||
| 1496 | (define-key dired-mode-map (kbd "C-S-m") 'image-dired-mark-and-display-next) | ||
| 1497 | |||
| 1498 | (define-key dired-mode-map "\C-td" 'image-dired-display-thumbs) | ||
| 1499 | (define-key dired-mode-map "\C-tt" 'image-dired-tag-files) | ||
| 1500 | (define-key dired-mode-map "\C-tr" 'image-dired-delete-tag) | ||
| 1501 | (define-key dired-mode-map [tab] 'image-dired-jump-thumbnail-buffer) | ||
| 1502 | (define-key dired-mode-map "\C-ti" 'image-dired-dired-display-image) | ||
| 1503 | (define-key dired-mode-map "\C-tx" 'image-dired-dired-display-external) | ||
| 1504 | (define-key dired-mode-map "\C-ta" 'image-dired-display-thumbs-append) | ||
| 1505 | (define-key dired-mode-map "\C-t." 'image-dired-display-thumb) | ||
| 1506 | (define-key dired-mode-map "\C-tc" 'image-dired-dired-comment-files) | ||
| 1507 | (define-key dired-mode-map "\C-tf" 'image-dired-mark-tagged-files) | ||
| 1508 | |||
| 1509 | ;; Menu for dired | ||
| 1510 | (define-key dired-mode-map [menu-bar image-dired] | ||
| 1511 | (cons "Image-Dired" (make-sparse-keymap "Image-Dired"))) | ||
| 1512 | |||
| 1513 | (define-key dired-mode-map [menu-bar image-dired image-dired-copy-with-exif-file-name] | ||
| 1514 | '("Copy with EXIF file name" . image-dired-copy-with-exif-file-name)) | ||
| 1515 | |||
| 1516 | (define-key dired-mode-map [menu-bar image-dired image-dired-dired-comment-files] | ||
| 1517 | '("Comment files" . image-dired-dired-comment-files)) | ||
| 1518 | |||
| 1519 | (define-key dired-mode-map [menu-bar image-dired image-dired-mark-tagged-files] | ||
| 1520 | '("Mark tagged files" . image-dired-mark-tagged-files)) | ||
| 1521 | |||
| 1522 | (define-key dired-mode-map [menu-bar image-dired image-dired-delete-tag] | ||
| 1523 | '("Remove tag from files" . image-dired-delete-tag)) | ||
| 1524 | |||
| 1525 | (define-key dired-mode-map [menu-bar image-dired image-dired-tag-files] | ||
| 1526 | '("Tag files" . image-dired-tag-files)) | ||
| 1527 | |||
| 1528 | (define-key dired-mode-map [menu-bar image-dired image-dired-jump-thumbnail-buffer] | ||
| 1529 | '("Jump to thumbnail buffer" . image-dired-jump-thumbnail-buffer)) | ||
| 1530 | |||
| 1531 | (define-key dired-mode-map [menu-bar image-dired image-dired-toggle-movement-tracking] | ||
| 1532 | '("Toggle movement tracking" . image-dired-toggle-movement-tracking)) | ||
| 1533 | |||
| 1534 | (define-key dired-mode-map | ||
| 1535 | [menu-bar image-dired image-dired-toggle-append-browsing] | ||
| 1536 | '("Toggle append browsing" . image-dired-toggle-append-browsing)) | ||
| 1537 | |||
| 1538 | (define-key dired-mode-map | ||
| 1539 | [menu-bar image-dired image-dired-toggle-disp-props] | ||
| 1540 | '("Toggle display properties" . image-dired-toggle-dired-display-properties)) | ||
| 1541 | |||
| 1542 | (define-key dired-mode-map | ||
| 1543 | [menu-bar image-dired image-dired-dired-display-external] | ||
| 1544 | '("Display in external viewer" . image-dired-dired-display-external)) | ||
| 1545 | (define-key dired-mode-map | ||
| 1546 | [menu-bar image-dired image-dired-dired-display-image] | ||
| 1547 | '("Display image" . image-dired-dired-display-image)) | ||
| 1548 | (define-key dired-mode-map | ||
| 1549 | [menu-bar image-dired image-dired-display-thumb] | ||
| 1550 | '("Display this thumbnail" . image-dired-display-thumb)) | ||
| 1551 | (define-key dired-mode-map | ||
| 1552 | [menu-bar image-dired image-dired-display-thumbs-append] | ||
| 1553 | '("Display thumbnails append" . image-dired-display-thumbs-append)) | ||
| 1554 | (define-key dired-mode-map | ||
| 1555 | [menu-bar image-dired image-dired-display-thumbs] | ||
| 1556 | '("Display thumbnails" . image-dired-display-thumbs)) | ||
| 1557 | |||
| 1558 | (define-key dired-mode-map | ||
| 1559 | [menu-bar image-dired image-dired-create-thumbs] | ||
| 1560 | '("Create thumbnails for marked files" . image-dired-create-thumbs)) | ||
| 1561 | |||
| 1562 | (define-key dired-mode-map | ||
| 1563 | [menu-bar image-dired image-dired-mark-and-display-next] | ||
| 1564 | '("Mark and display next" . image-dired-mark-and-display-next)) | ||
| 1565 | (define-key dired-mode-map | ||
| 1566 | [menu-bar image-dired image-dired-previous-line-and-display] | ||
| 1567 | '("Display thumb for previous file" . image-dired-previous-line-and-display)) | ||
| 1568 | (define-key dired-mode-map | ||
| 1569 | [menu-bar image-dired image-dired-next-line-and-display] | ||
| 1570 | '("Display thumb for next file" . image-dired-next-line-and-display))) | ||
| 1571 | |||
| 1572 | (defun image-dired-create-thumbs (&optional arg) | ||
| 1573 | "Create thumbnail images for all marked files in dired. | ||
| 1574 | With prefix argument ARG, create thumbnails even if they already exist | ||
| 1575 | \(i.e. use this to refresh your thumbnails)." | ||
| 1576 | (interactive "P") | ||
| 1577 | (let (curr-file thumb-name files count) | ||
| 1578 | (setq files (dired-get-marked-files)) | ||
| 1579 | (mapcar | ||
| 1580 | (lambda (curr-file) | ||
| 1581 | (setq thumb-name (image-dired-thumb-name curr-file)) | ||
| 1582 | ;; If the user overrides the exist check, we must clear the | ||
| 1583 | ;; image cache so that if the user wants to display the | ||
| 1584 | ;; thumnail, it is not fetched from cache. | ||
| 1585 | (if arg | ||
| 1586 | (clear-image-cache)) | ||
| 1587 | (if (or (not (file-exists-p thumb-name)) | ||
| 1588 | arg) | ||
| 1589 | (if (not (= 0 (image-dired-create-thumb curr-file | ||
| 1590 | (image-dired-thumb-name curr-file)))) | ||
| 1591 | (error "Thumb could not be created")))) | ||
| 1592 | files))) | ||
| 1593 | |||
| 1594 | (defvar image-dired-slideshow-timer nil | ||
| 1595 | "Slideshow timer.") | ||
| 1596 | |||
| 1597 | (defvar image-dired-slideshow-count 0 | ||
| 1598 | "Keeping track on number of images in slideshow.") | ||
| 1599 | |||
| 1600 | (defvar image-dired-slideshow-times 0 | ||
| 1601 | "Number of pictures to display in slideshow.") | ||
| 1602 | |||
| 1603 | (defun image-dired-slideshow-step () | ||
| 1604 | "Step to next file, if `image-dired-slideshow-times' has not been reached." | ||
| 1605 | (if (< image-dired-slideshow-count image-dired-slideshow-times) | ||
| 1606 | (progn | ||
| 1607 | (message "%s" (1+ image-dired-slideshow-count)) | ||
| 1608 | (setq image-dired-slideshow-count (1+ image-dired-slideshow-count)) | ||
| 1609 | (image-dired-next-line-and-display)) | ||
| 1610 | (image-dired-slideshow-stop))) | ||
| 1611 | |||
| 1612 | (defun image-dired-slideshow-start () | ||
| 1613 | "Start slideshow. | ||
| 1614 | Ask user for number of images to show and the delay in between." | ||
| 1615 | (interactive) | ||
| 1616 | (setq image-dired-slideshow-count 0) | ||
| 1617 | (setq image-dired-slideshow-times (string-to-number (read-string "How many: "))) | ||
| 1618 | (let ((repeat (string-to-number | ||
| 1619 | (read-string | ||
| 1620 | "Delay, in seconds. Decimals are accepted : " "1")))) | ||
| 1621 | (setq image-dired-slideshow-timer | ||
| 1622 | (run-with-timer | ||
| 1623 | 0 repeat | ||
| 1624 | 'image-dired-slideshow-step)))) | ||
| 1625 | |||
| 1626 | (defun image-dired-slideshow-stop () | ||
| 1627 | "Cancel slideshow." | ||
| 1628 | (interactive) | ||
| 1629 | (cancel-timer image-dired-slideshow-timer)) | ||
| 1630 | |||
| 1631 | (defun image-dired-delete-char () | ||
| 1632 | "Remove current thumbnail from thumbnail buffer and line up." | ||
| 1633 | (interactive) | ||
| 1634 | (let ((inhibit-read-only t)) | ||
| 1635 | (delete-char 1) | ||
| 1636 | (if (looking-at " ") | ||
| 1637 | (delete-char 1)))) | ||
| 1638 | |||
| 1639 | ;;;###autoload | ||
| 1640 | (defun image-dired-display-thumbs-append () | ||
| 1641 | "Append thumbnails to `image-dired-thumbnail-buffer'." | ||
| 1642 | (interactive) | ||
| 1643 | (image-dired-display-thumbs nil t t)) | ||
| 1644 | |||
| 1645 | ;;;###autoload | ||
| 1646 | (defun image-dired-display-thumb () | ||
| 1647 | "Shorthand for `image-dired-display-thumbs' with prefix argument." | ||
| 1648 | (interactive) | ||
| 1649 | (image-dired-display-thumbs t nil t)) | ||
| 1650 | |||
| 1651 | (defun image-dired-line-up () | ||
| 1652 | "Line up thumbnails according to `image-dired-thumbs-per-row'. | ||
| 1653 | See also `image-dired-line-up-dynamic'." | ||
| 1654 | (interactive) | ||
| 1655 | (let ((inhibit-read-only t)) | ||
| 1656 | (goto-char (point-min)) | ||
| 1657 | (while (and (not (image-dired-image-at-point-p)) | ||
| 1658 | (not (eobp))) | ||
| 1659 | (delete-char 1)) | ||
| 1660 | (while (not (eobp)) | ||
| 1661 | (forward-char) | ||
| 1662 | (while (and (not (image-dired-image-at-point-p)) | ||
| 1663 | (not (eobp))) | ||
| 1664 | (delete-char 1))) | ||
| 1665 | (goto-char (point-min)) | ||
| 1666 | (let ((count 0)) | ||
| 1667 | (while (not (eobp)) | ||
| 1668 | (forward-char) | ||
| 1669 | (if (= image-dired-thumbs-per-row 1) | ||
| 1670 | (insert "\n") | ||
| 1671 | (insert " ") | ||
| 1672 | (setq count (1+ count)) | ||
| 1673 | (when (and (= count (- image-dired-thumbs-per-row 1)) | ||
| 1674 | (not (eobp))) | ||
| 1675 | (forward-char) | ||
| 1676 | (insert "\n") | ||
| 1677 | (setq count 0))))) | ||
| 1678 | (goto-char (point-min)))) | ||
| 1679 | |||
| 1680 | (defun image-dired-line-up-dynamic () | ||
| 1681 | "Line up thumbnails images dynamically. | ||
| 1682 | Calculate how many thumbnails fit." | ||
| 1683 | (interactive) | ||
| 1684 | (let* ((char-width (frame-char-width)) | ||
| 1685 | (width (image-dired-window-width-pixels (image-dired-thumbnail-window))) | ||
| 1686 | (image-dired-thumbs-per-row | ||
| 1687 | (/ width | ||
| 1688 | (+ (* 2 image-dired-thumb-relief) | ||
| 1689 | (* 2 image-dired-thumb-margin) | ||
| 1690 | image-dired-thumb-width char-width)))) | ||
| 1691 | (image-dired-line-up))) | ||
| 1692 | |||
| 1693 | (defun image-dired-line-up-interactive () | ||
| 1694 | "Line up thumbnails interactively. | ||
| 1695 | Ask user how many thumbnails should be displayed per row." | ||
| 1696 | (interactive) | ||
| 1697 | (let ((image-dired-thumbs-per-row | ||
| 1698 | (string-to-number (read-string "How many thumbs per row: ")))) | ||
| 1699 | (if (not (> image-dired-thumbs-per-row 0)) | ||
| 1700 | (message "Number must be greater than 0") | ||
| 1701 | (image-dired-line-up)))) | ||
| 1702 | |||
| 1703 | (defun image-dired-thumbnail-display-external () | ||
| 1704 | "Display original image for thumbnail at point using external viewer." | ||
| 1705 | (interactive) | ||
| 1706 | (let ((file (image-dired-original-file-name))) | ||
| 1707 | (if (not (image-dired-image-at-point-p)) | ||
| 1708 | (message "No thumbnail at point") | ||
| 1709 | (if (not file) | ||
| 1710 | (message "No original file name found") | ||
| 1711 | (call-process shell-file-name nil nil nil shell-command-switch | ||
| 1712 | (format "%s \"%s\"" image-dired-external-viewer file)))))) | ||
| 1713 | |||
| 1714 | ;;;###autoload | ||
| 1715 | (defun image-dired-dired-display-external () | ||
| 1716 | "Display file at point using an external viewer." | ||
| 1717 | (interactive) | ||
| 1718 | (let ((file (dired-get-filename))) | ||
| 1719 | (call-process shell-file-name nil nil nil shell-command-switch | ||
| 1720 | (format "%s \"%s\"" image-dired-external-viewer file)))) | ||
| 1721 | |||
| 1722 | (defun image-dired-window-width-pixels (window) | ||
| 1723 | "Calculate WINDOW width in pixels." | ||
| 1724 | (* (window-width window) (frame-char-width))) | ||
| 1725 | |||
| 1726 | (defun image-dired-window-height-pixels (window) | ||
| 1727 | "Calculate WINDOW height in pixels." | ||
| 1728 | ;; Note: The mode-line consumes one line | ||
| 1729 | (* (- (window-height window) 1) (frame-char-height))) | ||
| 1730 | |||
| 1731 | (defun image-dired-display-window () | ||
| 1732 | "Return window where `image-dired-display-image-buffer' is visible." | ||
| 1733 | (get-window-with-predicate | ||
| 1734 | (lambda (window) | ||
| 1735 | (equal (buffer-name (window-buffer window)) image-dired-display-image-buffer)) | ||
| 1736 | nil t)) | ||
| 1737 | |||
| 1738 | (defun image-dired-thumbnail-window () | ||
| 1739 | "Return window where `image-dired-thumbnail-buffer' is visible." | ||
| 1740 | (get-window-with-predicate | ||
| 1741 | (lambda (window) | ||
| 1742 | (equal (buffer-name (window-buffer window)) image-dired-thumbnail-buffer)) | ||
| 1743 | nil t)) | ||
| 1744 | |||
| 1745 | (defun image-dired-associated-dired-buffer-window () | ||
| 1746 | "Return window where associated dired buffer is visible." | ||
| 1747 | (let (buf) | ||
| 1748 | (if (image-dired-image-at-point-p) | ||
| 1749 | (progn | ||
| 1750 | (setq buf (image-dired-associated-dired-buffer)) | ||
| 1751 | (get-window-with-predicate | ||
| 1752 | (lambda (window) | ||
| 1753 | (equal (window-buffer window) buf)))) | ||
| 1754 | (error "No thumbnail image at point")))) | ||
| 1755 | |||
| 1756 | (defun image-dired-display-window-width () | ||
| 1757 | "Return width, in pixels, of image-dired's image display window." | ||
| 1758 | (- (image-dired-window-width-pixels (image-dired-display-window)) | ||
| 1759 | image-dired-display-window-width-correction)) | ||
| 1760 | |||
| 1761 | (defun image-dired-display-window-height () | ||
| 1762 | "Return height, in pixels, of image-dired's image display window." | ||
| 1763 | (- (image-dired-window-height-pixels (image-dired-display-window)) | ||
| 1764 | image-dired-display-window-height-correction)) | ||
| 1765 | |||
| 1766 | (defun image-dired-display-image (file &optional original-size) | ||
| 1767 | "Display image FILE in image buffer. | ||
| 1768 | Use this when you want to display the image, semi sized, in a new | ||
| 1769 | window. The image is sized to fit the display window (using a | ||
| 1770 | temporary file, don't worry). Because of this, it will not be as | ||
| 1771 | quick as opening it directly, but on most modern systems it | ||
| 1772 | should feel snappy enough. | ||
| 1773 | |||
| 1774 | If optional argument ORIGINAL-SIZE is non-nil, display image in its | ||
| 1775 | original size." | ||
| 1776 | (let ((new-file (expand-file-name image-dired-temp-image-file)) | ||
| 1777 | width height command ret) | ||
| 1778 | (setq file (expand-file-name file)) | ||
| 1779 | (if (not original-size) | ||
| 1780 | (progn | ||
| 1781 | (setq width (image-dired-display-window-width)) | ||
| 1782 | (setq height (image-dired-display-window-height)) | ||
| 1783 | (setq command | ||
| 1784 | (format-spec | ||
| 1785 | image-dired-cmd-create-temp-image-options | ||
| 1786 | (list | ||
| 1787 | (cons ?p image-dired-cmd-create-temp-image-program) | ||
| 1788 | (cons ?w width) | ||
| 1789 | (cons ?h height) | ||
| 1790 | (cons ?f file) | ||
| 1791 | (cons ?t new-file)))) | ||
| 1792 | (setq ret (call-process shell-file-name nil nil nil | ||
| 1793 | shell-command-switch command)) | ||
| 1794 | (if (not (= 0 ret)) | ||
| 1795 | (error "Could not resize image"))) | ||
| 1796 | (copy-file file new-file t)) | ||
| 1797 | (with-current-buffer (image-dired-create-display-image-buffer) | ||
| 1798 | (let ((inhibit-read-only t)) | ||
| 1799 | (erase-buffer) | ||
| 1800 | (clear-image-cache) | ||
| 1801 | (image-dired-insert-image image-dired-temp-image-file 'jpeg 0 0) | ||
| 1802 | (goto-char (point-min)) | ||
| 1803 | (image-dired-update-property 'original-file-name file))))) | ||
| 1804 | |||
| 1805 | (defun image-dired-display-thumbnail-original-image (&optional arg) | ||
| 1806 | "Display current thumbnail's original image in display buffer. | ||
| 1807 | See documentation for `image-dired-display-image' for more information. | ||
| 1808 | With prefix argument ARG, display image in its original size." | ||
| 1809 | (interactive "P") | ||
| 1810 | (let ((file (image-dired-original-file-name))) | ||
| 1811 | (if (not (string-equal major-mode "image-dired-thumbnail-mode")) | ||
| 1812 | (message "Not in image-dired-thumbnail-mode") | ||
| 1813 | (if (not (image-dired-image-at-point-p)) | ||
| 1814 | (message "No thumbnail at point") | ||
| 1815 | (if (not file) | ||
| 1816 | (message "No original file name found") | ||
| 1817 | (image-dired-create-display-image-buffer) | ||
| 1818 | (display-buffer image-dired-display-image-buffer) | ||
| 1819 | (image-dired-display-image file arg)))))) | ||
| 1820 | |||
| 1821 | |||
| 1822 | ;;;###autoload | ||
| 1823 | (defun image-dired-dired-display-image (&optional arg) | ||
| 1824 | "Display current image file. | ||
| 1825 | See documentation for `image-dired-display-image' for more information. | ||
| 1826 | With prefix argument ARG, display image in its original size." | ||
| 1827 | (interactive "P") | ||
| 1828 | (image-dired-create-display-image-buffer) | ||
| 1829 | (display-buffer image-dired-display-image-buffer) | ||
| 1830 | (image-dired-display-image (dired-get-filename) arg)) | ||
| 1831 | |||
| 1832 | (defun image-dired-image-at-point-p () | ||
| 1833 | "Return true if there is a image-dired thumbnail at point." | ||
| 1834 | (get-text-property (point) 'image-dired-thumbnail)) | ||
| 1835 | |||
| 1836 | (defun image-dired-rotate-thumbnail (degrees) | ||
| 1837 | "Rotate thumbnail DEGREES degrees." | ||
| 1838 | (if (not (image-dired-image-at-point-p)) | ||
| 1839 | (message "No thumbnail at point") | ||
| 1840 | (let ((file (image-dired-thumb-name (image-dired-original-file-name))) | ||
| 1841 | command) | ||
| 1842 | (setq command (format-spec | ||
| 1843 | image-dired-cmd-rotate-thumbnail-options | ||
| 1844 | (list | ||
| 1845 | (cons ?p image-dired-cmd-rotate-thumbnail-program) | ||
| 1846 | (cons ?d degrees) | ||
| 1847 | (cons ?t (expand-file-name file))))) | ||
| 1848 | (call-process shell-file-name nil nil nil shell-command-switch command) | ||
| 1849 | ;; Clear the cache to refresh image. I wish I could just refresh | ||
| 1850 | ;; the current file but I do not know how to do that. Yet... | ||
| 1851 | (clear-image-cache)))) | ||
| 1852 | |||
| 1853 | (defun image-dired-rotate-thumbnail-left () | ||
| 1854 | "Rotate thumbnail left (counter clockwise) 90 degrees. | ||
| 1855 | The result of the rotation is displayed in the image display area | ||
| 1856 | and a confirmation is needed before the original image files is | ||
| 1857 | overwritten. This confirmation can be turned off using | ||
| 1858 | `image-dired-rotate-original-ask-before-overwrite'." | ||
| 1859 | (interactive) | ||
| 1860 | (image-dired-rotate-thumbnail "270")) | ||
| 1861 | |||
| 1862 | (defun image-dired-rotate-thumbnail-right () | ||
| 1863 | "Rotate thumbnail counter right (clockwise) 90 degrees. | ||
| 1864 | The result of the rotation is displayed in the image display area | ||
| 1865 | and a confirmation is needed before the original image files is | ||
| 1866 | overwritten. This confirmation can be turned off using | ||
| 1867 | `image-dired-rotate-original-ask-before-overwrite'." | ||
| 1868 | (interactive) | ||
| 1869 | (image-dired-rotate-thumbnail "90")) | ||
| 1870 | |||
| 1871 | (defun image-dired-refresh-thumb () | ||
| 1872 | "Force creation of new image for current thumbnail." | ||
| 1873 | (interactive) | ||
| 1874 | (let ((file (image-dired-original-file-name))) | ||
| 1875 | (clear-image-cache) | ||
| 1876 | (image-dired-create-thumb file (image-dired-thumb-name file)))) | ||
| 1877 | |||
| 1878 | (defun image-dired-rotate-original (degrees) | ||
| 1879 | "Rotate original image DEGREES degrees." | ||
| 1880 | (if (not (image-dired-image-at-point-p)) | ||
| 1881 | (message "No image at point") | ||
| 1882 | (let ((file (image-dired-original-file-name)) | ||
| 1883 | command temp-file) | ||
| 1884 | (if (not (string-match "\.[jJ][pP[eE]?[gG]$" file)) | ||
| 1885 | (error "Only JPEG images can be rotated!")) | ||
| 1886 | (setq command (format-spec | ||
| 1887 | image-dired-cmd-rotate-original-options | ||
| 1888 | (list | ||
| 1889 | (cons ?p image-dired-cmd-rotate-original-program) | ||
| 1890 | (cons ?d degrees) | ||
| 1891 | (cons ?o (expand-file-name file)) | ||
| 1892 | (cons ?t image-dired-temp-rotate-image-file)))) | ||
| 1893 | (if (not (= 0 (call-process shell-file-name nil nil nil | ||
| 1894 | shell-command-switch command))) | ||
| 1895 | (error "Could not rotate image") | ||
| 1896 | (image-dired-display-image image-dired-temp-rotate-image-file) | ||
| 1897 | (if (or (and image-dired-rotate-original-ask-before-overwrite | ||
| 1898 | (y-or-n-p | ||
| 1899 | "Rotate to temp file OK. Overwrite original image? ")) | ||
| 1900 | (not image-dired-rotate-original-ask-before-overwrite)) | ||
| 1901 | (progn | ||
| 1902 | (copy-file image-dired-temp-rotate-image-file file t) | ||
| 1903 | (image-dired-refresh-thumb)) | ||
| 1904 | (image-dired-display-image file)))))) | ||
| 1905 | |||
| 1906 | (defun image-dired-rotate-original-left () | ||
| 1907 | "Rotate original image left (counter clockwise) 90 degrees." | ||
| 1908 | (interactive) | ||
| 1909 | (image-dired-rotate-original "270")) | ||
| 1910 | |||
| 1911 | (defun image-dired-rotate-original-right () | ||
| 1912 | "Rotate original image right (clockwise) 90 degrees." | ||
| 1913 | (interactive) | ||
| 1914 | (image-dired-rotate-original "90")) | ||
| 1915 | |||
| 1916 | (defun image-dired-get-exif-file-name (file) | ||
| 1917 | "Use the image's EXIF information to return a unique file name. | ||
| 1918 | The file name should be unique as long as you do not take more than | ||
| 1919 | one picture per second. The original file name is suffixed at the end | ||
| 1920 | for traceability. The format of the returned file name is | ||
| 1921 | YYYY_MM_DD_HH_MM_DD_ORIG_FILE_NAME.jpg. Used from | ||
| 1922 | `image-dired-copy-with-exif-file-name'." | ||
| 1923 | (let (data no-exif-data-found) | ||
| 1924 | (if (not (string-match "\.[Jj][Pp][Ee]?[Gg]$" (expand-file-name file))) | ||
| 1925 | (progn | ||
| 1926 | (setq no-exif-data-found t) | ||
| 1927 | (setq data | ||
| 1928 | (format-time-string | ||
| 1929 | "%Y:%m:%d %H:%M:%S" | ||
| 1930 | (nth 5 (file-attributes (expand-file-name file)))))) | ||
| 1931 | (setq data (image-dired-get-exif-data (expand-file-name file) | ||
| 1932 | "DateTimeOriginal"))) | ||
| 1933 | (while (string-match "[ :]" data) | ||
| 1934 | (setq data (replace-match "_" nil nil data))) | ||
| 1935 | (format "%s%s%s" data | ||
| 1936 | (if no-exif-data-found | ||
| 1937 | "_noexif_" | ||
| 1938 | "_") | ||
| 1939 | (file-name-nondirectory file)))) | ||
| 1940 | |||
| 1941 | (defun image-dired-thumbnail-set-image-description () | ||
| 1942 | "Set the ImageDescription EXIF tag for the original image. | ||
| 1943 | If the image already has a value for this tag, it is used as the | ||
| 1944 | default value at the prompt." | ||
| 1945 | (interactive) | ||
| 1946 | (if (not (image-dired-image-at-point-p)) | ||
| 1947 | (message "No thumbnail at point") | ||
| 1948 | (let* ((file (image-dired-original-file-name)) | ||
| 1949 | (old-value (image-dired-get-exif-data file "ImageDescription"))) | ||
| 1950 | (if (eq 0 | ||
| 1951 | (image-dired-set-exif-data file "ImageDescription" | ||
| 1952 | (read-string "Value of ImageDescription: " | ||
| 1953 | old-value))) | ||
| 1954 | (message "Successfully wrote ImageDescription tag.") | ||
| 1955 | (error "Could not write ImageDescription tag"))))) | ||
| 1956 | |||
| 1957 | (defun image-dired-set-exif-data (file tag-name tag-value) | ||
| 1958 | "In FILE, set EXIF tag TAG-NAME to value TAG-VALUE." | ||
| 1959 | (let (command) | ||
| 1960 | (setq command (format-spec | ||
| 1961 | image-dired-cmd-write-exif-data-options | ||
| 1962 | (list | ||
| 1963 | (cons ?p image-dired-cmd-write-exif-data-program) | ||
| 1964 | (cons ?f (expand-file-name file)) | ||
| 1965 | (cons ?t tag-name) | ||
| 1966 | (cons ?v tag-value)))) | ||
| 1967 | (call-process shell-file-name nil nil nil shell-command-switch command))) | ||
| 1968 | |||
| 1969 | (defun image-dired-get-exif-data (file tag-name) | ||
| 1970 | "From FILE, return EXIF tag TAG-NAME." | ||
| 1971 | (let ((buf (get-buffer-create "*image-dired-get-exif-data*")) | ||
| 1972 | command tag-value) | ||
| 1973 | (setq command (format-spec | ||
| 1974 | image-dired-cmd-read-exif-data-options | ||
| 1975 | (list | ||
| 1976 | (cons ?p image-dired-cmd-read-exif-data-program) | ||
| 1977 | (cons ?f file) | ||
| 1978 | (cons ?t tag-name)))) | ||
| 1979 | (with-current-buffer buf | ||
| 1980 | (delete-region (point-min) (point-max)) | ||
| 1981 | (if (not (eq (call-process shell-file-name nil t nil | ||
| 1982 | shell-command-switch command) 0)) | ||
| 1983 | (error "Could not get EXIF tag") | ||
| 1984 | (goto-char (point-min)) | ||
| 1985 | ;; Clean buffer from newlines and carriage returns before | ||
| 1986 | ;; getting final info | ||
| 1987 | (while (search-forward-regexp "[\n\r]" nil t) | ||
| 1988 | (replace-match "" nil t)) | ||
| 1989 | (setq tag-value (buffer-substring (point-min) (point-max))))) | ||
| 1990 | tag-value)) | ||
| 1991 | |||
| 1992 | (defun image-dired-copy-with-exif-file-name () | ||
| 1993 | "Copy file with unique name to main image directory. | ||
| 1994 | Copy current or all marked files in dired to a new file in your | ||
| 1995 | main image directory, using a file name generated by | ||
| 1996 | `image-dired-get-exif-file-name'. A typical usage for this if when | ||
| 1997 | copying images from a digital camera into the image directory. | ||
| 1998 | |||
| 1999 | Typically, you would open up the folder with the incoming | ||
| 2000 | digital images, mark the files to be copied, and execute this | ||
| 2001 | function. The result is a couple of new files in | ||
| 2002 | `image-dired-main-image-directory' called | ||
| 2003 | 2005_05_08_12_52_00_dscn0319.jpg, | ||
| 2004 | 2005_05_08_14_27_45_dscn0320.jpg etc." | ||
| 2005 | (interactive) | ||
| 2006 | (let (new-name | ||
| 2007 | (files (dired-get-marked-files))) | ||
| 2008 | (mapcar | ||
| 2009 | (lambda (curr-file) | ||
| 2010 | (setq new-name | ||
| 2011 | (format "%s/%s" | ||
| 2012 | (file-name-as-directory | ||
| 2013 | (expand-file-name image-dired-main-image-directory)) | ||
| 2014 | (image-dired-get-exif-file-name curr-file))) | ||
| 2015 | (message "Copying %s to %s" curr-file new-name) | ||
| 2016 | (copy-file curr-file new-name)) | ||
| 2017 | files))) | ||
| 2018 | |||
| 2019 | (defun image-dired-display-next-thumbnail-original () | ||
| 2020 | "In thubnail buffer, move to next thumbnail and display the image." | ||
| 2021 | (interactive) | ||
| 2022 | (image-dired-forward-image) | ||
| 2023 | (image-dired-display-thumbnail-original-image)) | ||
| 2024 | |||
| 2025 | (defun image-dired-display-previous-thumbnail-original () | ||
| 2026 | "Move to previous thumbnail and display image." | ||
| 2027 | (interactive) | ||
| 2028 | (image-dired-backward-image) | ||
| 2029 | (image-dired-display-thumbnail-original-image)) | ||
| 2030 | |||
| 2031 | (defun image-dired-write-comments (file-comments) | ||
| 2032 | "Write file comments to database. | ||
| 2033 | Write file comments to one or more files. FILE-COMMENTS is an alist on | ||
| 2034 | the following form: | ||
| 2035 | ((FILE . COMMENT) ... )" | ||
| 2036 | (let (end comment-beg-pos comment-end-pos file comment) | ||
| 2037 | (with-temp-file image-dired-db-file | ||
| 2038 | (insert-file-contents image-dired-db-file) | ||
| 2039 | (dolist (elt file-comments) | ||
| 2040 | (setq file (car elt) | ||
| 2041 | comment (cdr elt)) | ||
| 2042 | (goto-char (point-min)) | ||
| 2043 | (if (search-forward-regexp (format "^%s.*$" file) nil t) | ||
| 2044 | (progn | ||
| 2045 | (setq end (point)) | ||
| 2046 | (beginning-of-line) | ||
| 2047 | ;; Delete old comment, if any | ||
| 2048 | (when (search-forward ";comment:" end t) | ||
| 2049 | (setq comment-beg-pos (match-beginning 0)) | ||
| 2050 | ;; Any tags after the comment? | ||
| 2051 | (if (search-forward ";" end t) | ||
| 2052 | (setq comment-end-pos (- (point) 1)) | ||
| 2053 | (setq comment-end-pos end)) | ||
| 2054 | ;; Delete comment tag and comment | ||
| 2055 | (delete-region comment-beg-pos comment-end-pos)) | ||
| 2056 | ;; Insert new comment | ||
| 2057 | (beginning-of-line) | ||
| 2058 | (unless (search-forward ";" end t) | ||
| 2059 | (end-of-line) | ||
| 2060 | (insert ";")) | ||
| 2061 | (insert (format "comment:%s;" comment))) | ||
| 2062 | ;; File does not exist in database - add it. | ||
| 2063 | (goto-char (point-max)) | ||
| 2064 | (insert (format "\n%s;comment:%s" file comment))))))) | ||
| 2065 | |||
| 2066 | (defun image-dired-update-property (prop value) | ||
| 2067 | "Update text property PROP with value VALUE at point." | ||
| 2068 | (let ((inhibit-read-only t)) | ||
| 2069 | (put-text-property | ||
| 2070 | (point) (1+ (point)) | ||
| 2071 | prop | ||
| 2072 | value))) | ||
| 2073 | |||
| 2074 | ;;;###autoload | ||
| 2075 | (defun image-dired-dired-comment-files () | ||
| 2076 | "Add comment to current or marked files in dired." | ||
| 2077 | (interactive) | ||
| 2078 | (let ((comment (image-dired-read-comment))) | ||
| 2079 | (image-dired-write-comments | ||
| 2080 | (mapcar | ||
| 2081 | (lambda (curr-file) | ||
| 2082 | (cons curr-file comment)) | ||
| 2083 | (dired-get-marked-files))))) | ||
| 2084 | |||
| 2085 | (defun image-dired-comment-thumbnail () | ||
| 2086 | "Add comment to current thumbnail in thumbnail buffer." | ||
| 2087 | (interactive) | ||
| 2088 | (let* ((file (image-dired-original-file-name)) | ||
| 2089 | (comment (image-dired-read-comment file))) | ||
| 2090 | (image-dired-write-comments (list (cons file comment))) | ||
| 2091 | (image-dired-update-property 'comment comment)) | ||
| 2092 | (image-dired-display-thumb-properties)) | ||
| 2093 | |||
| 2094 | (defun image-dired-read-comment (&optional file) | ||
| 2095 | "Read comment for an image. | ||
| 2096 | Read comment for an image, optionally using old comment from FILE | ||
| 2097 | as initial value." | ||
| 2098 | (let ((comment | ||
| 2099 | (read-string | ||
| 2100 | "Comment: " | ||
| 2101 | (if file (image-dired-get-comment file))))) | ||
| 2102 | comment)) | ||
| 2103 | |||
| 2104 | (defun image-dired-get-comment (file) | ||
| 2105 | "Get comment for file FILE." | ||
| 2106 | (save-excursion | ||
| 2107 | (let (end buf comment-beg-pos comment-end-pos comment) | ||
| 2108 | (setq buf (find-file image-dired-db-file)) | ||
| 2109 | (goto-char (point-min)) | ||
| 2110 | (when (search-forward-regexp | ||
| 2111 | (format "^%s" file) nil t) | ||
| 2112 | (end-of-line) | ||
| 2113 | (setq end (point)) | ||
| 2114 | (beginning-of-line) | ||
| 2115 | (cond ((search-forward ";comment:" end t) | ||
| 2116 | (setq comment-beg-pos (point)) | ||
| 2117 | (if (search-forward ";" end t) | ||
| 2118 | (setq comment-end-pos (- (point) 1)) | ||
| 2119 | (setq comment-end-pos end)) | ||
| 2120 | (setq comment (buffer-substring | ||
| 2121 | comment-beg-pos comment-end-pos))))) | ||
| 2122 | (kill-buffer buf) | ||
| 2123 | comment))) | ||
| 2124 | |||
| 2125 | ;;;###autoload | ||
| 2126 | (defun image-dired-mark-tagged-files () | ||
| 2127 | "Use regexp to mark files with matching tag. | ||
| 2128 | A `tag' is a keyword, a piece of meta data, associated with an | ||
| 2129 | image file and stored in image-dired's database file. This command | ||
| 2130 | lets you input a regexp and this will be matched against all tags | ||
| 2131 | on all image files in the database file. The files that have a | ||
| 2132 | matching tags will be marked in the dired buffer." | ||
| 2133 | (interactive) | ||
| 2134 | (let ((tag (read-string "Mark tagged files (regexp): ")) | ||
| 2135 | (hits 0) | ||
| 2136 | files buf) | ||
| 2137 | (save-excursion | ||
| 2138 | (setq buf (find-file image-dired-db-file)) | ||
| 2139 | (goto-char (point-min)) | ||
| 2140 | ;; Collect matches | ||
| 2141 | (while (search-forward-regexp | ||
| 2142 | (concat "\\(^[^;\n]+\\);.*" tag ".*$") nil t) | ||
| 2143 | (setq files (append (list (match-string 1)) files))) | ||
| 2144 | (kill-buffer buf) | ||
| 2145 | ;; Mark files | ||
| 2146 | (mapcar | ||
| 2147 | ;; I tried using `dired-mark-files-regexp' but it was | ||
| 2148 | ;; waaaay to slow. | ||
| 2149 | (lambda (curr-file) | ||
| 2150 | ;; Don't bother about hits found in other directories than | ||
| 2151 | ;; the current one. | ||
| 2152 | (when (string= (file-name-as-directory | ||
| 2153 | (expand-file-name default-directory)) | ||
| 2154 | (file-name-as-directory | ||
| 2155 | (file-name-directory curr-file))) | ||
| 2156 | (setq curr-file (file-name-nondirectory curr-file)) | ||
| 2157 | (goto-char (point-min)) | ||
| 2158 | (when (search-forward-regexp (format "\\s %s$" curr-file) nil t) | ||
| 2159 | (setq hits (+ hits 1)) | ||
| 2160 | (dired-mark 1)))) | ||
| 2161 | files)) | ||
| 2162 | (message "%d files with matching tag marked." hits))) | ||
| 2163 | |||
| 2164 | (defun image-dired-mouse-display-image (event) | ||
| 2165 | "Use mouse EVENT, call `image-dired-display-image' to display image. | ||
| 2166 | Track this in associated dired buffer if `image-dired-track-movement' is | ||
| 2167 | non-nil." | ||
| 2168 | (interactive "e") | ||
| 2169 | (let (file) | ||
| 2170 | (mouse-set-point event) | ||
| 2171 | (goto-char (posn-point (event-end event))) | ||
| 2172 | (setq file (image-dired-original-file-name)) | ||
| 2173 | (if image-dired-track-movement | ||
| 2174 | (image-dired-track-original-file)) | ||
| 2175 | (image-dired-create-display-image-buffer) | ||
| 2176 | (display-buffer image-dired-display-image-buffer) | ||
| 2177 | (image-dired-display-image file))) | ||
| 2178 | |||
| 2179 | (defun image-dired-mouse-select-thumbnail (event) | ||
| 2180 | "Use mouse EVENT to select thumbnail image. | ||
| 2181 | Track this in associated dired buffer if `image-dired-track-movement' is | ||
| 2182 | non-nil." | ||
| 2183 | (interactive "e") | ||
| 2184 | (let (file) | ||
| 2185 | (mouse-set-point event) | ||
| 2186 | (goto-char (posn-point (event-end event))) | ||
| 2187 | (if image-dired-track-movement | ||
| 2188 | (image-dired-track-original-file))) | ||
| 2189 | (image-dired-display-thumb-properties)) | ||
| 2190 | |||
| 2191 | (defun image-dired-mouse-toggle-mark (event) | ||
| 2192 | "Use mouse EVENT to toggle dired mark for thumbnail. | ||
| 2193 | Track this in associated dired buffer if `image-dired-track-movement' is | ||
| 2194 | non-nil." | ||
| 2195 | (interactive "e") | ||
| 2196 | (let (file) | ||
| 2197 | (mouse-set-point event) | ||
| 2198 | (goto-char (posn-point (event-end event))) | ||
| 2199 | (if image-dired-track-movement | ||
| 2200 | (image-dired-track-original-file))) | ||
| 2201 | (image-dired-toggle-mark-thumb-original-file)) | ||
| 2202 | |||
| 2203 | (defun image-dired-dired-display-properties () | ||
| 2204 | "Display properties for dired file in the echo area." | ||
| 2205 | (interactive) | ||
| 2206 | (let* ((file (dired-get-filename)) | ||
| 2207 | (file-name (file-name-nondirectory file)) | ||
| 2208 | (dired-buf (buffer-name (current-buffer))) | ||
| 2209 | (props (mapconcat | ||
| 2210 | 'princ | ||
| 2211 | (image-dired-list-tags file) | ||
| 2212 | ", ")) | ||
| 2213 | (comment (image-dired-get-comment file))) | ||
| 2214 | (if file-name | ||
| 2215 | (message | ||
| 2216 | (image-dired-format-properties-string | ||
| 2217 | dired-buf | ||
| 2218 | file-name | ||
| 2219 | props | ||
| 2220 | comment))))) | ||
| 2221 | |||
| 2222 | (defvar image-dired-tag-file-list nil | ||
| 2223 | "List to store tag-file structure.") | ||
| 2224 | |||
| 2225 | (defvar image-dired-file-tag-list nil | ||
| 2226 | "List to store file-tag structure.") | ||
| 2227 | |||
| 2228 | (defvar image-dired-file-comment-list nil | ||
| 2229 | "List to store file comments.") | ||
| 2230 | |||
| 2231 | (defun image-dired-add-to-tag-file-list (tag file) | ||
| 2232 | "Add relation between TAG and FILE." | ||
| 2233 | (let (curr) | ||
| 2234 | (if image-dired-tag-file-list | ||
| 2235 | (if (setq curr (assoc tag image-dired-tag-file-list)) | ||
| 2236 | (if (not (member file curr)) | ||
| 2237 | (setcdr curr (cons file (cdr curr)))) | ||
| 2238 | (setcdr image-dired-tag-file-list | ||
| 2239 | (cons (list tag file) (cdr image-dired-tag-file-list)))) | ||
| 2240 | (setq image-dired-tag-file-list (list (list tag file)))))) | ||
| 2241 | |||
| 2242 | (defun image-dired-add-to-tag-file-lists (tag file) | ||
| 2243 | "Helper function used from `image-dired-create-gallery-lists'. | ||
| 2244 | |||
| 2245 | Add TAG to FILE in one list and FILE to TAG in the other. | ||
| 2246 | |||
| 2247 | Lisp structures look like the following: | ||
| 2248 | |||
| 2249 | image-dired-file-tag-list: | ||
| 2250 | |||
| 2251 | ((\"filename1\" \"tag1\" \"tag2\" \"tag3\" ...) | ||
| 2252 | (\"filename2\" \"tag1\" \"tag2\" \"tag3\" ...) | ||
| 2253 | ...) | ||
| 2254 | |||
| 2255 | image-dired-tag-file-list: | ||
| 2256 | |||
| 2257 | ((\"tag1\" \"filename1\" \"filename2\" \"filename3\" ...) | ||
| 2258 | (\"tag2\" \"filename1\" \"filename2\" \"filename3\" ...) | ||
| 2259 | ...)" | ||
| 2260 | ;; Add tag to file list | ||
| 2261 | (let (curr) | ||
| 2262 | (if image-dired-file-tag-list | ||
| 2263 | (if (setq curr (assoc file image-dired-file-tag-list)) | ||
| 2264 | (setcdr curr (cons tag (cdr curr))) | ||
| 2265 | (setcdr image-dired-file-tag-list | ||
| 2266 | (cons (list file tag) (cdr image-dired-file-tag-list)))) | ||
| 2267 | (setq image-dired-file-tag-list (list (list file tag)))) | ||
| 2268 | ;; Add file to tag list | ||
| 2269 | (if image-dired-tag-file-list | ||
| 2270 | (if (setq curr (assoc tag image-dired-tag-file-list)) | ||
| 2271 | (if (not (member file curr)) | ||
| 2272 | (setcdr curr (cons file (cdr curr)))) | ||
| 2273 | (setcdr image-dired-tag-file-list | ||
| 2274 | (cons (list tag file) (cdr image-dired-tag-file-list)))) | ||
| 2275 | (setq image-dired-tag-file-list (list (list tag file)))))) | ||
| 2276 | |||
| 2277 | (defun image-dired-add-to-file-comment-list (file comment) | ||
| 2278 | "Helper function used from `image-dired-create-gallery-lists'. | ||
| 2279 | |||
| 2280 | For FILE, add COMMENT to list. | ||
| 2281 | |||
| 2282 | Lisp structure looks like the following: | ||
| 2283 | |||
| 2284 | image-dired-file-comment-list: | ||
| 2285 | |||
| 2286 | ((\"filename1\" . \"comment1\") | ||
| 2287 | (\"filename2\" . \"comment2\") | ||
| 2288 | ...)" | ||
| 2289 | (if image-dired-file-comment-list | ||
| 2290 | (if (not (assoc file image-dired-file-comment-list)) | ||
| 2291 | (setcdr image-dired-file-comment-list | ||
| 2292 | (cons (cons file comment) | ||
| 2293 | (cdr image-dired-file-comment-list)))) | ||
| 2294 | (setq image-dired-file-comment-list (list (cons file comment))))) | ||
| 2295 | |||
| 2296 | (defun image-dired-create-gallery-lists () | ||
| 2297 | "Create temporary lists used by `image-dired-gallery-generate'." | ||
| 2298 | (let ((buf (find-file image-dired-db-file)) | ||
| 2299 | end beg file row-tags) | ||
| 2300 | (setq image-dired-tag-file-list nil) | ||
| 2301 | (setq image-dired-file-tag-list nil) | ||
| 2302 | (setq image-dired-file-comment-list nil) | ||
| 2303 | (goto-char (point-min)) | ||
| 2304 | (while (search-forward-regexp "^." nil t) | ||
| 2305 | (end-of-line) | ||
| 2306 | (setq end (point)) | ||
| 2307 | (beginning-of-line) | ||
| 2308 | (setq beg (point)) | ||
| 2309 | (if (not (search-forward ";" end nil)) | ||
| 2310 | (error "Something is really wrong, check format of database")) | ||
| 2311 | (setq row-tags (split-string | ||
| 2312 | (buffer-substring beg end) ";")) | ||
| 2313 | (setq file (car row-tags)) | ||
| 2314 | (mapc | ||
| 2315 | (lambda (x) | ||
| 2316 | (if (not (string-match "^comment:\\(.*\\)" x)) | ||
| 2317 | (image-dired-add-to-tag-file-lists x file) | ||
| 2318 | (image-dired-add-to-file-comment-list file (match-string 1 x)))) | ||
| 2319 | (cdr row-tags))) | ||
| 2320 | (kill-buffer buf)) | ||
| 2321 | ;; Sort tag-file list | ||
| 2322 | (setq image-dired-tag-file-list | ||
| 2323 | (sort image-dired-tag-file-list | ||
| 2324 | (lambda (x y) | ||
| 2325 | (string< (car x) (car y)))))) | ||
| 2326 | |||
| 2327 | (defun image-dired-hidden-p (file) | ||
| 2328 | "Return t if image FILE has a \"hidden\" tag." | ||
| 2329 | (let (hidden) | ||
| 2330 | (mapc | ||
| 2331 | (lambda (tag) | ||
| 2332 | (if (member tag image-dired-gallery-hidden-tags) | ||
| 2333 | (setq hidden t))) | ||
| 2334 | (cdr (assoc file image-dired-file-tag-list))) | ||
| 2335 | hidden)) | ||
| 2336 | |||
| 2337 | (defun image-dired-gallery-generate () | ||
| 2338 | "Generate gallery pages. | ||
| 2339 | First we create a couple of Lisp structures from the database to make | ||
| 2340 | it easier to generate, then HTML-files are created in | ||
| 2341 | `image-dired-gallery-dir'" | ||
| 2342 | (interactive) | ||
| 2343 | (if (eq 'per-directory image-dired-thumbnail-storage) | ||
| 2344 | (error "Currently, gallery generation is not supported \ | ||
| 2345 | when using per-directory thumbnail file storage")) | ||
| 2346 | (image-dired-create-gallery-lists) | ||
| 2347 | (let ((tags image-dired-tag-file-list) | ||
| 2348 | count curr tag index-buf tag-buf | ||
| 2349 | comment file-tags tag-link tag-link-list) | ||
| 2350 | ;; Make sure gallery root exist | ||
| 2351 | (if (file-exists-p image-dired-gallery-dir) | ||
| 2352 | (if (not (file-directory-p image-dired-gallery-dir)) | ||
| 2353 | (error "Variable image-dired-gallery-dir is not a directory")) | ||
| 2354 | (make-directory image-dired-gallery-dir)) | ||
| 2355 | ;; Open index file | ||
| 2356 | (setq index-buf (find-file | ||
| 2357 | (format "%s/index.html" image-dired-gallery-dir))) | ||
| 2358 | (erase-buffer) | ||
| 2359 | (insert "<html>\n") | ||
| 2360 | (insert " <body>\n") | ||
| 2361 | (insert " <h2>Image-Dired Gallery</h2>\n") | ||
| 2362 | (insert (format "<p>\n Gallery generated %s\n <p>\n" | ||
| 2363 | (current-time-string))) | ||
| 2364 | (insert " <h3>Tag index</h3>\n") | ||
| 2365 | (setq count 1) | ||
| 2366 | ;; Pre-generate list of all tag links | ||
| 2367 | (mapc | ||
| 2368 | (lambda (curr) | ||
| 2369 | (setq tag (car curr)) | ||
| 2370 | (when (not (member tag image-dired-gallery-hidden-tags)) | ||
| 2371 | (setq tag-link (format "<a href=\"%d.html\">%s</a>" count tag)) | ||
| 2372 | (if tag-link-list | ||
| 2373 | (setq tag-link-list | ||
| 2374 | (append tag-link-list (list (cons tag tag-link)))) | ||
| 2375 | (setq tag-link-list (list (cons tag tag-link)))) | ||
| 2376 | (setq count (1+ count)))) | ||
| 2377 | tags) | ||
| 2378 | (setq count 1) | ||
| 2379 | ;; Main loop where we generated thumbnail pages per tag | ||
| 2380 | (mapc | ||
| 2381 | (lambda (curr) | ||
| 2382 | (setq tag (car curr)) | ||
| 2383 | ;; Don't display hidden tags | ||
| 2384 | (when (not (member tag image-dired-gallery-hidden-tags)) | ||
| 2385 | ;; Insert link to tag page in index | ||
| 2386 | (insert (format " %s<br>\n" (cdr (assoc tag tag-link-list)))) | ||
| 2387 | ;; Open per-tag file | ||
| 2388 | (setq tag-buf (find-file | ||
| 2389 | (format "%s/%s.html" image-dired-gallery-dir count))) | ||
| 2390 | (erase-buffer) | ||
| 2391 | (insert "<html>\n") | ||
| 2392 | (insert " <body>\n") | ||
| 2393 | (insert " <p><a href=\"index.html\">Index</a></p>\n") | ||
| 2394 | (insert (format " <h2>Images with tag "%s"</h2>" tag)) | ||
| 2395 | ;; Main loop for files per tag page | ||
| 2396 | (mapc | ||
| 2397 | (lambda (file) | ||
| 2398 | (when (not (image-dired-hidden-p file)) | ||
| 2399 | ;; Insert thumbnail with link to full image | ||
| 2400 | (insert | ||
| 2401 | (format "<a href=\"%s/%s\"><img src=\"%s/%s\"%s></a>\n" | ||
| 2402 | image-dired-gallery-image-root-url | ||
| 2403 | (file-name-nondirectory file) | ||
| 2404 | image-dired-gallery-thumb-image-root-url | ||
| 2405 | (file-name-nondirectory (image-dired-thumb-name file)) file)) | ||
| 2406 | ;; Insert comment, if any | ||
| 2407 | (if (setq comment (cdr (assoc file image-dired-file-comment-list))) | ||
| 2408 | (insert (format "<br>\n%s<br>\n" comment)) | ||
| 2409 | (insert "<br>\n")) | ||
| 2410 | ;; Insert links to other tags, if any | ||
| 2411 | (when (> (length | ||
| 2412 | (setq file-tags (assoc file image-dired-file-tag-list))) 2) | ||
| 2413 | (insert "[ ") | ||
| 2414 | (mapc | ||
| 2415 | (lambda (extra-tag) | ||
| 2416 | ;; Only insert if not file name or the main tag | ||
| 2417 | (if (and (not (equal extra-tag tag)) | ||
| 2418 | (not (equal extra-tag file))) | ||
| 2419 | (insert | ||
| 2420 | (format "%s " (cdr (assoc extra-tag tag-link-list)))))) | ||
| 2421 | file-tags) | ||
| 2422 | (insert "]<br>\n")))) | ||
| 2423 | (cdr curr)) | ||
| 2424 | (insert " <p><a href=\"index.html\">Index</a></p>\n") | ||
| 2425 | (insert " </body>\n") | ||
| 2426 | (insert "</html>\n") | ||
| 2427 | (save-buffer) | ||
| 2428 | (kill-buffer tag-buf) | ||
| 2429 | (setq count (1+ count)))) | ||
| 2430 | tags) | ||
| 2431 | (insert " </body>\n") | ||
| 2432 | (insert "</html>") | ||
| 2433 | (save-buffer) | ||
| 2434 | (kill-buffer index-buf))) | ||
| 2435 | |||
| 2436 | (defun image-dired-kill-buffer-and-window () | ||
| 2437 | "Kill the current buffer and, if possible, also the window." | ||
| 2438 | (interactive) | ||
| 2439 | (let ((buffer (current-buffer))) | ||
| 2440 | (condition-case nil | ||
| 2441 | (delete-window (selected-window)) | ||
| 2442 | (error nil)) | ||
| 2443 | (kill-buffer buffer))) | ||
| 2444 | |||
| 2445 | (defvar image-dired-widget-list nil | ||
| 2446 | "List to keep track of meta data in edit buffer.") | ||
| 2447 | |||
| 2448 | ;;;###autoload | ||
| 2449 | (defun image-dired-dired-edit-comment-and-tags () | ||
| 2450 | "Edit comment and tags of current or marked image files. | ||
| 2451 | Edit comment and tags for all marked image files in an | ||
| 2452 | easy-to-use form." | ||
| 2453 | (interactive) | ||
| 2454 | (setq image-dired-widget-list nil) | ||
| 2455 | ;; Setup buffer. | ||
| 2456 | (let ((files (dired-get-marked-files))) | ||
| 2457 | (switch-to-buffer "*Image-Dired Edit Meta Data*") | ||
| 2458 | (kill-all-local-variables) | ||
| 2459 | (make-local-variable 'widget-example-repeat) | ||
| 2460 | (let ((inhibit-read-only t)) | ||
| 2461 | (erase-buffer)) | ||
| 2462 | (remove-overlays) | ||
| 2463 | ;; Some help for the user. | ||
| 2464 | (widget-insert | ||
| 2465 | "\nEdit comments and tags for each image. Separate multiple tags | ||
| 2466 | with a comma. Move forward between fields using TAB or RET. | ||
| 2467 | Move to the previous field using backtab (S-TAB). Save by | ||
| 2468 | activating the Save button at the bottom of the form or cancel | ||
| 2469 | the operation by activating the Cancel button.\n\n") | ||
| 2470 | ;; Here comes all images and a comment and tag field for each | ||
| 2471 | ;; image. | ||
| 2472 | (let (thumb-file img comment-widget tag-widget) | ||
| 2473 | |||
| 2474 | (dolist (file files) | ||
| 2475 | |||
| 2476 | (setq thumb-file (image-dired-thumb-name file) | ||
| 2477 | img (create-image thumb-file)) | ||
| 2478 | |||
| 2479 | (insert-image img) | ||
| 2480 | (widget-insert "\n\nComment: ") | ||
| 2481 | (setq comment-widget | ||
| 2482 | (widget-create 'editable-field | ||
| 2483 | :size 60 | ||
| 2484 | :format "%v " | ||
| 2485 | :value (or (image-dired-get-comment file) ""))) | ||
| 2486 | (widget-insert "\nTags: ") | ||
| 2487 | (setq tag-widget | ||
| 2488 | (widget-create 'editable-field | ||
| 2489 | :size 60 | ||
| 2490 | :format "%v " | ||
| 2491 | :value (or (mapconcat | ||
| 2492 | (lambda (tag) | ||
| 2493 | tag) | ||
| 2494 | (image-dired-list-tags file) | ||
| 2495 | ",") ""))) | ||
| 2496 | ;; Save information in all widgets so that we can use it when | ||
| 2497 | ;; the user saves the form. | ||
| 2498 | (setq image-dired-widget-list | ||
| 2499 | (append image-dired-widget-list | ||
| 2500 | (list (list file comment-widget tag-widget)))) | ||
| 2501 | (widget-insert "\n\n"))) | ||
| 2502 | |||
| 2503 | ;; Footer with Save and Cancel button. | ||
| 2504 | (widget-insert "\n") | ||
| 2505 | (widget-create 'push-button | ||
| 2506 | :notify | ||
| 2507 | (lambda (&rest ignore) | ||
| 2508 | (image-dired-save-information-from-widgets) | ||
| 2509 | (bury-buffer) | ||
| 2510 | (message "Done.")) | ||
| 2511 | "Save") | ||
| 2512 | (widget-insert " ") | ||
| 2513 | (widget-create 'push-button | ||
| 2514 | :notify | ||
| 2515 | (lambda (&rest ignore) | ||
| 2516 | (bury-buffer) | ||
| 2517 | (message "Operation canceled.")) | ||
| 2518 | "Cancel") | ||
| 2519 | (widget-insert "\n") | ||
| 2520 | (use-local-map widget-keymap) | ||
| 2521 | (widget-setup) | ||
| 2522 | ;; Jump to the first widget. | ||
| 2523 | (widget-forward 1))) | ||
| 2524 | |||
| 2525 | (defun image-dired-save-information-from-widgets () | ||
| 2526 | "Save information found in `image-dired-widget-list'. | ||
| 2527 | Use the information in `image-dired-widget-list' to save comments and | ||
| 2528 | tags to their respective image file. Internal function used by | ||
| 2529 | `image-dired-dired-edit-comment-and-tags'." | ||
| 2530 | (let (file comment tag-string tag-list lst) | ||
| 2531 | (image-dired-write-comments | ||
| 2532 | (mapcar | ||
| 2533 | (lambda (widget) | ||
| 2534 | (setq file (car widget) | ||
| 2535 | comment (widget-value (cadr widget))) | ||
| 2536 | (cons file comment)) | ||
| 2537 | image-dired-widget-list)) | ||
| 2538 | (image-dired-write-tags | ||
| 2539 | (dolist (widget image-dired-widget-list lst) | ||
| 2540 | (setq file (car widget) | ||
| 2541 | tag-string (widget-value (car (cddr widget))) | ||
| 2542 | tag-list (split-string tag-string ",")) | ||
| 2543 | (dolist (tag tag-list) | ||
| 2544 | (push (cons file tag) lst)))))) | ||
| 2545 | |||
| 2546 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 2547 | ;;;;;;;;; TEST-SECTION ;;;;;;;;;;; | ||
| 2548 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 2549 | |||
| 2550 | ;; (defvar image-dired-dir-max-size 12300000) | ||
| 2551 | |||
| 2552 | ;; (defun image-dired-test-clean-old-files () | ||
| 2553 | ;; "Clean `image-dired-dir' from old thumbnail files. | ||
| 2554 | ;; \"Oldness\" measured using last access time. If the total size of all | ||
| 2555 | ;; thumbnail files in `image-dired-dir' is larger than 'image-dired-dir-max-size', | ||
| 2556 | ;; old files are deleted until the max size is reached." | ||
| 2557 | ;; (let* ((files | ||
| 2558 | ;; (sort | ||
| 2559 | ;; (mapcar | ||
| 2560 | ;; (lambda (f) | ||
| 2561 | ;; (let ((fattribs (file-attributes f))) | ||
| 2562 | ;; ;; Get last access time and file size | ||
| 2563 | ;; `(,(nth 4 fattribs) ,(nth 7 fattribs) ,f))) | ||
| 2564 | ;; (directory-files (image-dired-dir) t ".+\.thumb\..+$")) | ||
| 2565 | ;; ;; Sort function. Compare time between two files. | ||
| 2566 | ;; '(lambda (l1 l2) | ||
| 2567 | ;; (time-less-p (car l1) (car l2))))) | ||
| 2568 | ;; (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files)))) | ||
| 2569 | ;; (while (> dirsize image-dired-dir-max-size) | ||
| 2570 | ;; (y-or-n-p | ||
| 2571 | ;; (format "Size of thumbnail directory: %d, delete old file %s? " | ||
| 2572 | ;; dirsize (cadr (cdar files)))) | ||
| 2573 | ;; (delete-file (cadr (cdar files))) | ||
| 2574 | ;; (setq dirsize (- dirsize (car (cdar files)))) | ||
| 2575 | ;; (setq files (cdr files))))) | ||
| 2576 | |||
| 2577 | ;;;;;;;;;;;;;;;;;;;;;;, | ||
| 2578 | |||
| 2579 | ;; (defun dired-speedbar-buttons (dired-buffer) | ||
| 2580 | ;; (when (and (boundp 'image-dired-use-speedbar) | ||
| 2581 | ;; image-dired-use-speedbar) | ||
| 2582 | ;; (let ((filename (with-current-buffer dired-buffer | ||
| 2583 | ;; (dired-get-filename)))) | ||
| 2584 | ;; (when (and (not (string-equal filename (buffer-string))) | ||
| 2585 | ;; (string-match (image-file-name-regexp) filename)) | ||
| 2586 | ;; (erase-buffer) | ||
| 2587 | ;; (insert (propertize | ||
| 2588 | ;; filename | ||
| 2589 | ;; 'display | ||
| 2590 | ;; (image-dired-get-thumbnail-image filename))))))) | ||
| 2591 | |||
| 2592 | ;; (setq image-dired-use-speedbar t) | ||
| 2593 | |||
| 2594 | (provide 'image-dired) | ||
| 2595 | |||
| 2596 | ;; arch-tag: 9d11411d-331f-4380-8b44-8adfe3a0343e | ||
| 2597 | ;;; image-dired.el ends here | ||