comparison lisp/thumbs.el @ 90185:5b029ff3b08d

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-55 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 320-323) - Update from CVS
author Miles Bader <miles@gnu.org>
date Thu, 26 May 2005 05:42:19 +0000
parents 4da4a09e8b1b 6dd34b690fa9
children 01137c1fdbe9
comparison
equal deleted inserted replaced
90184:9e5e2f01c7ab 90185:5b029ff3b08d
81 :type 'string 81 :type 'string
82 :group 'thumbs) 82 :group 'thumbs)
83 83
84 (defcustom thumbs-thumbsdir-max-size 50000000 84 (defcustom thumbs-thumbsdir-max-size 50000000
85 "Max size for thumbnails directory. 85 "Max size for thumbnails directory.
86 When it reach that size (in bytes), a warning is send." 86 When it reachs that size (in bytes), a warning is sent."
87 :type 'string 87 :type 'string
88 :group 'thumbs) 88 :group 'thumbs)
89 89
90 (defcustom thumbs-conversion-program 90 (defcustom thumbs-conversion-program
91 (if (equal 'windows-nt system-type) 91 (if (equal 'windows-nt system-type)
140 :group 'thumbs) 140 :group 'thumbs)
141 141
142 ;; Initialize some variable, for later use. 142 ;; Initialize some variable, for later use.
143 (defvar thumbs-temp-file 143 (defvar thumbs-temp-file
144 (concat thumbs-temp-dir thumbs-temp-prefix) 144 (concat thumbs-temp-dir thumbs-temp-prefix)
145 "Temporary filesname for images.") 145 "Temporary filename for images.")
146 146
147 (defvar thumbs-current-tmp-filename 147 (defvar thumbs-current-tmp-filename
148 nil 148 nil
149 "Temporary filename of current image.") 149 "Temporary filename of current image.")
150 (defvar thumbs-current-image-filename 150 (defvar thumbs-current-image-filename
186 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter)))))) 186 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter))))))
187 (make-symbol (format "%s%d" prefix num)))) 187 (make-symbol (format "%s%d" prefix num))))
188 188
189 (defun thumbs-cleanup-thumbsdir () 189 (defun thumbs-cleanup-thumbsdir ()
190 "Clean the thumbnails directory. 190 "Clean the thumbnails directory.
191 If the total size of all files in 'thumbs-thumbsdir' is bigger than 191 If the total size of all files in `thumbs-thumbsdir' is bigger than
192 'thumbs-thumbsdir-max-size', files are deleted until the max size is 192 `thumbs-thumbsdir-max-size', files are deleted until the max size is
193 reached." 193 reached."
194 (let* ((filesL 194 (let* ((filesL
195 (sort 195 (sort
196 (mapcar 196 (mapcar
197 (lambda (f) 197 (lambda (f)
215 &optional arg output-format action-prefix) 215 &optional arg output-format action-prefix)
216 "Call the convert program. 216 "Call the convert program.
217 FILEIN is the input file, 217 FILEIN is the input file,
218 FILEOUT is the output file, 218 FILEOUT is the output file,
219 ACTION is the command to send to convert. 219 ACTION is the command to send to convert.
220 Optional argument are: 220 Optional arguments are:
221 ARG any arguments to the ACTION command, 221 ARG any arguments to the ACTION command,
222 OUTPUT-FORMAT is the file format to output, default is jpeg 222 OUTPUT-FORMAT is the file format to output (default is jpeg),
223 ACTION-PREFIX is the symbol to place before the ACTION command 223 ACTION-PREFIX is the symbol to place before the ACTION command
224 (default to '-' but can sometime be '+')." 224 (defaults to '-' but can sometimes be '+')."
225 (let ((command (format "%s %s%s %s \"%s\" \"%s:%s\"" 225 (let ((command (format "%s %s%s %s \"%s\" \"%s:%s\""
226 thumbs-conversion-program 226 thumbs-conversion-program
227 (or action-prefix "-") 227 (or action-prefix "-")
228 action 228 action
229 (or arg "") 229 (or arg "")
239 (defun thumbs-decrement-image-size-element (n d) 239 (defun thumbs-decrement-image-size-element (n d)
240 "Decrement number N by D percent." 240 "Decrement number N by D percent."
241 (round (- n (/ (* d n) 100)))) 241 (round (- n (/ (* d n) 100))))
242 242
243 (defun thumbs-increment-image-size (s) 243 (defun thumbs-increment-image-size (s)
244 "Increment S (a cons of width x heigh)." 244 "Increment S (a cons of width x height)."
245 (cons 245 (cons
246 (thumbs-increment-image-size-element (car s) 246 (thumbs-increment-image-size-element (car s)
247 thumbs-image-resizing-step) 247 thumbs-image-resizing-step)
248 (thumbs-increment-image-size-element (cdr s) 248 (thumbs-increment-image-size-element (cdr s)
249 thumbs-image-resizing-step))) 249 thumbs-image-resizing-step)))
250 250
251 (defun thumbs-decrement-image-size (s) 251 (defun thumbs-decrement-image-size (s)
252 "Decrement S (a cons of width x heigh)." 252 "Decrement S (a cons of width x height)."
253 (cons 253 (cons
254 (thumbs-decrement-image-size-element (car s) 254 (thumbs-decrement-image-size-element (car s)
255 thumbs-image-resizing-step) 255 thumbs-image-resizing-step)
256 (thumbs-decrement-image-size-element (cdr s) 256 (thumbs-decrement-image-size-element (cdr s)
257 thumbs-image-resizing-step))) 257 thumbs-image-resizing-step)))
347 347
348 (defun thumbs-insert-image (img type relief &optional marked) 348 (defun thumbs-insert-image (img type relief &optional marked)
349 "Insert image IMG at point. 349 "Insert image IMG at point.
350 TYPE and RELIEF will be used in constructing the image; see `image' 350 TYPE and RELIEF will be used in constructing the image; see `image'
351 in the emacs-lisp manual for further documentation. 351 in the emacs-lisp manual for further documentation.
352 if MARKED is non-nil, the image is marked." 352 If MARKED is non-nil, the image is marked."
353 (let ((i `(image :type ,type 353 (let ((i `(image :type ,type
354 :file ,img 354 :file ,img
355 :relief ,relief 355 :relief ,relief
356 :conversion ,(if marked 'disabled) 356 :conversion ,(if marked 'disabled)
357 :margin ,thumbs-margin))) 357 :margin ,thumbs-margin)))
359 (setq thumbs-current-image-size 359 (setq thumbs-current-image-size
360 (image-size i t)))) 360 (image-size i t))))
361 361
362 (defun thumbs-insert-thumb (img &optional marked) 362 (defun thumbs-insert-thumb (img &optional marked)
363 "Insert the thumbnail for IMG at point. 363 "Insert the thumbnail for IMG at point.
364 if MARKED is non-nil, the image is marked" 364 If MARKED is non-nil, the image is marked."
365 (thumbs-insert-image 365 (thumbs-insert-image
366 (thumbs-make-thumb img) 'jpeg thumbs-relief marked) 366 (thumbs-make-thumb img) 'jpeg thumbs-relief marked)
367 (put-text-property (1- (point)) (point) 367 (put-text-property (1- (point)) (point)
368 'thumb-image-file img)) 368 'thumb-image-file img))
369 369
401 (or reg (image-file-name-regexp))) 401 (or reg (image-file-name-regexp)))
402 (concat "*Thumbs: " dir) same-window)) 402 (concat "*Thumbs: " dir) same-window))
403 403
404 ;;;###autoload 404 ;;;###autoload
405 (defun thumbs-dired-show-marked () 405 (defun thumbs-dired-show-marked ()
406 "In Dired, make a thumbs buffer with all marked files." 406 "In dired, make a thumbs buffer with all marked files."
407 (interactive) 407 (interactive)
408 (thumbs-show-thumbs-list (dired-get-marked-files) nil t)) 408 (thumbs-show-thumbs-list (dired-get-marked-files) nil t))
409 409
410 ;;;###autoload 410 ;;;###autoload
411 (defun thumbs-dired-show-all () 411 (defun thumbs-dired-show-all ()
433 (delete-region (point-min)(point-max)) 433 (delete-region (point-min)(point-max))
434 (thumbs-insert-image img (thumbs-image-type img) 0))) 434 (thumbs-insert-image img (thumbs-image-type img) 0)))
435 435
436 (defun thumbs-find-image-at-point (&optional img otherwin) 436 (defun thumbs-find-image-at-point (&optional img otherwin)
437 "Display image IMG for thumbnail at point. 437 "Display image IMG for thumbnail at point.
438 use another window it OTHERWIN is t." 438 Use another window if OTHERWIN is t."
439 (interactive) 439 (interactive)
440 (let* ((i (or img (thumbs-current-image)))) 440 (let* ((i (or img (thumbs-current-image))))
441 (thumbs-find-image i (point) otherwin))) 441 (thumbs-find-image i (point) otherwin)))
442 442
443 (defun thumbs-find-image-at-point-other-window () 443 (defun thumbs-find-image-at-point-other-window ()
497 (push (thumbs-current-image) list)) 497 (push (thumbs-current-image) list))
498 (forward-char 1)) 498 (forward-char 1))
499 (nreverse list)))) 499 (nreverse list))))
500 500
501 (defun thumbs-delete-images () 501 (defun thumbs-delete-images ()
502 "Delete the image at point (and it's thumbnail) (or marked files if any)." 502 "Delete the image at point (and its thumbnail) (or marked files if any)."
503 (interactive) 503 (interactive)
504 (let ((files (or thumbs-markedL (list (thumbs-current-image))))) 504 (let ((files (or thumbs-markedL (list (thumbs-current-image)))))
505 (if (yes-or-no-p (format "Really delete %d files? " (length files))) 505 (if (yes-or-no-p (format "Really delete %d files? " (length files)))
506 (let ((thumbs-fileL (thumbs-file-alist)) 506 (let ((thumbs-fileL (thumbs-file-alist))
507 (inhibit-read-only t)) 507 (inhibit-read-only t))
518 (delete-region (point) (1+ (point)))) 518 (delete-region (point) (1+ (point))))
519 (setq thumbs-markedL 519 (setq thumbs-markedL
520 (delq x thumbs-markedL))))))))) 520 (delq x thumbs-markedL)))))))))
521 521
522 (defun thumbs-rename-images (newfile) 522 (defun thumbs-rename-images (newfile)
523 "Rename the image at point (and it's thumbnail) (or marked files if any)." 523 "Rename the image at point (and its thumbnail) (or marked files if any)."
524 (interactive "FRename to file or directory: ") 524 (interactive "FRename to file or directory: ")
525 (let ((files (or thumbs-markedL (list (thumbs-current-image)))) 525 (let ((files (or thumbs-markedL (list (thumbs-current-image))))
526 failures) 526 failures)
527 (if (and (not (file-directory-p newfile)) 527 (if (and (not (file-directory-p newfile))
528 thumbs-markedL) 528 thumbs-markedL)
572 (thumbs-insert-image i (thumbs-image-type i) 0)) 572 (thumbs-insert-image i (thumbs-image-type i) 0))
573 (setq thumbs-image-num num 573 (setq thumbs-image-num num
574 thumbs-current-image-filename i)))) 574 thumbs-current-image-filename i))))
575 575
576 (defun thumbs-next-image () 576 (defun thumbs-next-image ()
577 "Show next image." 577 "Show the next image."
578 (interactive) 578 (interactive)
579 (let* ((i (1+ thumbs-image-num)) 579 (let* ((i (1+ thumbs-image-num))
580 (list (thumbs-file-alist)) 580 (list (thumbs-file-alist))
581 (l (caar list))) 581 (l (caar list)))
582 (while (and (/= i thumbs-image-num) (not (assoc i list))) 582 (while (and (/= i thumbs-image-num) (not (assoc i list)))
780 fundamental-mode "image-view-mode" 780 fundamental-mode "image-view-mode"
781 (setq buffer-read-only t)) 781 (setq buffer-read-only t))
782 782
783 ;;;###autoload 783 ;;;###autoload
784 (defun thumbs-dired-setroot () 784 (defun thumbs-dired-setroot ()
785 "In dired, Call the setroot program on the image at point." 785 "In dired, call the setroot program on the image at point."
786 (interactive) 786 (interactive)
787 (thumbs-call-setroot-command (dired-get-filename))) 787 (thumbs-call-setroot-command (dired-get-filename)))
788 788
789 ;; Modif to dired mode map 789 ;; Modif to dired mode map
790 (define-key dired-mode-map "\C-ta" 'thumbs-dired-show-all) 790 (define-key dired-mode-map "\C-ta" 'thumbs-dired-show-all)