Mercurial > emacs
comparison lisp/thumbs.el @ 55827:c5c73c8c2b3e
Don't include cl. Don't bother with old Emacs versions.
(thumbs-subst-char-in-string): Deleted.
(thumbs-thumbname): Use subst-char-in-string.
(thumbs-resize-image): Use condition-case, not ignore-errors.
(thumbs-kill-buffer): Likewise.
(thumbs-mode): Make buffer read-only.
(thumbs-make-thumb): Unconditionally accept an existing file.
(thumbs-insert-thumb): Add thumb-image-file property to the image.
(thumbs-do-thumbs-insertion): Be smarter about where to put newlines.
(thumbs-show-thumbs-list): Error if images not supported.
(thumbs-save-current-image): Improve prompt string.
(thumbs-mode-map): Define u, R, x.
(thumbs-unmark): New command.
(thumbs-emboss-image): Minor cleanup.
(thumbs-forward-char, thumbs-backward-char): Skip chars with no image.
(thumbs-rename-images): New command.
(thumbs-show-image-num): Rewrite. Don't rename the buffer.
(thumbs-current-image): New function.
(thumbs-file-list, thumbs-file-alist): New functions.
(thumbs-find-image): Delete arg L.
Don't set up thumbs-fileL as buffer-local global var.
(thumbs-find-image-at-point): Use thumbs-current-image.
(thumbs-set-image-at-point-to-root-window): Likewise.
(thumbs-delete-images): Use thumbs-current-image, thumbs-file-alist.
Record and warn about errors. Update thumbs-markedL for deletions.
(thumbs-next-image, thumbs-previous-image): Use thumbs-file-alist.
(thumbs-redraw-buffer): Use thumbs-file-list.
(thumbs-mark): Use thumbs-current-image.
(thumbs-show-name): Use thumbs-current-image.
(thumbs-show-name): Do nothing if no image at point.
(thumbs-mouse-find-image): New command.
(thumbs-mode-map): Bind it to mouse-2.
(thumbs-mode): Make mode-class special.
(thumbs-view-image-mode): Likewise.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 29 May 2004 15:22:55 +0000 |
parents | c5dd3d0f1c5d |
children | ff141f26a0cb 4c90ffeb71c5 |
comparison
equal
deleted
inserted
replaced
55826:e7bdb5b77df2 | 55827:c5c73c8c2b3e |
---|---|
1 ;;; thumbs.el --- Thumbnails previewer for images files | 1 ;;; thumbs.el --- Thumbnails previewer for images files |
2 ;;; | 2 |
3 ;; Copyright 2004 Free Software Foundation, Inc | |
4 | |
3 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca> | 5 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca> |
4 ;; | 6 ;; Keywords: Multimedia |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 ;; | |
5 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time | 25 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time |
6 ;; The peoples at #emacs@freenode.net for numerous help | 26 ;; The peoples at #emacs@freenode.net for numerous help |
7 ;; RMS for emacs and the GNU project. | 27 ;; RMS for emacs and the GNU project. |
8 ;; | 28 ;; |
9 ;; Keywords: Multimedia | |
10 | |
11 (defconst thumbs-version "2.0") | |
12 | |
13 ;; This file is part of GNU Emacs. | |
14 | |
15 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 ;; it under the terms of the GNU General Public License as published by | |
17 ;; the Free Software Foundation; either version 2, or (at your option) | |
18 ;; any later version. | |
19 | |
20 ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 ;; GNU General Public License for more details. | |
24 | |
25 ;; You should have received a copy of the GNU General Public License | |
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 ;; Boston, MA 02111-1307, USA. | |
29 | 29 |
30 ;;; Commentary: | 30 ;;; Commentary: |
31 | 31 |
32 ;; This package create two new mode: thumbs-mode and | 32 ;; This package create two new mode: thumbs-mode and |
33 ;; thumbs-view-image-mode. It is used for images browsing and viewing | 33 ;; thumbs-view-image-mode. It is used for images browsing and viewing |
54 ;;; History: | 54 ;;; History: |
55 ;; | 55 ;; |
56 | 56 |
57 ;;; Code: | 57 ;;; Code: |
58 | 58 |
59 (eval-when-compile | |
60 (require 'cl)) | |
61 (require 'dired) | 59 (require 'dired) |
62 | |
63 ;; Abort if in-line imaging isn't supported (i.e. Emacs-20.7) | |
64 | |
65 (when (not (display-images-p)) | |
66 (error "Your Emacs version (%S) doesn't support in-line images, | |
67 was not compiled with image support or is run in console mode. | |
68 Upgrade to Emacs 21.1 or newer, compile it with image support | |
69 or use a window-system" | |
70 emacs-version)) | |
71 | 60 |
72 ;; CUSTOMIZATIONS | 61 ;; CUSTOMIZATIONS |
73 | 62 |
74 (defgroup thumbs nil | 63 (defgroup thumbs nil |
75 "Thumbnails previewer." | 64 "Thumbnails previewer." |
210 (directory-files thumbs-thumbsdir t (image-file-name-regexp))) | 199 (directory-files thumbs-thumbsdir t (image-file-name-regexp))) |
211 '(lambda (l1 l2) (time-less-p (car l1)(car l2))))) | 200 '(lambda (l1 l2) (time-less-p (car l1)(car l2))))) |
212 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL)))) | 201 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL)))) |
213 (while (> dirsize thumbs-thumbsdir-max-size) | 202 (while (> dirsize thumbs-thumbsdir-max-size) |
214 (progn | 203 (progn |
215 (message "Deleting file %s" (caddar filesL))) | 204 (message "Deleting file %s" (cadr (cdar filesL)))) |
216 (delete-file (caddar filesL)) | 205 (delete-file (cadr (cdar filesL))) |
217 (setq dirsize (- dirsize (cadar filesL))) | 206 (setq dirsize (- dirsize (car (cdar filesL)))) |
218 (setq filesL (cdr filesL))))) | 207 (setq filesL (cdr filesL))))) |
219 | 208 |
220 ;; Check the thumbsnail directory size and clean it if necessary. | 209 ;; Check the thumbsnail directory size and clean it if necessary. |
221 (when thumbs-thumbsdir-auto-clean | 210 (when thumbs-thumbsdir-auto-clean |
222 (thumbs-cleanup-thumbsdir)) | 211 (thumbs-cleanup-thumbsdir)) |
270 "Resize image in current buffer. | 259 "Resize image in current buffer. |
271 if INCREMENT is set, make the image bigger, else smaller. | 260 if INCREMENT is set, make the image bigger, else smaller. |
272 Or, alternatively, a SIZE may be specified." | 261 Or, alternatively, a SIZE may be specified." |
273 (interactive) | 262 (interactive) |
274 ;; cleaning of old temp file | 263 ;; cleaning of old temp file |
275 (ignore-errors | 264 (condition-case nil |
276 (apply 'delete-file | 265 (apply 'delete-file |
277 (directory-files | 266 (directory-files |
278 thumbs-temp-dir t | 267 thumbs-temp-dir t |
279 thumbs-temp-prefix))) | 268 thumbs-temp-prefix)) |
269 (error nil)) | |
280 (let ((buffer-read-only nil) | 270 (let ((buffer-read-only nil) |
281 (x (if size | 271 (x (if size |
282 size | 272 size |
283 (if increment | 273 (if increment |
284 (thumbs-increment-image-size | 274 (thumbs-increment-image-size |
307 (defun thumbs-resize-image-size-up () | 297 (defun thumbs-resize-image-size-up () |
308 "Resize image (bigger)." | 298 "Resize image (bigger)." |
309 (interactive) | 299 (interactive) |
310 (thumbs-resize-image t)) | 300 (thumbs-resize-image t)) |
311 | 301 |
312 (defun thumbs-subst-char-in-string (orig rep string) | |
313 "Replace occurrences of character ORIG with character REP in STRING. | |
314 Return the resulting (new) string. -- (defun borowed to Dave Love)" | |
315 (let ((string (copy-sequence string)) | |
316 (l (length string)) | |
317 (i 0)) | |
318 (while (< i l) | |
319 (if (= (aref string i) orig) | |
320 (aset string i rep)) | |
321 (setq i (1+ i))) | |
322 string)) | |
323 | |
324 (defun thumbs-thumbname (img) | 302 (defun thumbs-thumbname (img) |
325 "Return a thumbnail name for the image IMG." | 303 "Return a thumbnail name for the image IMG." |
326 (concat thumbs-thumbsdir "/" | 304 (concat thumbs-thumbsdir "/" |
327 (thumbs-subst-char-in-string | 305 (subst-char-in-string |
328 ?\ ?\_ | 306 ?\ ?\_ |
329 (apply | 307 (apply |
330 'concat | 308 'concat |
331 (split-string | 309 (split-string |
332 (expand-file-name img) "/"))))) | 310 (expand-file-name img) "/"))))) |
334 (defun thumbs-make-thumb (img) | 312 (defun thumbs-make-thumb (img) |
335 "Create the thumbnail for IMG." | 313 "Create the thumbnail for IMG." |
336 (let* ((fn (expand-file-name img)) | 314 (let* ((fn (expand-file-name img)) |
337 (tn (thumbs-thumbname img))) | 315 (tn (thumbs-thumbname img))) |
338 (if (or (not (file-exists-p tn)) | 316 (if (or (not (file-exists-p tn)) |
339 (not (equal (thumbs-file-size tn) thumbs-geometry))) | 317 ;; This is not the right fix, but I don't understand |
318 ;; the external program or why it produces a geometry | |
319 ;; unequal to the one requested -- rms. | |
320 ;;; (not (equal (thumbs-file-size tn) thumbs-geometry)) | |
321 ) | |
340 (thumbs-call-convert fn tn "sample" thumbs-geometry)) | 322 (thumbs-call-convert fn tn "sample" thumbs-geometry)) |
341 tn)) | 323 tn)) |
342 | 324 |
343 (defun thumbs-image-type (img) | 325 (defun thumbs-image-type (img) |
344 "Return image type from filename IMG." | 326 "Return image type from filename IMG." |
378 | 360 |
379 (defun thumbs-insert-thumb (img &optional marked) | 361 (defun thumbs-insert-thumb (img &optional marked) |
380 "Insert the thumbnail for IMG at point. | 362 "Insert the thumbnail for IMG at point. |
381 if MARKED is non-nil, the image is marked" | 363 if MARKED is non-nil, the image is marked" |
382 (thumbs-insert-image | 364 (thumbs-insert-image |
383 (thumbs-make-thumb img) 'jpeg thumbs-relief marked)) | 365 (thumbs-make-thumb img) 'jpeg thumbs-relief marked) |
366 (put-text-property (1- (point)) (point) | |
367 'thumb-image-file img)) | |
384 | 368 |
385 (defun thumbs-do-thumbs-insertion (L) | 369 (defun thumbs-do-thumbs-insertion (L) |
386 "Insert all thumbs in list L." | 370 "Insert all thumbs in list L." |
387 (setq thumbs-fileL nil) | |
388 (let ((i 0)) | 371 (let ((i 0)) |
389 (while L | 372 (dolist (img L) |
373 (thumbs-insert-thumb img | |
374 (member img thumbs-markedL)) | |
390 (when (= 0 (mod (setq i (1+ i)) thumbs-per-line)) | 375 (when (= 0 (mod (setq i (1+ i)) thumbs-per-line)) |
391 (newline)) | 376 (newline))) |
392 (setq thumbs-fileL (cons (cons (point) | 377 (unless (bobp) (newline)))) |
393 (car L)) | |
394 thumbs-fileL)) | |
395 (thumbs-insert-thumb (car L) | |
396 (member (car L) thumbs-markedL)) | |
397 (setq L (cdr L))))) | |
398 | 378 |
399 (defun thumbs-show-thumbs-list (L &optional buffer-name same-window) | 379 (defun thumbs-show-thumbs-list (L &optional buffer-name same-window) |
380 (when (not (display-images-p)) | |
381 (error "Images are not supported in this Emacs session")) | |
400 (funcall (if same-window 'switch-to-buffer 'pop-to-buffer) | 382 (funcall (if same-window 'switch-to-buffer 'pop-to-buffer) |
401 (or buffer-name "*THUMB-View*")) | 383 (or buffer-name "*THUMB-View*")) |
402 (let ((inhibit-read-only t)) | 384 (let ((inhibit-read-only t)) |
403 (erase-buffer) | 385 (erase-buffer) |
404 (thumbs-mode) | 386 (thumbs-mode) |
405 (make-variable-buffer-local 'thumbs-fileL) | |
406 (setq thumbs-fileL nil) | |
407 (thumbs-do-thumbs-insertion L) | 387 (thumbs-do-thumbs-insertion L) |
408 (goto-char (point-min)) | 388 (goto-char (point-min)) |
409 (setq thumbs-current-dir default-directory) | 389 (setq thumbs-current-dir default-directory) |
410 (make-variable-buffer-local 'thumbs-current-dir))) | 390 (make-variable-buffer-local 'thumbs-current-dir))) |
411 | 391 |
433 (thumbs-show-all-from-dir default-directory nil t)) | 413 (thumbs-show-all-from-dir default-directory nil t)) |
434 | 414 |
435 ;;;###autoload | 415 ;;;###autoload |
436 (defalias 'thumbs 'thumbs-show-all-from-dir) | 416 (defalias 'thumbs 'thumbs-show-all-from-dir) |
437 | 417 |
438 (defun thumbs-find-image (img L &optional num otherwin) | 418 (defun thumbs-find-image (img &optional num otherwin) |
439 (funcall | 419 (funcall |
440 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer) | 420 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer) |
441 (concat "*Image: " (file-name-nondirectory img) " - " | 421 (concat "*Image: " (file-name-nondirectory img) " - " |
442 (number-to-string (or num 0)) "*")) | 422 (number-to-string (or num 0)) "*")) |
443 (thumbs-view-image-mode) | 423 (thumbs-view-image-mode) |
444 (let ((inhibit-read-only t)) | 424 (let ((inhibit-read-only t)) |
447 thumbs-image-num (or num 0)) | 427 thumbs-image-num (or num 0)) |
448 (make-variable-buffer-local 'thumbs-current-image-filename) | 428 (make-variable-buffer-local 'thumbs-current-image-filename) |
449 (make-variable-buffer-local 'thumbs-current-tmp-filename) | 429 (make-variable-buffer-local 'thumbs-current-tmp-filename) |
450 (make-variable-buffer-local 'thumbs-current-image-size) | 430 (make-variable-buffer-local 'thumbs-current-image-size) |
451 (make-variable-buffer-local 'thumbs-image-num) | 431 (make-variable-buffer-local 'thumbs-image-num) |
452 (make-variable-buffer-local 'thumbs-fileL) | |
453 (setq thumbs-fileL L) | |
454 (delete-region (point-min)(point-max)) | 432 (delete-region (point-min)(point-max)) |
455 (thumbs-insert-image img (thumbs-image-type img) 0))) | 433 (thumbs-insert-image img (thumbs-image-type img) 0))) |
456 | 434 |
457 (defun thumbs-find-image-at-point (&optional img otherwin) | 435 (defun thumbs-find-image-at-point (&optional img otherwin) |
458 "Display image IMG for thumbnail at point. | 436 "Display image IMG for thumbnail at point. |
459 use another window it OTHERWIN is t." | 437 use another window it OTHERWIN is t." |
460 (interactive) | 438 (interactive) |
461 (let* ((L thumbs-fileL) | 439 (let* ((i (or img (thumbs-current-image)))) |
462 (n (point)) | 440 (thumbs-find-image i (point) otherwin))) |
463 (i (or img (cdr (assoc n L))))) | |
464 (thumbs-find-image i L n otherwin))) | |
465 | 441 |
466 (defun thumbs-find-image-at-point-other-window () | 442 (defun thumbs-find-image-at-point-other-window () |
467 "Display image for thumbnail at point in the preview buffer. | 443 "Display image for thumbnail at point in the preview buffer. |
468 Open another window." | 444 Open another window." |
469 (interactive) | 445 (interactive) |
470 (thumbs-find-image-at-point nil t)) | 446 (thumbs-find-image-at-point nil t)) |
447 | |
448 (defun thumbs-mouse-find-image (event) | |
449 "Display image for thumbnail at mouse click EVENT." | |
450 (interactive "e") | |
451 (mouse-set-point event) | |
452 (thumbs-find-image-at-point)) | |
471 | 453 |
472 (defun thumbs-call-setroot-command (img) | 454 (defun thumbs-call-setroot-command (img) |
473 "Call the setroot program for IMG." | 455 "Call the setroot program for IMG." |
474 (run-hooks 'thumbs-before-setroot-hook) | 456 (run-hooks 'thumbs-before-setroot-hook) |
475 (shell-command (replace-regexp-in-string | 457 (shell-command (replace-regexp-in-string |
479 (run-hooks 'thumbs-after-setroot-hook)) | 461 (run-hooks 'thumbs-after-setroot-hook)) |
480 | 462 |
481 (defun thumbs-set-image-at-point-to-root-window () | 463 (defun thumbs-set-image-at-point-to-root-window () |
482 "Set the image at point as the desktop wallpaper." | 464 "Set the image at point as the desktop wallpaper." |
483 (interactive) | 465 (interactive) |
484 (thumbs-call-setroot-command (cdr (assoc (point) thumbs-fileL)))) | 466 (thumbs-call-setroot-command |
467 (thumbs-current-image))) | |
485 | 468 |
486 (defun thumbs-set-root () | 469 (defun thumbs-set-root () |
487 "Set the current image as root." | 470 "Set the current image as root." |
488 (interactive) | 471 (interactive) |
489 (thumbs-call-setroot-command | 472 (thumbs-call-setroot-command |
490 (or thumbs-current-tmp-filename | 473 (or thumbs-current-tmp-filename |
491 thumbs-current-image-filename))) | 474 thumbs-current-image-filename))) |
492 | 475 |
476 (defun thumbs-file-alist () | |
477 "Make an alist of elements (POS . FILENAME) for all images in thumb buffer." | |
478 (save-excursion | |
479 (let (list) | |
480 (goto-char (point-min)) | |
481 (while (not (eobp)) | |
482 (if (thumbs-current-image) | |
483 (push (cons (point-marker) | |
484 (thumbs-current-image)) | |
485 list)) | |
486 (forward-char 1)) | |
487 list))) | |
488 | |
489 (defun thumbs-file-list () | |
490 "Make a list of file names for all images in thumb buffer." | |
491 (save-excursion | |
492 (let (list) | |
493 (goto-char (point-min)) | |
494 (while (not (eobp)) | |
495 (if (thumbs-current-image) | |
496 (push (thumbs-current-image) list)) | |
497 (forward-char 1)) | |
498 (nreverse list)))) | |
499 | |
493 (defun thumbs-delete-images () | 500 (defun thumbs-delete-images () |
494 "Delete the image at point (and it's thumbnail) (or marked files if any)." | 501 "Delete the image at point (and it's thumbnail) (or marked files if any)." |
495 (interactive) | 502 (interactive) |
496 (let ((f (or thumbs-markedL (list (cdr (assoc (point) thumbs-fileL)))))) | 503 (let ((files (or thumbs-markedL (list (thumbs-current-image))))) |
497 (if (yes-or-no-p (format "Really delete %d files? " (length f))) | 504 (if (yes-or-no-p (format "Really delete %d files? " (length files))) |
498 (progn | 505 (let ((thumbs-fileL (thumbs-file-alist)) |
499 (mapcar (lambda (x) | 506 (inhibit-read-only t)) |
500 (setq thumbs-fileL (delete (rassoc x thumbs-fileL) thumbs-fileL)) | 507 (dolist (x files) |
508 (let (failure) | |
509 (condition-case () | |
510 (progn | |
501 (delete-file x) | 511 (delete-file x) |
502 (delete-file (thumbs-thumbname x))) f) | 512 (delete-file (thumbs-thumbname x))) |
503 (thumbs-redraw-buffer))))) | 513 (file-error (setq failure t))) |
514 (unless failure | |
515 (when (rassoc x thumbs-fileL) | |
516 (goto-char (car (rassoc x thumbs-fileL))) | |
517 (delete-region (point) (1+ (point)))) | |
518 (setq thumbs-markedL | |
519 (delq x thumbs-markedL))))))))) | |
520 | |
521 (defun thumbs-rename-images (newfile) | |
522 "Rename the image at point (and it's thumbnail) (or marked files if any)." | |
523 (interactive "FRename to file or directory: ") | |
524 (let ((files (or thumbs-markedL (list (thumbs-current-image)))) | |
525 failures) | |
526 (if (and (not (file-directory-p newfile)) | |
527 thumbs-markedL) | |
528 (if (file-exists-p newfile) | |
529 (error "Renaming marked files to file name `%s'" newfile) | |
530 (make-directory newfile t))) | |
531 (if (yes-or-no-p (format "Really rename %d files? " (length files))) | |
532 (let ((thumbs-fileL (thumbs-file-alist)) | |
533 (inhibit-read-only t)) | |
534 (dolist (file files) | |
535 (let (failure) | |
536 (condition-case () | |
537 (if (file-directory-p newfile) | |
538 (rename-file file | |
539 (expand-file-name | |
540 (file-name-nondirectory file) | |
541 newfile)) | |
542 (rename-file file newfile)) | |
543 (file-error (setq failure t) | |
544 (push file failures))) | |
545 (unless failure | |
546 (when (rassoc file thumbs-fileL) | |
547 (goto-char (car (rassoc file thumbs-fileL))) | |
548 (delete-region (point) (1+ (point)))) | |
549 (setq thumbs-markedL | |
550 (delq file thumbs-markedL))))))) | |
551 (if failures | |
552 (display-warning 'file-error | |
553 (format "Rename failures for %s into %s" | |
554 failures newfile) | |
555 :error)))) | |
504 | 556 |
505 (defun thumbs-kill-buffer () | 557 (defun thumbs-kill-buffer () |
506 "Kill the current buffer." | 558 "Kill the current buffer." |
507 (interactive) | 559 (interactive) |
508 (let ((buffer (current-buffer))) | 560 (let ((buffer (current-buffer))) |
509 (ignore-errors (delete-window (selected-window))) | 561 (condition-case nil |
562 (delete-window (selected-window)) | |
563 (error nil)) | |
510 (kill-buffer buffer))) | 564 (kill-buffer buffer))) |
511 | 565 |
512 (defun thumbs-show-image-num (num) | 566 (defun thumbs-show-image-num (num) |
513 "Show the image with number NUM." | 567 "Show the image with number NUM." |
514 (let ((inhibit-read-only t)) | 568 (let ((image-buffer (get-buffer-create "*Image*"))) |
515 (delete-region (point-min)(point-max)) | 569 (let ((i (thumbs-current-image))) |
516 (let ((i (cdr (assoc num thumbs-fileL)))) | 570 (with-current-buffer image-buffer |
517 (thumbs-insert-image i (thumbs-image-type i) 0) | 571 (thumbs-insert-image i (thumbs-image-type i) 0)) |
518 (sleep-for 2) | |
519 (rename-buffer (concat "*Image: " | |
520 (file-name-nondirectory i) | |
521 " - " | |
522 (number-to-string num) "*")) | |
523 (setq thumbs-image-num num | 572 (setq thumbs-image-num num |
524 thumbs-current-image-filename i)))) | 573 thumbs-current-image-filename i)))) |
525 | 574 |
526 (defun thumbs-next-image () | 575 (defun thumbs-next-image () |
527 "Show next image." | 576 "Show next image." |
528 (interactive) | 577 (interactive) |
529 (let* ((i (1+ thumbs-image-num)) | 578 (let* ((i (1+ thumbs-image-num)) |
530 (l (caar thumbs-fileL)) | 579 (list (thumbs-file-alist)) |
531 (num | 580 (l (caar list))) |
532 (cond ((assoc i thumbs-fileL) i) | 581 (while (and (/= i thumbs-image-num) (not (assoc i list))) |
533 ((>= i l) 1) | 582 (setq i (if (>= i l) 1 (1+ i)))) |
534 (t (1+ i))))) | 583 (thumbs-show-image-num i))) |
535 (thumbs-show-image-num num))) | |
536 | 584 |
537 (defun thumbs-previous-image () | 585 (defun thumbs-previous-image () |
538 "Show the previous image." | 586 "Show the previous image." |
539 (interactive) | 587 (interactive) |
540 (let* ((i (- thumbs-image-num 1)) | 588 (let* ((i (- thumbs-image-num 1)) |
541 (l (caar thumbs-fileL)) | 589 (list (thumbs-file-alist)) |
542 (num | 590 (l (caar list))) |
543 (cond ((assoc i thumbs-fileL) i) | 591 (while (and (/= i thumbs-image-num) (not (assoc i list))) |
544 ((<= i 1) l) | 592 (setq i (if (<= i 1) l (1- i)))) |
545 (t (- i 1))))) | 593 (thumbs-show-image-num i))) |
546 (thumbs-show-image-num num))) | |
547 | 594 |
548 (defun thumbs-redraw-buffer () | 595 (defun thumbs-redraw-buffer () |
549 "Redraw the current thumbs buffer." | 596 "Redraw the current thumbs buffer." |
550 (let ((p (point)) | 597 (let ((p (point)) |
551 (inhibit-read-only t)) | 598 (inhibit-read-only t) |
552 (delete-region (point-min)(point-max)) | 599 (files (thumbs-file-list))) |
553 (thumbs-do-thumbs-insertion (reverse (mapcar 'cdr thumbs-fileL))) | 600 (erase-buffer) |
554 (goto-char (1+ p)))) | 601 (thumbs-do-thumbs-insertion files) |
602 (goto-char p))) | |
555 | 603 |
556 (defun thumbs-mark () | 604 (defun thumbs-mark () |
557 "Mark the image at point." | 605 "Mark the image at point." |
558 (interactive) | 606 (interactive) |
559 (setq thumbs-markedL (cons (cdr (assoc (point) thumbs-fileL)) thumbs-markedL)) | 607 (let ((elt (thumbs-current-image))) |
560 (let ((inhibit-read-only t)) | 608 (unless elt |
561 (delete-char 1) | 609 (error "No image here")) |
562 (thumbs-insert-thumb (cdr (assoc (point) thumbs-fileL)) t)) | 610 (push elt thumbs-markedL) |
563 (when (eolp)(forward-char))) | 611 (let ((inhibit-read-only t)) |
612 (delete-char 1) | |
613 (thumbs-insert-thumb elt t))) | |
614 (when (eolp) (forward-char))) | |
615 | |
616 (defun thumbs-unmark () | |
617 "Unmark the image at point." | |
618 (interactive) | |
619 (let ((elt (thumbs-current-image))) | |
620 (unless elt | |
621 (error "No image here")) | |
622 (setq thumbs-markedL (delete elt thumbs-markedL)) | |
623 (let ((inhibit-read-only t)) | |
624 (delete-char 1) | |
625 (thumbs-insert-thumb elt nil))) | |
626 (when (eolp) (forward-char))) | |
564 | 627 |
565 ;; Image modification routines | 628 ;; Image modification routines |
566 | 629 |
567 (defun thumbs-modify-image (action &optional arg) | 630 (defun thumbs-modify-image (action &optional arg) |
568 "Call convert to do ACTION on image with argument ARG. | 631 "Call convert to do ACTION on image with argument ARG. |
585 (setq thumbs-current-tmp-filename tmp))) | 648 (setq thumbs-current-tmp-filename tmp))) |
586 | 649 |
587 (defun thumbs-emboss-image (emboss) | 650 (defun thumbs-emboss-image (emboss) |
588 "Emboss the image with value EMBOSS." | 651 "Emboss the image with value EMBOSS." |
589 (interactive "nEmboss value: ") | 652 (interactive "nEmboss value: ") |
590 (if (or (< emboss 3) (> emboss 31) (zerop (logand emboss 1))) | 653 (if (or (< emboss 3) (> emboss 31) (zerop (% emboss 2))) |
591 (error "Arg must be a odd number between 3 and 31")) | 654 (error "Arg must be an odd number between 3 and 31")) |
592 (thumbs-modify-image "emboss" (number-to-string emboss))) | 655 (thumbs-modify-image "emboss" (number-to-string emboss))) |
593 | 656 |
594 (defun thumbs-monochrome-image () | 657 (defun thumbs-monochrome-image () |
595 "Turn the image to monochrome." | 658 "Turn the image to monochrome." |
596 (interactive) | 659 (interactive) |
609 (defun thumbs-rotate-right () | 672 (defun thumbs-rotate-right () |
610 "Rotate the image 90 degrees clockwise." | 673 "Rotate the image 90 degrees clockwise." |
611 (interactive) | 674 (interactive) |
612 (thumbs-modify-image "rotate" "90")) | 675 (thumbs-modify-image "rotate" "90")) |
613 | 676 |
677 (defun thumbs-current-image () | |
678 "Return the name of the image file name at point." | |
679 (get-text-property (point) 'thumb-image-file)) | |
680 | |
614 (defun thumbs-forward-char () | 681 (defun thumbs-forward-char () |
615 "Move forward one image." | 682 "Move forward one image." |
616 (interactive) | 683 (interactive) |
617 (forward-char) | 684 (forward-char) |
618 (when (eolp)(forward-char)) | 685 (while (and (not (eobp)) (not (thumbs-current-image))) |
686 (forward-char)) | |
619 (thumbs-show-name)) | 687 (thumbs-show-name)) |
620 | 688 |
621 (defun thumbs-backward-char () | 689 (defun thumbs-backward-char () |
622 "Move backward one image." | 690 "Move backward one image." |
623 (interactive) | 691 (interactive) |
624 (forward-char -1) | 692 (forward-char -1) |
693 (while (and (not (bobp)) (not (thumbs-current-image))) | |
694 (forward-char -1)) | |
625 (thumbs-show-name)) | 695 (thumbs-show-name)) |
626 | 696 |
627 (defun thumbs-forward-line () | 697 (defun thumbs-forward-line () |
628 "Move down one line." | 698 "Move down one line." |
629 (interactive) | 699 (interactive) |
637 (thumbs-show-name)) | 707 (thumbs-show-name)) |
638 | 708 |
639 (defun thumbs-show-name () | 709 (defun thumbs-show-name () |
640 "Show the name of the current file." | 710 "Show the name of the current file." |
641 (interactive) | 711 (interactive) |
642 (let ((f (cdr (assoc (point) thumbs-fileL)))) | 712 (let ((f (thumbs-current-image))) |
643 (message "%s [%s]" f (thumbs-file-size f)))) | 713 (and f (message "%s [%s]" f (thumbs-file-size f))))) |
644 | 714 |
645 (defun thumbs-save-current-image () | 715 (defun thumbs-save-current-image () |
646 "Save the current image." | 716 "Save the current image." |
647 (interactive) | 717 (interactive) |
648 (let ((f (or thumbs-current-tmp-filename | 718 (let ((f (or thumbs-current-tmp-filename |
649 thumbs-current-image-filename)) | 719 thumbs-current-image-filename)) |
650 (sa (read-from-minibuffer "save file as: " | 720 (sa (read-from-minibuffer "Save image file as: " |
651 thumbs-current-image-filename))) | 721 thumbs-current-image-filename))) |
652 (copy-file f sa))) | 722 (copy-file f sa))) |
653 | 723 |
654 (defun thumbs-dired () | 724 (defun thumbs-dired () |
655 "Use `dired' on the current thumbs directory." | 725 "Use `dired' on the current thumbs directory." |
659 ;; thumbs-mode | 729 ;; thumbs-mode |
660 | 730 |
661 (defvar thumbs-mode-map | 731 (defvar thumbs-mode-map |
662 (let ((map (make-sparse-keymap))) | 732 (let ((map (make-sparse-keymap))) |
663 (define-key map [return] 'thumbs-find-image-at-point) | 733 (define-key map [return] 'thumbs-find-image-at-point) |
734 (define-key map [mouse-2] 'thumbs-mouse-find-image) | |
664 (define-key map [(meta return)] 'thumbs-find-image-at-point-other-window) | 735 (define-key map [(meta return)] 'thumbs-find-image-at-point-other-window) |
665 (define-key map [(control return)] 'thumbs-set-image-at-point-to-root-window) | 736 (define-key map [(control return)] 'thumbs-set-image-at-point-to-root-window) |
666 (define-key map [delete] 'thumbs-delete-images) | 737 (define-key map [delete] 'thumbs-delete-images) |
667 (define-key map [right] 'thumbs-forward-char) | 738 (define-key map [right] 'thumbs-forward-char) |
668 (define-key map [left] 'thumbs-backward-char) | 739 (define-key map [left] 'thumbs-backward-char) |
669 (define-key map [up] 'thumbs-backward-line) | 740 (define-key map [up] 'thumbs-backward-line) |
670 (define-key map [down] 'thumbs-forward-line) | 741 (define-key map [down] 'thumbs-forward-line) |
671 (define-key map "d" 'thumbs-dired) | 742 (define-key map "d" 'thumbs-dired) |
672 (define-key map "m" 'thumbs-mark) | 743 (define-key map "m" 'thumbs-mark) |
744 (define-key map "u" 'thumbs-unmark) | |
745 (define-key map "R" 'thumbs-rename-images) | |
746 (define-key map "x" 'thumbs-delete-images) | |
673 (define-key map "s" 'thumbs-show-name) | 747 (define-key map "s" 'thumbs-show-name) |
674 (define-key map "q" 'thumbs-kill-buffer) | 748 (define-key map "q" 'thumbs-kill-buffer) |
675 map) | 749 map) |
676 "Keymap for `thumbs-mode'.") | 750 "Keymap for `thumbs-mode'.") |
677 | 751 |
752 (put 'thumbs-mode 'mode-class 'special) | |
678 (define-derived-mode thumbs-mode | 753 (define-derived-mode thumbs-mode |
679 fundamental-mode "thumbs" | 754 fundamental-mode "thumbs" |
680 "Preview images in a thumbnails buffer" | 755 "Preview images in a thumbnails buffer" |
681 (make-variable-buffer-local 'thumbs-markedL) | 756 (make-variable-buffer-local 'thumbs-markedL) |
757 (setq buffer-read-only t) | |
682 (setq thumbs-markedL nil)) | 758 (setq thumbs-markedL nil)) |
683 | 759 |
684 (defvar thumbs-view-image-mode-map | 760 (defvar thumbs-view-image-mode-map |
685 (let ((map (make-sparse-keymap))) | 761 (let ((map (make-sparse-keymap))) |
686 (define-key map [prior] 'thumbs-previous-image) | 762 (define-key map [prior] 'thumbs-previous-image) |
696 (define-key map "w" 'thunbs-set-root) | 772 (define-key map "w" 'thunbs-set-root) |
697 map) | 773 map) |
698 "Keymap for `thumbs-view-image-mode'.") | 774 "Keymap for `thumbs-view-image-mode'.") |
699 | 775 |
700 ;; thumbs-view-image-mode | 776 ;; thumbs-view-image-mode |
777 (put 'thumbs-view-image-mode 'mode-class 'special) | |
701 (define-derived-mode thumbs-view-image-mode | 778 (define-derived-mode thumbs-view-image-mode |
702 fundamental-mode "image-view-mode") | 779 fundamental-mode "image-view-mode") |
703 | 780 |
704 ;;;###autoload | 781 ;;;###autoload |
705 (defun thumbs-dired-setroot () | 782 (defun thumbs-dired-setroot () |