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