diff options
| author | Mathias Dahl | 2006-02-06 21:08:34 +0000 |
|---|---|---|
| committer | Mathias Dahl | 2006-02-06 21:08:34 +0000 |
| commit | 556aacbbc25019ec250f3a035c0574a3919ef8e3 (patch) | |
| tree | 217a6a89bc2c017095a47e4854698d3fb7ff0960 | |
| parent | 215e2336cf9d4665f97dc434a4187130e1e8d3d5 (diff) | |
| download | emacs-556aacbbc25019ec250f3a035c0574a3919ef8e3.tar.gz emacs-556aacbbc25019ec250f3a035c0574a3919ef8e3.zip | |
Some user interface changes: added command `tumme', etc.
| -rw-r--r-- | lisp/tumme.el | 185 |
1 files changed, 146 insertions, 39 deletions
diff --git a/lisp/tumme.el b/lisp/tumme.el index ecdd37f1eb6..34a768f398d 100644 --- a/lisp/tumme.el +++ b/lisp/tumme.el | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | ;; | 2 | ;; |
| 3 | ;; Copyright (C) 2005, 2006 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2005, 2006 Free Software Foundation, Inc. |
| 4 | ;; | 4 | ;; |
| 5 | ;; Version: 0.4.10 | 5 | ;; Version: 0.4.11 |
| 6 | ;; Keywords: multimedia | 6 | ;; Keywords: multimedia |
| 7 | ;; Author: Mathias Dahl <mathias.rem0veth1s.dahl@gmail.com> | 7 | ;; Author: Mathias Dahl <mathias.rem0veth1s.dahl@gmail.com> |
| 8 | 8 | ||
| @@ -128,11 +128,6 @@ | |||
| 128 | ;; LIMITATIONS | 128 | ;; LIMITATIONS |
| 129 | ;; =========== | 129 | ;; =========== |
| 130 | ;; | 130 | ;; |
| 131 | ;; * In order to work well, `tumme' require that all your images have | ||
| 132 | ;; unique names. The reason is the way thumbnail file names are | ||
| 133 | ;; generated. I will probably not fix this problem as my images all | ||
| 134 | ;; have unique names. | ||
| 135 | ;; | ||
| 136 | ;; * Supports all image formats that Emacs and convert supports, but | 131 | ;; * Supports all image formats that Emacs and convert supports, but |
| 137 | ;; the thumbnails are hard-coded to JPEG format. | 132 | ;; the thumbnails are hard-coded to JPEG format. |
| 138 | ;; | 133 | ;; |
| @@ -489,6 +484,29 @@ | |||
| 489 | ;; * To be included in Emacs 22. | 484 | ;; * To be included in Emacs 22. |
| 490 | ;; | 485 | ;; |
| 491 | ;; | 486 | ;; |
| 487 | ;; Version 0.4.11, 2006-MM-DD | ||
| 488 | ;; | ||
| 489 | ;; * Changed `tumme-display-thumbs' so that it calls `display-buffer' | ||
| 490 | ;; after generating the thumbnails and changed | ||
| 491 | ;; `tumme-display-thumbnail-original-image' to display the image | ||
| 492 | ;; buffer. These small changes should make it easier for a user to | ||
| 493 | ;; start using tumme. | ||
| 494 | ;; | ||
| 495 | ;; * Added `tumme-show-all-from-dir' to mimic thumbs.el's easy-to-use | ||
| 496 | ;; `thumbs' command. A new customize option, | ||
| 497 | ;; `tumme-show-all-from-dir-max-files' was added too. | ||
| 498 | ;; | ||
| 499 | ;; * Renamed `tumme-dired' to `tumme-dired-with-window-configuration' | ||
| 500 | ;; and added code to save the window configuration before messing it | ||
| 501 | ;; up. The saved window configuration can be restored using the new | ||
| 502 | ;; command `tumme-restore-window-configuration'. | ||
| 503 | ;; | ||
| 504 | ;; * Added `tumme-get-thumbnail-image', created by Chong Yidong. His | ||
| 505 | ;; own comments: ..., that just takes the original filename and | ||
| 506 | ;; returns a thumbnail image descriptor. Then third-party libraries | ||
| 507 | ;; won't have to muck around with tumme.el's internal functions like | ||
| 508 | ;; `thumme-thumb-name', `tumme-create-thumb', etc. His code to get | ||
| 509 | ;; speedbar display tumme thumbnails, might be integrated soon. | ||
| 492 | ;; | 510 | ;; |
| 493 | ;; TODO | 511 | ;; TODO |
| 494 | ;; ==== | 512 | ;; ==== |
| @@ -821,6 +839,12 @@ Used by `tumme-copy-with-exif-file-name'." | |||
| 821 | :type 'string | 839 | :type 'string |
| 822 | :group 'tumme) | 840 | :group 'tumme) |
| 823 | 841 | ||
| 842 | (defcustom tumme-show-all-from-dir-max-files 50 | ||
| 843 | "*Maximum number of files to show using`tumme-show-all-from-dir'. | ||
| 844 | before warning the user." | ||
| 845 | :type 'integer | ||
| 846 | :group 'tumme) | ||
| 847 | |||
| 824 | (defun tumme-insert-image (file type relief margin) | 848 | (defun tumme-insert-image (file type relief margin) |
| 825 | "Insert image FILE of image TYPE, using RELIEF and MARGIN, at point." | 849 | "Insert image FILE of image TYPE, using RELIEF and MARGIN, at point." |
| 826 | 850 | ||
| @@ -830,6 +854,18 @@ Used by `tumme-copy-with-exif-file-name'." | |||
| 830 | :margin ,margin))) | 854 | :margin ,margin))) |
| 831 | (insert-image i))) | 855 | (insert-image i))) |
| 832 | 856 | ||
| 857 | (defun tumme-get-thumbnail-image (file) | ||
| 858 | "Return the image descriptor for a thumbnail of image file FILE." | ||
| 859 | (unless (string-match (image-file-name-regexp) file) | ||
| 860 | (error "%s is not a valid image file.")) | ||
| 861 | (let ((thumb-file (tumme-thumb-name file))) | ||
| 862 | (unless (and (file-exists-p thumb-file) | ||
| 863 | (<= (float-time (nth 5 (file-attributes file))) | ||
| 864 | (float-time (nth 5 (file-attributes thumb-file))))) | ||
| 865 | (tumme-create-thumb file thumb-file)) | ||
| 866 | (list 'image :type 'jpeg :file thumb-file | ||
| 867 | :relief tumme-thumb-relief :margin tumme-thumb-margin))) | ||
| 868 | |||
| 833 | (defun tumme-insert-thumbnail (file original-file-name | 869 | (defun tumme-insert-thumbnail (file original-file-name |
| 834 | associated-dired-buffer) | 870 | associated-dired-buffer) |
| 835 | "Insert thumbnail image FILE. | 871 | "Insert thumbnail image FILE. |
| @@ -969,8 +1005,11 @@ add a subdirectory." | |||
| 969 | (tumme-display-image-mode))) | 1005 | (tumme-display-image-mode))) |
| 970 | buf)) | 1006 | buf)) |
| 971 | 1007 | ||
| 1008 | (defvar tumme-saved-window-configuration nil | ||
| 1009 | "Saved window configuration.") | ||
| 1010 | |||
| 972 | ;;;###autoload | 1011 | ;;;###autoload |
| 973 | (defun tumme-dired (dir &optional arg) | 1012 | (defun tumme-dired-with-window-configuration (dir &optional arg) |
| 974 | "Open directory DIR and create a default window configuration. | 1013 | "Open directory DIR and create a default window configuration. |
| 975 | 1014 | ||
| 976 | Convenience command that: | 1015 | Convenience command that: |
| @@ -979,11 +1018,21 @@ Convenience command that: | |||
| 979 | - Splits windows in most useful (?) way | 1018 | - Splits windows in most useful (?) way |
| 980 | - Set `truncate-lines' to t | 1019 | - Set `truncate-lines' to t |
| 981 | 1020 | ||
| 982 | If called with prefix argument ARG, skip splitting of windows." | 1021 | After the command has finished, you would typically mark some |
| 1022 | image files in dired and call `tumme-display-thumbs' (by default | ||
| 1023 | bound to C-t d). | ||
| 1024 | |||
| 1025 | If called with prefix argument ARG, skip splitting of windows. | ||
| 1026 | |||
| 1027 | The current window configuration is saved and can be restored by | ||
| 1028 | calling `tumme-restore-window-configuration'." | ||
| 983 | (interactive "DDirectory: \nP") | 1029 | (interactive "DDirectory: \nP") |
| 984 | (let ((buf (tumme-create-thumbnail-buffer)) | 1030 | (let ((buf (tumme-create-thumbnail-buffer)) |
| 985 | (buf2 (tumme-create-display-image-buffer))) | 1031 | (buf2 (tumme-create-display-image-buffer))) |
| 1032 | (setq tumme-saved-window-configuration | ||
| 1033 | (current-window-configuration)) | ||
| 986 | (dired dir) | 1034 | (dired dir) |
| 1035 | (delete-other-windows) | ||
| 987 | (when (not arg) | 1036 | (when (not arg) |
| 988 | (split-window-horizontally) | 1037 | (split-window-horizontally) |
| 989 | (setq truncate-lines t) | 1038 | (setq truncate-lines t) |
| @@ -995,6 +1044,16 @@ If called with prefix argument ARG, skip splitting of windows." | |||
| 995 | (switch-to-buffer buf2) | 1044 | (switch-to-buffer buf2) |
| 996 | (other-window -2))))) | 1045 | (other-window -2))))) |
| 997 | 1046 | ||
| 1047 | (defun tumme-restore-window-configuration () | ||
| 1048 | "Restore window configuration. | ||
| 1049 | Restore any changes to the window configuration made by calling | ||
| 1050 | `tumme-dired-with-window-configuration'" | ||
| 1051 | (interactive) | ||
| 1052 | (if tumme-saved-window-configuration | ||
| 1053 | (set-window-configuration tumme-saved-window-configuration) | ||
| 1054 | (message "No saved window configuration"))) | ||
| 1055 | |||
| 1056 | ;;;###autoload | ||
| 998 | (defun tumme-display-thumbs (&optional arg append) | 1057 | (defun tumme-display-thumbs (&optional arg append) |
| 999 | "Display thumbnails of all marked files, in `tumme-thumbnail-buffer'. | 1058 | "Display thumbnails of all marked files, in `tumme-thumbnail-buffer'. |
| 1000 | If a thumbnail image does not exist for a file, it is created on the | 1059 | If a thumbnail image does not exist for a file, it is created on the |
| @@ -1038,7 +1097,31 @@ instead of erasing it first." | |||
| 1038 | ((eq 'none tumme-line-up-method) | 1097 | ((eq 'none tumme-line-up-method) |
| 1039 | nil) | 1098 | nil) |
| 1040 | (t | 1099 | (t |
| 1041 | (tumme-line-up-dynamic)))))) | 1100 | (tumme-line-up-dynamic)))) |
| 1101 | (pop-to-buffer tumme-thumbnail-buffer))) | ||
| 1102 | |||
| 1103 | (defun tumme-show-all-from-dir (dir) | ||
| 1104 | "Make a preview buffer for all images in DIR and display it. | ||
| 1105 | If the number of files in DIR matching `image-file-name-regexp' | ||
| 1106 | exceeds `tumme-show-all-from-dir-max-files', a warning will be | ||
| 1107 | displayed." | ||
| 1108 | (interactive "DDir: ") | ||
| 1109 | (dired dir) | ||
| 1110 | (dired-mark-files-regexp (image-file-name-regexp)) | ||
| 1111 | (let ((files (dired-get-marked-files))) | ||
| 1112 | (if (or (<= (length files) tumme-show-all-from-dir-max-files) | ||
| 1113 | (and (> (length files) tumme-show-all-from-dir-max-files) | ||
| 1114 | (y-or-n-p | ||
| 1115 | (format | ||
| 1116 | "Directory contains more than %d image files. Proceed? " | ||
| 1117 | tumme-show-all-from-dir-max-files)))) | ||
| 1118 | (progn | ||
| 1119 | (tumme-display-thumbs) | ||
| 1120 | (pop-to-buffer tumme-thumbnail-buffer)) | ||
| 1121 | (message "Cancelled.")))) | ||
| 1122 | |||
| 1123 | ;;;###autoload | ||
| 1124 | (defalias 'tumme 'tumme-show-all-from-dir) | ||
| 1042 | 1125 | ||
| 1043 | (defun tumme-write-tag (files tag) | 1126 | (defun tumme-write-tag (files tag) |
| 1044 | "For all FILES, writes TAG to the image database." | 1127 | "For all FILES, writes TAG to the image database." |
| @@ -1984,7 +2067,16 @@ With prefix argument ARG, display image in its original size." | |||
| 1984 | (message "No thumbnail at point") | 2067 | (message "No thumbnail at point") |
| 1985 | (if (not file) | 2068 | (if (not file) |
| 1986 | (message "No original file name found") | 2069 | (message "No original file name found") |
| 1987 | (tumme-display-image file arg)))))) | 2070 | (tumme-display-image file arg) |
| 2071 | (display-buffer tumme-display-image-buffer)))))) | ||
| 2072 | |||
| 2073 | (defun obsolete-tumme-display-thumbnail-original-image-and-buffer (&optional arg) | ||
| 2074 | "Call `tumme-display-thumbnail-original-image' and display display buffer. | ||
| 2075 | See command `tumme-display-thumbnail-original-image' for | ||
| 2076 | details." | ||
| 2077 | (interactive "P") | ||
| 2078 | (tumme-display-thumbnail-original-image arg) | ||
| 2079 | (display-buffer tumme-display-image-buffer)) | ||
| 1988 | 2080 | ||
| 1989 | (defun tumme-display-dired-image (&optional arg) | 2081 | (defun tumme-display-dired-image (&optional arg) |
| 1990 | "Display current image file. | 2082 | "Display current image file. |
| @@ -2555,7 +2647,7 @@ when using per-directory thumbnail file storage")) | |||
| 2555 | ;; Insert thumbnail with link to full image | 2647 | ;; Insert thumbnail with link to full image |
| 2556 | (insert | 2648 | (insert |
| 2557 | (format "<a href=\"%s/%s\"><img src=\"%s/%s\"%s></a>\n" | 2649 | (format "<a href=\"%s/%s\"><img src=\"%s/%s\"%s></a>\n" |
| 2558 | tumme-gallery-image-root-url file | 2650 | tumme-gallery-image-root-url (file-name-nondirectory file) |
| 2559 | tumme-gallery-thumb-image-root-url | 2651 | tumme-gallery-thumb-image-root-url |
| 2560 | (file-name-nondirectory (tumme-thumb-name file)) file)) | 2652 | (file-name-nondirectory (tumme-thumb-name file)) file)) |
| 2561 | ;; Insert comment, if any | 2653 | ;; Insert comment, if any |
| @@ -2597,38 +2689,53 @@ when using per-directory thumbnail file storage")) | |||
| 2597 | (error nil)) | 2689 | (error nil)) |
| 2598 | (kill-buffer buffer))) | 2690 | (kill-buffer buffer))) |
| 2599 | 2691 | ||
| 2600 | |||
| 2601 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2692 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2602 | ;;;;;;;;; TEST-SECTION ;;;;;;;;;;; | 2693 | ;;;;;;;;; TEST-SECTION ;;;;;;;;;;; |
| 2603 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2694 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2604 | 2695 | ||
| 2605 | 2696 | ;; (defvar tumme-dir-max-size 12300000) | |
| 2606 | (defvar tumme-dir-max-size 12300000) | 2697 | |
| 2607 | 2698 | ;; (defun tumme-test-clean-old-files () | |
| 2608 | (defun tumme-test () | 2699 | ;; "Clean `tumme-dir' from old thumbnail files. |
| 2609 | "Clean `tumme-dir' from old thumbnail files. | 2700 | ;; \"Oldness\" measured using last access time. If the total size of all |
| 2610 | \"Oldness\" measured using last access time. If the total size of all | 2701 | ;; thumbnail files in `tumme-dir' is larger than 'tumme-dir-max-size', |
| 2611 | thumbnail files in `tumme-dir' is larger than 'tumme-dir-max-size', | 2702 | ;; old files are deleted until the max size is reached." |
| 2612 | old files are deleted until the max size is reached." | 2703 | ;; (let* ((files |
| 2613 | (let* ((files | 2704 | ;; (sort |
| 2614 | (sort | 2705 | ;; (mapcar |
| 2615 | (mapcar | 2706 | ;; (lambda (f) |
| 2616 | (lambda (f) | 2707 | ;; (let ((fattribs (file-attributes f))) |
| 2617 | (let ((fattribs (file-attributes f))) | 2708 | ;; ;; Get last access time and file size |
| 2618 | ;; Get last access time and file size | 2709 | ;; `(,(nth 4 fattribs) ,(nth 7 fattribs) ,f))) |
| 2619 | `(,(nth 4 fattribs) ,(nth 7 fattribs) ,f))) | 2710 | ;; (directory-files tumme-dir t ".+\.thumb\..+$")) |
| 2620 | (directory-files tumme-dir t ".+\.thumb\..+$")) | 2711 | ;; ;; Sort function. Compare time between two files. |
| 2621 | ;; Sort function. Compare time between two files. | 2712 | ;; '(lambda (l1 l2) |
| 2622 | '(lambda (l1 l2) | 2713 | ;; (time-less-p (car l1) (car l2))))) |
| 2623 | (time-less-p (car l1) (car l2))))) | 2714 | ;; (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files)))) |
| 2624 | (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files)))) | 2715 | ;; (while (> dirsize tumme-dir-max-size) |
| 2625 | (while (> dirsize tumme-dir-max-size) | 2716 | ;; (y-or-n-p |
| 2626 | (y-or-n-p | 2717 | ;; (format "Size of thumbnail directory: %d, delete old file %s? " |
| 2627 | (format "Size of thumbnail directory: %d, delete old file %s? " | 2718 | ;; dirsize (cadr (cdar files)))) |
| 2628 | dirsize (cadr (cdar files)))) | 2719 | ;; (delete-file (cadr (cdar files))) |
| 2629 | (delete-file (cadr (cdar files))) | 2720 | ;; (setq dirsize (- dirsize (car (cdar files)))) |
| 2630 | (setq dirsize (- dirsize (car (cdar files)))) | 2721 | ;; (setq files (cdr files))))) |
| 2631 | (setq files (cdr files))))) | 2722 | |
| 2723 | ;;;;;;;;;;;;;;;;;;;;;;, | ||
| 2724 | |||
| 2725 | ;; (defun dired-speedbar-buttons (dired-buffer) | ||
| 2726 | ;; (when (and (boundp 'tumme-use-speedbar) | ||
| 2727 | ;; tumme-use-speedbar) | ||
| 2728 | ;; (let ((filename (with-current-buffer dired-buffer | ||
| 2729 | ;; (dired-get-filename)))) | ||
| 2730 | ;; (when (and (not (string-equal filename (buffer-string))) | ||
| 2731 | ;; (string-match (image-file-name-regexp) filename)) | ||
| 2732 | ;; (erase-buffer) | ||
| 2733 | ;; (insert (propertize | ||
| 2734 | ;; filename | ||
| 2735 | ;; 'display | ||
| 2736 | ;; (tumme-get-thumbnail-image filename))))))) | ||
| 2737 | |||
| 2738 | ;; (setq tumme-use-speedbar t) | ||
| 2632 | 2739 | ||
| 2633 | (provide 'tumme) | 2740 | (provide 'tumme) |
| 2634 | 2741 | ||