Mercurial > emacs
diff lisp/tumme.el @ 90294:c5406394f567
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-13
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 43-57)
- Update from CVS
- Merge from erc--emacs--0
- Make constrain-to-field notice overlays
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 18-21)
- Update from CVS
- Merge from emacs--devo--0
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 08 Feb 2006 04:26:44 +0000 |
parents | 23eaa0d773ea |
children | 9c1ca2e3695c |
line wrap: on
line diff
--- a/lisp/tumme.el Sun Feb 05 02:46:54 2006 +0000 +++ b/lisp/tumme.el Wed Feb 08 04:26:44 2006 +0000 @@ -1,8 +1,8 @@ ;;; tumme.el --- use dired to browse and manipulate your images ;; -;; Copyright (C) 2005 Free Software Foundation, Inc. +;; Copyright (C) 2005, 2006 Free Software Foundation, Inc. ;; -;; Version: 0.4.10 +;; Version: 0.4.11 ;; Keywords: multimedia ;; Author: Mathias Dahl <mathias.rem0veth1s.dahl@gmail.com> @@ -128,11 +128,6 @@ ;; LIMITATIONS ;; =========== ;; -;; * In order to work well, `tumme' require that all your images have -;; unique names. The reason is the way thumbnail file names are -;; generated. I will probably not fix this problem as my images all -;; have unique names. -;; ;; * Supports all image formats that Emacs and convert supports, but ;; the thumbnails are hard-coded to JPEG format. ;; @@ -489,6 +484,29 @@ ;; * To be included in Emacs 22. ;; ;; +;; Version 0.4.11, 2006-MM-DD +;; +;; * Changed `tumme-display-thumbs' so that it calls `display-buffer' +;; after generating the thumbnails and changed +;; `tumme-display-thumbnail-original-image' to display the image +;; buffer. These small changes should make it easier for a user to +;; start using tumme. +;; +;; * Added `tumme-show-all-from-dir' to mimic thumbs.el's easy-to-use +;; `thumbs' command. A new customize option, +;; `tumme-show-all-from-dir-max-files' was added too. +;; +;; * Renamed `tumme-dired' to `tumme-dired-with-window-configuration' +;; and added code to save the window configuration before messing it +;; up. The saved window configuration can be restored using the new +;; command `tumme-restore-window-configuration'. +;; +;; * Added `tumme-get-thumbnail-image', created by Chong Yidong. His +;; own comments: ..., that just takes the original filename and +;; returns a thumbnail image descriptor. Then third-party libraries +;; won't have to muck around with tumme.el's internal functions like +;; `thumme-thumb-name', `tumme-create-thumb', etc. His code to get +;; speedbar display tumme thumbnails, might be integrated soon. ;; ;; TODO ;; ==== @@ -667,7 +685,7 @@ number of (positive) degrees to rotate the image, normally 90 or 270 \(for 90 degrees right and left), %o which is replaced by the original image file name and %t which is replaced by -`tumme-temp-image-file'" +`tumme-temp-image-file'." :type 'string :group 'tumme) @@ -760,7 +778,7 @@ :group 'tumme) (defcustom tumme-display-window-width-correction 1 - "*Number to be used to correct image display window height. + "*Number to be used to correct image display window width. Change if the default (1) does not work (i.e. if the image does not completely fit)." :type 'integer @@ -768,7 +786,7 @@ (defcustom tumme-display-window-height-correction 0 "*Number to be used to correct image display window height. -Use if the default (0) does not work (i.e. if the image does not +Change if the default (0) does not work (i.e. if the image does not completely fit)." :type 'integer :group 'tumme) @@ -801,7 +819,7 @@ :group 'tumme) (defcustom tumme-display-properties-format "%b: %f (%t): %c" - "* Display format for thumbnail properties. + "*Display format for thumbnail properties. %b is replaced with associated dired buffer name, %f with file name \(without path) of original image file, %t with the list of tags and %c with the comment." @@ -821,6 +839,12 @@ :type 'string :group 'tumme) +(defcustom tumme-show-all-from-dir-max-files 50 + "*Maximum number of files to show using`tumme-show-all-from-dir'. + before warning the user." + :type 'integer + :group 'tumme) + (defun tumme-insert-image (file type relief margin) "Insert image FILE of image TYPE, using RELIEF and MARGIN, at point." @@ -830,6 +854,18 @@ :margin ,margin))) (insert-image i))) +(defun tumme-get-thumbnail-image (file) + "Return the image descriptor for a thumbnail of image file FILE." + (unless (string-match (image-file-name-regexp) file) + (error "%s is not a valid image file" file)) + (let ((thumb-file (tumme-thumb-name file))) + (unless (and (file-exists-p thumb-file) + (<= (float-time (nth 5 (file-attributes file))) + (float-time (nth 5 (file-attributes thumb-file))))) + (tumme-create-thumb file thumb-file)) + (list 'image :type 'jpeg :file thumb-file + :relief tumme-thumb-relief :margin tumme-thumb-margin))) + (defun tumme-insert-thumbnail (file original-file-name associated-dired-buffer) "Insert thumbnail image FILE. @@ -969,8 +1005,11 @@ (tumme-display-image-mode))) buf)) +(defvar tumme-saved-window-configuration nil + "Saved window configuration.") + ;;;###autoload -(defun tumme-dired (dir &optional arg) +(defun tumme-dired-with-window-configuration (dir &optional arg) "Open directory DIR and create a default window configuration. Convenience command that: @@ -979,11 +1018,21 @@ - Splits windows in most useful (?) way - Set `truncate-lines' to t -If called with prefix argument ARG, skip splitting of windows." +After the command has finished, you would typically mark some +image files in dired and call `tumme-display-thumbs' (by default +bound to C-t d). + +If called with prefix argument ARG, skip splitting of windows. + +The current window configuration is saved and can be restored by +calling `tumme-restore-window-configuration'." (interactive "DDirectory: \nP") (let ((buf (tumme-create-thumbnail-buffer)) (buf2 (tumme-create-display-image-buffer))) + (setq tumme-saved-window-configuration + (current-window-configuration)) (dired dir) + (delete-other-windows) (when (not arg) (split-window-horizontally) (setq truncate-lines t) @@ -995,6 +1044,16 @@ (switch-to-buffer buf2) (other-window -2))))) +(defun tumme-restore-window-configuration () + "Restore window configuration. +Restore any changes to the window configuration made by calling +`tumme-dired-with-window-configuration'." + (interactive) + (if tumme-saved-window-configuration + (set-window-configuration tumme-saved-window-configuration) + (message "No saved window configuration"))) + +;;;###autoload (defun tumme-display-thumbs (&optional arg append) "Display thumbnails of all marked files, in `tumme-thumbnail-buffer'. If a thumbnail image does not exist for a file, it is created on the @@ -1038,7 +1097,31 @@ ((eq 'none tumme-line-up-method) nil) (t - (tumme-line-up-dynamic)))))) + (tumme-line-up-dynamic)))) + (pop-to-buffer tumme-thumbnail-buffer))) + +(defun tumme-show-all-from-dir (dir) + "Make a preview buffer for all images in DIR and display it. +If the number of files in DIR matching `image-file-name-regexp' +exceeds `tumme-show-all-from-dir-max-files', a warning will be +displayed." + (interactive "DDir: ") + (dired dir) + (dired-mark-files-regexp (image-file-name-regexp)) + (let ((files (dired-get-marked-files))) + (if (or (<= (length files) tumme-show-all-from-dir-max-files) + (and (> (length files) tumme-show-all-from-dir-max-files) + (y-or-n-p + (format + "Directory contains more than %d image files. Proceed? " + tumme-show-all-from-dir-max-files)))) + (progn + (tumme-display-thumbs) + (pop-to-buffer tumme-thumbnail-buffer)) + (message "Cancelled.")))) + +;;;###autoload +(defalias 'tumme 'tumme-show-all-from-dir) (defun tumme-write-tag (files tag) "For all FILES, writes TAG to the image database." @@ -1125,6 +1208,7 @@ (kill-buffer buf) (split-string tags ";")))) +;;;###autoload (defun tumme-tag-files (arg) "Tag marked file(s) in dired. With prefix ARG, tag file at point." (interactive "P") @@ -1143,6 +1227,7 @@ (tumme-update-property 'tags (tumme-list-tags (tumme-original-file-name)))) +;;;###autoload (defun tumme-tag-remove (arg) "Remove tag for selected file(s). With prefix argument ARG, remove tag from file at point." @@ -1310,7 +1395,7 @@ (defun tumme-format-properties-string (buf file props comment) "Format display properties. BUF is the associated dired buffer, FILE is the original image file -name, PROPS is a list of tags and COMMENT is the images files's +name, PROPS is a list of tags and COMMENT is the image files's comment." (format-spec tumme-display-properties-format @@ -1406,6 +1491,7 @@ (select-window window)) (message "Associated dired buffer not visible")))) +;;;###autoload (defun tumme-jump-thumbnail-buffer () "Jump to thumbnail buffer." (interactive) @@ -1740,7 +1826,7 @@ (defun tumme-create-thumbs (&optional arg) "Create thumbnail images for all marked files in dired. With prefix argument ARG, create thumbnails even if they already exist -\(i.e. use this to refresh your thumbnails)." +\(i.e. use this to refresh your thumbnails)." (interactive "P") (let (curr-file thumb-name files count) (setq files (dired-get-marked-files)) @@ -1804,11 +1890,13 @@ (if (looking-at " ") (delete-char 1)))) +;;;###autoload (defun tumme-display-thumbs-append () "Append thumbnails to `tumme-thumbnail-buffer'." (interactive) (tumme-display-thumbs nil t)) +;;;###autoload (defun tumme-display-thumb () "Shorthard for `tumme-display-thumbs' with prefix argument." (interactive) @@ -1845,7 +1933,7 @@ (defun tumme-line-up-dynamic () "Line up thumbnails images dynamically. -Calculate how many thumbnails that fits." +Calculate how many thumbnails fit." (interactive) (let* ((char-width (frame-char-width)) (width (tumme-window-width-pixels (tumme-thumbnail-window))) @@ -1858,7 +1946,7 @@ (defun tumme-line-up-interactive () "Line up thumbnails interactively. -Ask user how many thumbnails that should be displayed per row." +Ask user how many thumbnails should be displayed per row." (interactive) (let ((tumme-thumbs-per-row (string-to-number (read-string "How many thumbs per row: ")))) @@ -1879,6 +1967,7 @@ tumme-external-viewer file)))))) +;;;###autoload (defun tumme-dired-display-external () "Display file at point using an external viewer." (interactive) @@ -1984,8 +2073,10 @@ (message "No thumbnail at point") (if (not file) (message "No original file name found") - (tumme-display-image file arg)))))) + (tumme-display-image file arg) + (display-buffer tumme-display-image-buffer)))))) +;;;###autoload (defun tumme-display-dired-image (&optional arg) "Display current image file. See documentation for `tumme-display-image' for more information. @@ -2187,7 +2278,7 @@ (tumme-display-thumbnail-original-image)) (defun tumme-display-previous-thumbnail-original () - "Move to previous thumbnail and display image." + "Move to previous thumbnail and display image." (interactive) (tumme-backward-char) @@ -2236,6 +2327,7 @@ prop value))) +;;;###autoload (defun tumme-dired-comment-files () "Add comment to current or marked files in dired." (interactive) @@ -2286,6 +2378,7 @@ (kill-buffer buf) comment))) +;;;###autoload (defun tumme-mark-tagged-files () "Use regexp to mark files with matching tag." (interactive) @@ -2506,7 +2599,7 @@ ;; Make sure gallery root exist (if (file-exists-p tumme-gallery-dir) (if (not (file-directory-p tumme-gallery-dir)) - (error "Tumme-gallery-dir is not a directory")) + (error "tumme-gallery-dir is not a directory")) (make-directory tumme-gallery-dir)) ;; Open index file (setq index-buf (find-file @@ -2555,7 +2648,7 @@ ;; Insert thumbnail with link to full image (insert (format "<a href=\"%s/%s\"><img src=\"%s/%s\"%s></a>\n" - tumme-gallery-image-root-url file + tumme-gallery-image-root-url (file-name-nondirectory file) tumme-gallery-thumb-image-root-url (file-name-nondirectory (tumme-thumb-name file)) file)) ;; Insert comment, if any @@ -2597,38 +2690,53 @@ (error nil)) (kill-buffer buffer))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;; TEST-SECTION ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defvar tumme-dir-max-size 12300000) +;; (defvar tumme-dir-max-size 12300000) -(defun tumme-test () - "Clean `tumme-dir' from old thumbnail files. -\"Oldness\" measured using last access time. If the total size of all -thumbnail files in `tumme-dir' is larger than 'tumme-dir-max-size', -old files are deleted until the max size is reached." - (let* ((files - (sort - (mapcar - (lambda (f) - (let ((fattribs (file-attributes f))) - ;; Get last access time and file size - `(,(nth 4 fattribs) ,(nth 7 fattribs) ,f))) - (directory-files tumme-dir t ".+\.thumb\..+$")) - ;; Sort function. Compare time between two files. - '(lambda (l1 l2) - (time-less-p (car l1) (car l2))))) - (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files)))) - (while (> dirsize tumme-dir-max-size) - (y-or-n-p - (format "Size of thumbnail directory: %d, delete old file %s? " - dirsize (cadr (cdar files)))) - (delete-file (cadr (cdar files))) - (setq dirsize (- dirsize (car (cdar files)))) - (setq files (cdr files))))) +;; (defun tumme-test-clean-old-files () +;; "Clean `tumme-dir' from old thumbnail files. +;; \"Oldness\" measured using last access time. If the total size of all +;; thumbnail files in `tumme-dir' is larger than 'tumme-dir-max-size', +;; old files are deleted until the max size is reached." +;; (let* ((files +;; (sort +;; (mapcar +;; (lambda (f) +;; (let ((fattribs (file-attributes f))) +;; ;; Get last access time and file size +;; `(,(nth 4 fattribs) ,(nth 7 fattribs) ,f))) +;; (directory-files tumme-dir t ".+\.thumb\..+$")) +;; ;; Sort function. Compare time between two files. +;; '(lambda (l1 l2) +;; (time-less-p (car l1) (car l2))))) +;; (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files)))) +;; (while (> dirsize tumme-dir-max-size) +;; (y-or-n-p +;; (format "Size of thumbnail directory: %d, delete old file %s? " +;; dirsize (cadr (cdar files)))) +;; (delete-file (cadr (cdar files))) +;; (setq dirsize (- dirsize (car (cdar files)))) +;; (setq files (cdr files))))) + +;;;;;;;;;;;;;;;;;;;;;;, + +;; (defun dired-speedbar-buttons (dired-buffer) +;; (when (and (boundp 'tumme-use-speedbar) +;; tumme-use-speedbar) +;; (let ((filename (with-current-buffer dired-buffer +;; (dired-get-filename)))) +;; (when (and (not (string-equal filename (buffer-string))) +;; (string-match (image-file-name-regexp) filename)) +;; (erase-buffer) +;; (insert (propertize +;; filename +;; 'display +;; (tumme-get-thumbnail-image filename))))))) + +;; (setq tumme-use-speedbar t) (provide 'tumme)