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