Mercurial > emacs
comparison lisp/thumbs.el @ 55206:c2c29cafaa74
(time-less-p): Remove.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 27 Apr 2004 22:43:35 +0000 |
parents | 318542a275c4 |
children | a911edb6dadf |
comparison
equal
deleted
inserted
replaced
55205:bc07155aabd8 | 55206:c2c29cafaa74 |
---|---|
1 ;;; thumbs.el --- Thumbnails previewer for images files | 1 ;;; thumbs.el --- Thumbnails previewer for images files |
2 ;;; | 2 ;;; |
3 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca> | 3 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca> |
4 ;; | 4 ;; |
5 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time | 5 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time |
6 ;; The peoples at #emacs@freenode.net for numerous help | 6 ;; The peoples at #emacs@freenode.net for numerous help |
7 ;; RMS for emacs and the GNU project. | 7 ;; RMS for emacs and the GNU project. |
8 ;; | 8 ;; |
9 ;; Keywords: Multimedia | 9 ;; Keywords: Multimedia |
50 ;; C-t a enter in thumbs-mode with all files in current-directory | 50 ;; C-t a enter in thumbs-mode with all files in current-directory |
51 ;; In thumbs-mode, pressing <return> on a image will bring you in image view mode | 51 ;; In thumbs-mode, pressing <return> on a image will bring you in image view mode |
52 ;; for that image. C-h m will give you a list of available keybinding. | 52 ;; for that image. C-h m will give you a list of available keybinding. |
53 | 53 |
54 ;;; History: | 54 ;;; History: |
55 ;; | 55 ;; |
56 | 56 |
57 ;;; Code: | 57 ;;; Code: |
58 | 58 |
59 (require 'dired) | 59 (require 'dired) |
60 | 60 |
61 ;; Abort if in-line imaging isn't supported (i.e. Emacs-20.7) | 61 ;; Abort if in-line imaging isn't supported (i.e. Emacs-20.7) |
62 | 62 |
63 (when (not (display-images-p)) | 63 (when (not (display-images-p)) |
64 (error "Your Emacs version (%S) doesn't support in-line images, | 64 (error "Your Emacs version (%S) doesn't support in-line images, |
65 was not compiled with image support or is run in console mode. | 65 was not compiled with image support or is run in console mode. |
66 Upgrade to Emacs 21.1 or newer, compile it with image support | 66 Upgrade to Emacs 21.1 or newer, compile it with image support |
67 or use a window-system" | 67 or use a window-system" |
68 emacs-version)) | 68 emacs-version)) |
69 | 69 |
70 ;; CUSTOMIZATIONS | 70 ;; CUSTOMIZATIONS |
71 | 71 |
72 (defgroup thumbs nil | 72 (defgroup thumbs nil |
146 "Prefix to add to temp files." | 146 "Prefix to add to temp files." |
147 :type 'string | 147 :type 'string |
148 :group 'thumbs) | 148 :group 'thumbs) |
149 | 149 |
150 ;; Initialize some variable, for later use. | 150 ;; Initialize some variable, for later use. |
151 (defvar thumbs-temp-file | 151 (defvar thumbs-temp-file |
152 (concat thumbs-temp-dir thumbs-temp-prefix) | 152 (concat thumbs-temp-dir thumbs-temp-prefix) |
153 "Temporary filesname for images.") | 153 "Temporary filesname for images.") |
154 | 154 |
155 (defvar thumbs-current-tmp-filename | 155 (defvar thumbs-current-tmp-filename |
156 nil | 156 nil |
157 "Temporary filename of current image.") | 157 "Temporary filename of current image.") |
158 (defvar thumbs-current-image-filename | 158 (defvar thumbs-current-image-filename |
159 nil | 159 nil |
160 "Filename of current image.") | 160 "Filename of current image.") |
161 (defvar thumbs-current-image-size | 161 (defvar thumbs-current-image-size |
162 nil | 162 nil |
163 "Size of current image.") | 163 "Size of current image.") |
164 (defvar thumbs-image-num | 164 (defvar thumbs-image-num |
165 nil | 165 nil |
166 "Number of current image.") | 166 "Number of current image.") |
167 (defvar thumbs-current-dir | 167 (defvar thumbs-current-dir |
168 nil | 168 nil |
169 "Current directory.") | 169 "Current directory.") |
170 (defvar thumbs-markedL | 170 (defvar thumbs-markedL |
171 nil | 171 nil |
172 "List of marked files.") | 172 "List of marked files.") |
173 | 173 |
174 ;; Make sure auto-image-file-mode is ON. | 174 ;; Make sure auto-image-file-mode is ON. |
175 (auto-image-file-mode t) | 175 (auto-image-file-mode t) |
185 (when (not (fboundp 'ignore-errors)) | 185 (when (not (fboundp 'ignore-errors)) |
186 (defmacro ignore-errors (&rest body) | 186 (defmacro ignore-errors (&rest body) |
187 "Execute FORMS; if anz error occurs, return nil. | 187 "Execute FORMS; if anz error occurs, return nil. |
188 Otherwise, return result of last FORM." | 188 Otherwise, return result of last FORM." |
189 (let ((err (thumbs-gensym))) | 189 (let ((err (thumbs-gensym))) |
190 (list 'condition-case err (cons 'progn body) '(error nil))))) | 190 (list 'condition-case err (cons 'progn body) '(error nil))))) |
191 | |
192 (when (not (fboundp 'time-less-p)) | |
193 (defun time-less-p (t1 t2) | |
194 "Say whether time T1 is less than time T2." | |
195 (or (< (car t1) (car t2)) | |
196 (and (= (car t1) (car t2)) | |
197 (< (nth 1 t1) (nth 1 t2)))))) | |
198 | 191 |
199 (when (not (fboundp 'caddar)) | 192 (when (not (fboundp 'caddar)) |
200 (defun caddar (x) | 193 (defun caddar (x) |
201 "Return the `car' of the `cdr' of the `cdr' of the `car' of X." | 194 "Return the `car' of the `cdr' of the `cdr' of the `car' of X." |
202 (car (cdr (cdr (car x)))))) | 195 (car (cdr (cdr (car x)))))) |
206 (defun thumbs-gensym (&optional arg) | 199 (defun thumbs-gensym (&optional arg) |
207 "Generate a new uninterned symbol. | 200 "Generate a new uninterned symbol. |
208 The name is made by appending a number to PREFIX, default \"Thumbs\"." | 201 The name is made by appending a number to PREFIX, default \"Thumbs\"." |
209 (let ((prefix (if (stringp arg) arg "Thumbs")) | 202 (let ((prefix (if (stringp arg) arg "Thumbs")) |
210 (num (if (integerp arg) arg | 203 (num (if (integerp arg) arg |
211 (prog1 | 204 (prog1 |
212 thumbs-gensym-counter | 205 thumbs-gensym-counter |
213 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter)))))) | 206 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter)))))) |
214 (make-symbol (format "%s%d" prefix num)))) | 207 (make-symbol (format "%s%d" prefix num)))) |
215 | 208 |
216 (defun thumbs-cleanup-thumbsdir () | 209 (defun thumbs-cleanup-thumbsdir () |
272 (cons | 265 (cons |
273 (thumbs-increment-image-size-element (car s) | 266 (thumbs-increment-image-size-element (car s) |
274 thumbs-image-resizing-step) | 267 thumbs-image-resizing-step) |
275 (thumbs-increment-image-size-element (cdr s) | 268 (thumbs-increment-image-size-element (cdr s) |
276 thumbs-image-resizing-step))) | 269 thumbs-image-resizing-step))) |
277 | 270 |
278 (defun thumbs-decrement-image-size (s) | 271 (defun thumbs-decrement-image-size (s) |
279 "Decrement S (a cons of width x heigh)." | 272 "Decrement S (a cons of width x heigh)." |
280 (cons | 273 (cons |
281 (thumbs-decrement-image-size-element (car s) | 274 (thumbs-decrement-image-size-element (car s) |
282 thumbs-image-resizing-step) | 275 thumbs-image-resizing-step) |
287 "Resize image in current buffer. | 280 "Resize image in current buffer. |
288 if INCREMENT is set, make the image bigger, else smaller. | 281 if INCREMENT is set, make the image bigger, else smaller. |
289 Or, alternatively, a SIZE may be specified." | 282 Or, alternatively, a SIZE may be specified." |
290 (interactive) | 283 (interactive) |
291 ;; cleaning of old temp file | 284 ;; cleaning of old temp file |
292 (ignore-errors | 285 (ignore-errors |
293 (apply 'delete-file | 286 (apply 'delete-file |
294 (directory-files | 287 (directory-files |
295 thumbs-temp-dir t | 288 thumbs-temp-dir t |
296 thumbs-temp-prefix))) | 289 thumbs-temp-prefix))) |
297 (let ((buffer-read-only nil) | 290 (let ((buffer-read-only nil) |
313 | 306 |
314 (defun thumbs-resize-interactive (width height) | 307 (defun thumbs-resize-interactive (width height) |
315 "Resize Image interactively to specified WIDTH and HEIGHT." | 308 "Resize Image interactively to specified WIDTH and HEIGHT." |
316 (interactive "nWidth: \nnHeight: ") | 309 (interactive "nWidth: \nnHeight: ") |
317 (thumbs-resize-image nil (cons width height))) | 310 (thumbs-resize-image nil (cons width height))) |
318 | 311 |
319 (defun thumbs-resize-image-size-down () | 312 (defun thumbs-resize-image-size-down () |
320 "Resize image (smaller)." | 313 "Resize image (smaller)." |
321 (interactive) | 314 (interactive) |
322 (thumbs-resize-image nil)) | 315 (thumbs-resize-image nil)) |
323 | 316 |
354 (tn (thumbs-thumbname img))) | 347 (tn (thumbs-thumbname img))) |
355 (if (or (not (file-exists-p tn)) | 348 (if (or (not (file-exists-p tn)) |
356 (not (equal (thumbs-file-size tn) thumbs-geometry))) | 349 (not (equal (thumbs-file-size tn) thumbs-geometry))) |
357 (thumbs-call-convert fn tn "sample" thumbs-geometry)) | 350 (thumbs-call-convert fn tn "sample" thumbs-geometry)) |
358 tn)) | 351 tn)) |
359 | 352 |
360 (defun thumbs-image-type (img) | 353 (defun thumbs-image-type (img) |
361 "Return image type from filename IMG." | 354 "Return image type from filename IMG." |
362 (cond ((string-match ".*\\.jpe?g\\'" img) 'jpeg) | 355 (cond ((string-match ".*\\.jpe?g\\'" img) 'jpeg) |
363 ((string-match ".*\\.xpm\\'" img) 'xpm) | 356 ((string-match ".*\\.xpm\\'" img) 'xpm) |
364 ((string-match ".*\\.xbm\\'" img) 'xbm) | 357 ((string-match ".*\\.xbm\\'" img) 'xbm) |
370 (defun thumbs-file-size (img) | 363 (defun thumbs-file-size (img) |
371 (let ((i (image-size (find-image `((:type ,(thumbs-image-type img) :file ,img))) t))) | 364 (let ((i (image-size (find-image `((:type ,(thumbs-image-type img) :file ,img))) t))) |
372 (concat (number-to-string (round (car i))) | 365 (concat (number-to-string (round (car i))) |
373 "x" | 366 "x" |
374 (number-to-string (round (cdr i)))))) | 367 (number-to-string (round (cdr i)))))) |
375 | 368 |
376 ;;;###autoload | 369 ;;;###autoload |
377 (defun thumbs-find-thumb (img) | 370 (defun thumbs-find-thumb (img) |
378 "Display the thumbnail for IMG." | 371 "Display the thumbnail for IMG." |
379 (interactive "f") | 372 (interactive "f") |
380 (find-file (thumbs-make-thumb img))) | 373 (find-file (thumbs-make-thumb img))) |
451 | 444 |
452 ;;;###autoload | 445 ;;;###autoload |
453 (defalias 'thumbs 'thumbs-show-all-from-dir) | 446 (defalias 'thumbs 'thumbs-show-all-from-dir) |
454 | 447 |
455 (defun thumbs-find-image (img L &optional num otherwin) | 448 (defun thumbs-find-image (img L &optional num otherwin) |
456 (funcall | 449 (funcall |
457 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer) | 450 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer) |
458 (concat "*Image: " (file-name-nondirectory img) " - " | 451 (concat "*Image: " (file-name-nondirectory img) " - " |
459 (number-to-string (or num 0)) "*")) | 452 (number-to-string (or num 0)) "*")) |
460 (thumbs-view-image-mode) | 453 (thumbs-view-image-mode) |
461 (let ((inhibit-read-only t)) | 454 (let ((inhibit-read-only t)) |
492 (shell-command (replace-regexp-in-string | 485 (shell-command (replace-regexp-in-string |
493 "\\*" | 486 "\\*" |
494 (shell-quote-argument (expand-file-name img)) | 487 (shell-quote-argument (expand-file-name img)) |
495 thumbs-setroot-command nil t)) | 488 thumbs-setroot-command nil t)) |
496 (run-hooks 'thumbs-after-setroot-hook)) | 489 (run-hooks 'thumbs-after-setroot-hook)) |
497 | 490 |
498 (defun thumbs-set-image-at-point-to-root-window () | 491 (defun thumbs-set-image-at-point-to-root-window () |
499 "Set the image at point as the desktop wallpaper." | 492 "Set the image at point as the desktop wallpaper." |
500 (interactive) | 493 (interactive) |
501 (thumbs-call-setroot-command (cdr (assoc (point) thumbs-fileL)))) | 494 (thumbs-call-setroot-command (cdr (assoc (point) thumbs-fileL)))) |
502 | 495 |
567 (let ((p (point)) | 560 (let ((p (point)) |
568 (inhibit-read-only t)) | 561 (inhibit-read-only t)) |
569 (delete-region (point-min)(point-max)) | 562 (delete-region (point-min)(point-max)) |
570 (thumbs-do-thumbs-insertion (reverse (mapcar 'cdr thumbs-fileL))) | 563 (thumbs-do-thumbs-insertion (reverse (mapcar 'cdr thumbs-fileL))) |
571 (goto-char (1+ p)))) | 564 (goto-char (1+ p)))) |
572 | 565 |
573 (defun thumbs-mark () | 566 (defun thumbs-mark () |
574 "Mark the image at point." | 567 "Mark the image at point." |
575 (interactive) | 568 (interactive) |
576 (setq thumbs-markedL (cons (cdr (assoc (point) thumbs-fileL)) thumbs-markedL)) | 569 (setq thumbs-markedL (cons (cdr (assoc (point) thumbs-fileL)) thumbs-markedL)) |
577 (let ((inhibit-read-only t)) | 570 (let ((inhibit-read-only t)) |
578 (delete-char 1) | 571 (delete-char 1) |
579 (thumbs-insert-thumb (cdr (assoc (point) thumbs-fileL)) t)) | 572 (thumbs-insert-thumb (cdr (assoc (point) thumbs-fileL)) t)) |
580 (when (eolp)(forward-char))) | 573 (when (eolp)(forward-char))) |
581 | 574 |
582 ;; Image modification routines | 575 ;; Image modification routines |
583 | 576 |
584 (defun thumbs-modify-image (action &optional arg) | 577 (defun thumbs-modify-image (action &optional arg) |
585 "Call convert to do ACTION on image with argument ARG. | 578 "Call convert to do ACTION on image with argument ARG. |
586 ACTION and ARG should be legal convert command." | 579 ACTION and ARG should be legal convert command." |