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