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