annotate lisp/thumbs.el @ 76983:99a420a313c3

* textmodes/flyspell.el (flyspell-duplicate, flyspell-incorrect): Revert 2006-01-27 change.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 06 Apr 2007 18:55:01 +0000
parents e3694f1cb928
children 9b9e3ca5a965 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; thumbs.el --- Thumbnails previewer for images files
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 71807
diff changeset
3 ;; Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
4
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca>
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
6 ;; Maintainer: FSF
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: Multimedia
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63313
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63313
diff changeset
24 ;; Boston, MA 02110-1301, USA.
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
28 ;; This package create two new modes: thumbs-mode and thumbs-view-image-mode.
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
29 ;; It is used for basic browsing and viewing of images from within Emacs.
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
30 ;; Minimal image manipulation functions are also available via external
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
31 ;; programs. If you want to do more complex tasks like categorise and tag
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
32 ;; your images, use tumme.el
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; The 'convert' program from 'ImageMagick'
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; [URL:http://www.imagemagick.org/] is required.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
37 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
38 ;; time. The peoples at #emacs@freenode.net for numerous help. RMS
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
39 ;; for emacs and the GNU project.
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
40 ;;
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
42 ;;
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; CHANGELOG
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; This is version 2.0
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; USAGE
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; Type M-x thumbs RET DIR RET to view the directory DIR in Thumbs mode.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; That should be a directory containing image files.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; from dired, C-t m enter in thumbs-mode with all marked files
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; C-t a enter in thumbs-mode with all files in current-directory
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
53 ;; In thumbs-mode, pressing <return> on a image will bring you in image view
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
54 ;; mode for that image. C-h m will give you a list of available keybinding.
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; History:
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
57 ;;
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;; Code:
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (require 'dired)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; CUSTOMIZATIONS
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (defgroup thumbs nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 "Thumbnails previewer."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57831
diff changeset
67 :version "22.1"
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 :group 'multimedia)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
66568
624edd899d32 * thumbs.el (thumbs-thumbsdir): Default to ~/.emacs.d/thumbs.
Chong Yidong <cyd@stupidchicken.com>
parents: 66413
diff changeset
70 (defcustom thumbs-thumbsdir "~/.emacs.d/thumbs"
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 "*Directory to store thumbnails."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 :type 'directory
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (defcustom thumbs-geometry "100x100"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 "*Size of thumbnails."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
80 (defcustom thumbs-per-line 4
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
81 "Number of thumbnails per line to show in directory."
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
82 :type 'integer
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
83 :group 'thumbs)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
84
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
85 (defcustom thumbs-max-image-number 16
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
86 "Maximum number of images initially displayed in thumbs buffer."
63313
2d9ef16c13be (thumbs-per-line, thumbs-thumbsdir-max-size)
Eli Zaretskii <eliz@gnu.org>
parents: 63280
diff changeset
87 :type 'integer
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defcustom thumbs-thumbsdir-max-size 50000000
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
91 "Maximum size for thumbnails directory.
63078
2d7151e2c3ee (thumbs-thumbsdir-max-size, thumbs-image-resizing-step,
Juanma Barranquero <lekktu@gmail.com>
parents: 62927
diff changeset
92 When it reaches that size (in bytes), a warning is sent."
63313
2d9ef16c13be (thumbs-per-line, thumbs-thumbsdir-max-size)
Eli Zaretskii <eliz@gnu.org>
parents: 63280
diff changeset
93 :type 'integer
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (defcustom thumbs-conversion-program
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
97 (if (eq system-type 'windows-nt)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 "convert.exe"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (or (executable-find "convert")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "/usr/X11R6/bin/convert"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 "*Name of conversion program for thumbnails generation.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 It must be 'convert'."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (defcustom thumbs-setroot-command
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 "xloadimage -onroot -fullscreen *"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 "Command to set the root window."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defcustom thumbs-relief 5
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 "*Size of button-like border around thumbnails."
63313
2d9ef16c13be (thumbs-per-line, thumbs-thumbsdir-max-size)
Eli Zaretskii <eliz@gnu.org>
parents: 63280
diff changeset
114 :type 'integer
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (defcustom thumbs-margin 2
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 "*Size of the margin around thumbnails.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 This is where you see the cursor."
63313
2d9ef16c13be (thumbs-per-line, thumbs-thumbsdir-max-size)
Eli Zaretskii <eliz@gnu.org>
parents: 63280
diff changeset
120 :type 'integer
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defcustom thumbs-thumbsdir-auto-clean t
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 "If set, delete older file in the thumbnails directory.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 Deletion is done at load time when the directory size is bigger
63078
2d7151e2c3ee (thumbs-thumbsdir-max-size, thumbs-image-resizing-step,
Juanma Barranquero <lekktu@gmail.com>
parents: 62927
diff changeset
126 than `thumbs-thumbsdir-max-size'."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 :type 'boolean
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (defcustom thumbs-image-resizing-step 10
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
131 "Step by which to resize image as a percentage."
63313
2d9ef16c13be (thumbs-per-line, thumbs-thumbsdir-max-size)
Eli Zaretskii <eliz@gnu.org>
parents: 63280
diff changeset
132 :type 'integer
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
135 (defcustom thumbs-temp-dir temporary-file-directory
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 "Temporary directory to use.
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
137 Defaults to `temporary-file-directory'. Leaving it to
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
138 this value can let another user see some of your images."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 :type 'directory
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (defcustom thumbs-temp-prefix "emacsthumbs"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 "Prefix to add to temp files."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; Initialize some variable, for later use.
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
148 (defvar thumbs-current-tmp-filename nil
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 "Temporary filename of current image.")
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
150 (make-variable-buffer-local 'thumbs-current-tmp-filename)
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
151
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
152 (defvar thumbs-current-image-filename nil
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 "Filename of current image.")
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
154 (make-variable-buffer-local 'thumbs-current-image-filename)
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
155
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
156 (defvar thumbs-extra-images 1
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
157 "Counter for showing extra images in thumbs buffer.")
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
158 (make-variable-buffer-local 'thumbs-extra-images)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
159 (put 'thumbs-extra-images 'permanent-local t)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
160
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
161 (defvar thumbs-current-image-size nil
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 "Size of current image.")
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
163
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
164 (defvar thumbs-image-num nil
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 "Number of current image.")
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
166 (make-variable-buffer-local 'thumbs-image-num)
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
167
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
168 (defvar thumbs-buffer nil
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
169 "Name of buffer containing thumbnails associated with image.")
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
170 (make-variable-buffer-local 'thumbs-buffer)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
171
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
172 (defvar thumbs-current-dir nil
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 "Current directory.")
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
174
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
175 (defvar thumbs-marked-list nil
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 "List of marked files.")
68486
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
177 (make-variable-buffer-local 'thumbs-marked-list)
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
178 (put 'thumbs-marked-list 'permanent-local t)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
180 (defalias 'thumbs-gensym
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
181 (if (fboundp 'gensym)
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
182 'gensym
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
183 ;; Copied from cl-macs.el
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
184 (defvar thumbs-gensym-counter 0)
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
185 (lambda (&optional prefix)
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
186 "Generate a new uninterned symbol.
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
187 The name is made by appending a number to PREFIX, default \"G\"."
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
188 (let ((pfix (if (stringp prefix) prefix "G"))
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
189 (num (if (integerp prefix) prefix
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
190 (prog1 thumbs-gensym-counter
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
191 (setq thumbs-gensym-counter
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
192 (1+ thumbs-gensym-counter))))))
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
193 (make-symbol (format "%s%d" pfix num))))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
63280
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
195 (defsubst thumbs-temp-dir ()
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
196 (file-name-as-directory (expand-file-name thumbs-temp-dir)))
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
197
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
198 (defun thumbs-temp-file ()
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
199 "Return a unique temporary filename for an image."
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
200 (format "%s%s-%s.jpg"
63280
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
201 (thumbs-temp-dir)
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
202 thumbs-temp-prefix
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
203 (thumbs-gensym "T")))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
205 (defun thumbs-thumbsdir ()
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
206 "Return the current thumbnails directory (from `thumbs-thumbsdir').
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
207 Create the thumbnails directory if it does not exist."
63280
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
208 (let ((thumbs-thumbsdir (file-name-as-directory
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
209 (expand-file-name thumbs-thumbsdir))))
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
210 (unless (file-directory-p thumbs-thumbsdir)
66568
624edd899d32 * thumbs.el (thumbs-thumbsdir): Default to ~/.emacs.d/thumbs.
Chong Yidong <cyd@stupidchicken.com>
parents: 66413
diff changeset
211 (make-directory thumbs-thumbsdir t)
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
212 (message "Creating thumbnails directory"))
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
213 thumbs-thumbsdir))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (defun thumbs-cleanup-thumbsdir ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 "Clean the thumbnails directory.
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
217 If the total size of all files in `thumbs-thumbsdir' is bigger than
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
218 `thumbs-thumbsdir-max-size', files are deleted until the max size is
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 reached."
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
220 (let* ((files-list
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (sort
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (mapcar
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (lambda (f)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
224 (let ((fattribs-list (file-attributes f)))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
225 `(,(nth 4 fattribs-list) ,(nth 7 fattribs-list) ,f)))
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
226 (directory-files (thumbs-thumbsdir) t (image-file-name-regexp)))
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
227 '(lambda (l1 l2) (time-less-p (car l1) (car l2)))))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
228 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) files-list))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (while (> dirsize thumbs-thumbsdir-max-size)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (progn
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
231 (message "Deleting file %s" (cadr (cdar files-list))))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
232 (delete-file (cadr (cdar files-list)))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
233 (setq dirsize (- dirsize (car (cdar files-list))))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
234 (setq files-list (cdr files-list)))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;; Check the thumbsnail directory size and clean it if necessary.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (when thumbs-thumbsdir-auto-clean
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (thumbs-cleanup-thumbsdir))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (defun thumbs-call-convert (filein fileout action
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 &optional arg output-format action-prefix)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 "Call the convert program.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 FILEIN is the input file,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 FILEOUT is the output file,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ACTION is the command to send to convert.
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
246 Optional arguments are:
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 ARG any arguments to the ACTION command,
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
248 OUTPUT-FORMAT is the file format to output (default is jpeg),
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 ACTION-PREFIX is the symbol to place before the ACTION command
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
250 (defaults to '-' but can sometimes be '+')."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (let ((command (format "%s %s%s %s \"%s\" \"%s:%s\""
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 thumbs-conversion-program
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (or action-prefix "-")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 action
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (or arg "")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 filein
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (or output-format "jpeg")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 fileout)))
71807
682a51aa586a (thumbs-call-convert): Use shell-command-switch.
Nick Roberts <nickrob@snap.net.nz>
parents: 68651
diff changeset
259 (call-process shell-file-name nil nil nil shell-command-switch command)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
261 (defun thumbs-new-image-size (s increment)
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
262 "New image (a cons of width x height)."
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
263 (let ((d (* increment thumbs-image-resizing-step)))
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
264 (cons
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
265 (round (+ (car s) (/ (* d (car s)) 100)))
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
266 (round (+ (cdr s) (/ (* d (cdr s)) 100))))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
268 (defun thumbs-resize-image-1 (&optional increment size)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 "Resize image in current buffer.
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
270 If SIZE is specified use it. Otherwise make the image larger or
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
271 smaller according to whether INCREMENT is 1 or -1."
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
272 (let* ((buffer-read-only nil)
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
273 (old thumbs-current-tmp-filename)
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
274 (x (or size
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
275 (thumbs-new-image-size thumbs-current-image-size increment)))
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
276 (tmp (thumbs-temp-file)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (erase-buffer)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
278 (thumbs-call-convert (or old thumbs-current-image-filename)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 tmp "sample"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (concat (number-to-string (car x)) "x"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (number-to-string (cdr x))))
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
282 (save-excursion
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
283 (thumbs-insert-image tmp 'jpeg 0))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (setq thumbs-current-tmp-filename tmp)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
286 (defun thumbs-resize-image (width height)
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
287 "Resize image interactively to specified WIDTH and HEIGHT."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (interactive "nWidth: \nnHeight: ")
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
289 (thumbs-resize-image-1 nil (cons width height)))
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
290
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
291 (defun thumbs-shrink-image ()
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 "Resize image (smaller)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (interactive)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
294 (thumbs-resize-image-1 -1))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
296 (defun thumbs-enlarge-image ()
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 "Resize image (bigger)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (interactive)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
299 (thumbs-resize-image-1 1))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (defun thumbs-thumbname (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 "Return a thumbnail name for the image IMG."
62891
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
303 (convert-standard-filename
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
304 (let ((filename (expand-file-name img)))
63280
69ae2aff114c Fixes for changes of 2005-06-09.
Juanma Barranquero <lekktu@gmail.com>
parents: 63155
diff changeset
305 (format "%s%08x-%s.jpg"
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
306 (thumbs-thumbsdir)
62891
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
307 (sxhash filename)
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
308 (subst-char-in-string
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
309 ?\s ?\_
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
310 (apply
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
311 'concat
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
312 (split-string filename "/")))))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (defun thumbs-make-thumb (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 "Create the thumbnail for IMG."
62891
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
316 (let ((fn (expand-file-name img))
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
317 (tn (thumbs-thumbname img)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (if (or (not (file-exists-p tn))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
319 ;; This is not the right fix, but I don't understand
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
320 ;; the external program or why it produces a geometry
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
321 ;; unequal to the one requested -- rms.
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
322 ;;; (not (equal (thumbs-file-size tn) thumbs-geometry))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
323 )
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (thumbs-call-convert fn tn "sample" thumbs-geometry))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 tn))
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
326
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (defun thumbs-image-type (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 "Return image type from filename IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (cond ((string-match ".*\\.jpe?g\\'" img) 'jpeg)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 ((string-match ".*\\.xpm\\'" img) 'xpm)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ((string-match ".*\\.xbm\\'" img) 'xbm)
66413
4e56b3fda002 * menu-bar.el (menu-bar-help-menu): Rename "psychiatrist", in line
Chong Yidong <cyd@stupidchicken.com>
parents: 64762
diff changeset
332 ((string-match ".*\\.pbm\\'" img) 'pbm)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ((string-match ".*\\.gif\\'" img) 'gif)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 ((string-match ".*\\.bmp\\'" img) 'bmp)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ((string-match ".*\\.png\\'" img) 'png)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 ((string-match ".*\\.tiff?\\'" img) 'tiff)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defun thumbs-file-size (img)
68486
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
339 (let ((i (image-size
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
340 (find-image `((:type ,(thumbs-image-type img) :file ,img))) t)))
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
341 (concat (number-to-string (round (car i))) "x"
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (number-to-string (round (cdr i))))))
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
343
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (defun thumbs-find-thumb (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 "Display the thumbnail for IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (interactive "f")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (find-file (thumbs-make-thumb img)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (defun thumbs-insert-image (img type relief &optional marked)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 "Insert image IMG at point.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 TYPE and RELIEF will be used in constructing the image; see `image'
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 in the emacs-lisp manual for further documentation.
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
354 If MARKED is non-nil, the image is marked."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (let ((i `(image :type ,type
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 :file ,img
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 :relief ,relief
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 :conversion ,(if marked 'disabled)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 :margin ,thumbs-margin)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (insert-image i)
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
361 (set (make-local-variable 'thumbs-current-image-size)
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
362 (image-size i t))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (defun thumbs-insert-thumb (img &optional marked)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 "Insert the thumbnail for IMG at point.
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
366 If MARKED is non-nil, the image is marked."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (thumbs-insert-image
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
368 (thumbs-make-thumb img) 'jpeg thumbs-relief marked)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
369 (add-text-properties (1- (point)) (point)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
370 `(thumb-image-file ,img
68486
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
371 help-echo ,(file-name-nondirectory img)
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
372 rear-nonsticky help-echo)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
374 (defun thumbs-do-thumbs-insertion (list)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
375 "Insert all thumbnails into thumbs buffer."
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
376 (let* ((i 0)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
377 (length (length list))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
378 (diff (- length (* thumbs-max-image-number thumbs-extra-images))))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
379 (nbutlast list diff)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
380 (dolist (img list)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
381 (thumbs-insert-thumb img
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
382 (member img thumbs-marked-list))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (when (= 0 (mod (setq i (1+ i)) thumbs-per-line))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
384 (newline)))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
385 (unless (bobp) (newline))
68409
7ca2eae4cee2 (thumbs-do-thumbs-insertion): Suppress message when
Nick Roberts <nickrob@snap.net.nz>
parents: 68373
diff changeset
386 (if (> diff 0) (message "Type + to display more images."))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
388 (defun thumbs-show-thumbs-list (list &optional dir same-window)
62891
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
389 (unless (and (display-images-p)
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
390 (image-type-available-p 'jpeg))
58c1e48ab7bc (thumbs-thumbname): The resulting thubname includes a hash value to improve its
Juanma Barranquero <lekktu@gmail.com>
parents: 62692
diff changeset
391 (error "Required image type is not supported in this Emacs session"))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (funcall (if same-window 'switch-to-buffer 'pop-to-buffer)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
393 (if dir (concat "*Thumbs: " dir) "*THUMB-View*"))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (let ((inhibit-read-only t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (erase-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (thumbs-mode)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
397 (setq thumbs-buffer (current-buffer))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
398 (if dir (setq default-directory dir))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
399 (thumbs-do-thumbs-insertion list)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (goto-char (point-min))
64718
40aaf4d2def3 (thumbs-find-image): Don't make variables automatically buffer local.
Juanma Barranquero <lekktu@gmail.com>
parents: 64091
diff changeset
401 (set (make-local-variable 'thumbs-current-dir) default-directory)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 ;;;###autoload
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
404 (defun thumbs-show-from-dir (dir &optional reg same-window)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 "Make a preview buffer for all images in DIR.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 Optional argument REG to select file matching a regexp,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 and SAME-WINDOW to show thumbs in the same window."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (interactive "DDir: ")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (thumbs-show-thumbs-list
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
410 (directory-files dir t (or reg (image-file-name-regexp)))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
411 dir same-window))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (defun thumbs-dired-show-marked ()
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
415 "In dired, make a thumbs buffer with marked files."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (thumbs-show-thumbs-list (dired-get-marked-files) nil t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 ;;;###autoload
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
420 (defun thumbs-dired-show ()
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 "In dired, make a thumbs buffer with all files in current directory."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (interactive)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
423 (thumbs-show-from-dir default-directory nil t))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 ;;;###autoload
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
426 (defalias 'thumbs 'thumbs-show-from-dir)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
428 (defun thumbs-find-image (img &optional num otherwin)
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
429 (let ((buffer (current-buffer)))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
430 (funcall
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
431 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
432 "*Image*")
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
433 (thumbs-view-image-mode)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
434 (setq mode-name
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
435 (concat "image-view-mode: " (file-name-nondirectory img)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
436 " - " (number-to-string num)))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
437 (setq thumbs-buffer buffer)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
438 (let ((inhibit-read-only t))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
439 (setq thumbs-current-image-filename img
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
440 thumbs-current-tmp-filename nil
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
441 thumbs-image-num (or num 0))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
442 (delete-region (point-min)(point-max))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
443 (save-excursion
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
444 (thumbs-insert-image img (thumbs-image-type img) 0)))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (defun thumbs-find-image-at-point (&optional img otherwin)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 "Display image IMG for thumbnail at point.
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
448 Use another window if OTHERWIN is t."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (interactive)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
450 (let* ((i (or img (thumbs-current-image))))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
451 (thumbs-find-image i (point) otherwin)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (defun thumbs-find-image-at-point-other-window ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 "Display image for thumbnail at point in the preview buffer.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 Open another window."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (thumbs-find-image-at-point nil t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
459 (defun thumbs-mouse-find-image (event)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
460 "Display image for thumbnail at mouse click EVENT."
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
461 (interactive "e")
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
462 (mouse-set-point event)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
463 (thumbs-find-image-at-point))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
464
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (defun thumbs-call-setroot-command (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 "Call the setroot program for IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (run-hooks 'thumbs-before-setroot-hook)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (shell-command (replace-regexp-in-string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 "\\*"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (shell-quote-argument (expand-file-name img))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 thumbs-setroot-command nil t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (run-hooks 'thumbs-after-setroot-hook))
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
473
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (defun thumbs-set-image-at-point-to-root-window ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 "Set the image at point as the desktop wallpaper."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (interactive)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
477 (thumbs-call-setroot-command
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
478 (thumbs-current-image)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (defun thumbs-set-root ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 "Set the current image as root."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (thumbs-call-setroot-command
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (or thumbs-current-tmp-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 thumbs-current-image-filename)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
487 (defun thumbs-file-alist ()
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
488 "Make an alist of elements (POS . FILENAME) for all images in thumb buffer."
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
489 (with-current-buffer thumbs-buffer
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
490 (save-excursion
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
491 (let (list)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
492 (goto-char (point-min))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
493 (while (not (eobp))
68486
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
494 (unless (eolp)
68340
5325b795290b (thumbs-file-alist): Avoid creating duplicate entries.
Nick Roberts <nickrob@snap.net.nz>
parents: 68289
diff changeset
495 (if (thumbs-current-image)
5325b795290b (thumbs-file-alist): Avoid creating duplicate entries.
Nick Roberts <nickrob@snap.net.nz>
parents: 68289
diff changeset
496 (push (cons (point-marker)
5325b795290b (thumbs-file-alist): Avoid creating duplicate entries.
Nick Roberts <nickrob@snap.net.nz>
parents: 68289
diff changeset
497 (thumbs-current-image))
5325b795290b (thumbs-file-alist): Avoid creating duplicate entries.
Nick Roberts <nickrob@snap.net.nz>
parents: 68289
diff changeset
498 list)))
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
499 (forward-char 1))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
500 (nreverse list)))))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
501
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
502 (defun thumbs-file-list ()
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
503 "Make a list of file names for all images in thumb buffer."
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
504 (save-excursion
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
505 (let (list)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
506 (goto-char (point-min))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
507 (while (not (eobp))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
508 (if (thumbs-current-image)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
509 (push (thumbs-current-image) list))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
510 (forward-char 1))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
511 (nreverse list))))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
512
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (defun thumbs-delete-images ()
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
514 "Delete the image at point (and its thumbnail) (or marked files if any)."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (interactive)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
516 (let ((files (or thumbs-marked-list (list (thumbs-current-image)))))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
517 (if (yes-or-no-p (format "Really delete %d files? " (length files)))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
518 (let ((thumbs-file-list (thumbs-file-alist))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
519 (inhibit-read-only t))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
520 (dolist (x files)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
521 (let (failure)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
522 (condition-case ()
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
523 (progn
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (delete-file x)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
525 (delete-file (thumbs-thumbname x)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
526 (file-error (setq failure t)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
527 (unless failure
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
528 (when (rassoc x thumbs-file-list)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
529 (goto-char (car (rassoc x thumbs-file-list)))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
530 (delete-region (point) (1+ (point))))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
531 (setq thumbs-marked-list
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
532 (delq x thumbs-marked-list)))))))))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
533
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
534 (defun thumbs-rename-images (newfile)
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
535 "Rename the image at point (and its thumbnail) (or marked files if any)."
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
536 (interactive "FRename to file or directory: ")
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
537 (let ((files (or thumbs-marked-list (list (thumbs-current-image))))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
538 failures)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
539 (if (and (not (file-directory-p newfile))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
540 thumbs-marked-list)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
541 (if (file-exists-p newfile)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
542 (error "Renaming marked files to file name `%s'" newfile)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
543 (make-directory newfile t)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
544 (if (yes-or-no-p (format "Really rename %d files? " (length files)))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
545 (let ((thumbs-file-list (thumbs-file-alist))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
546 (inhibit-read-only t))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
547 (dolist (file files)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
548 (let (failure)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
549 (condition-case ()
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
550 (if (file-directory-p newfile)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
551 (rename-file file
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
552 (expand-file-name
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
553 (file-name-nondirectory file)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
554 newfile))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
555 (rename-file file newfile))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
556 (file-error (setq failure t)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
557 (push file failures)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
558 (unless failure
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
559 (when (rassoc file thumbs-file-list)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
560 (goto-char (car (rassoc file thumbs-file-list)))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
561 (delete-region (point) (1+ (point))))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
562 (setq thumbs-marked-list
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
563 (delq file thumbs-marked-list)))))))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
564 (if failures
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
565 (display-warning 'file-error
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
566 (format "Rename failures for %s into %s"
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
567 failures newfile)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
568 :error))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (defun thumbs-kill-buffer ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 "Kill the current buffer."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (interactive)
63155
911109216331 Don't set `auto-image-file-mode'. Do not create the thumbnails directory on
Juanma Barranquero <lekktu@gmail.com>
parents: 63078
diff changeset
573 (quit-window t (selected-window)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (defun thumbs-show-image-num (num)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 "Show the image with number NUM."
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
577 (let ((image-buffer (get-buffer-create "*Image*")))
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
578 (let ((img (cdr (nth (1- num) (thumbs-file-alist)))))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
579 (with-current-buffer image-buffer
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
580 (setq mode-name
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
581 (concat "image-view-mode: " (file-name-nondirectory img)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
582 " - " (number-to-string num)))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
583 (let ((inhibit-read-only t))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
584 (erase-buffer)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
585 (thumbs-insert-image img (thumbs-image-type img) 0)
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
586 (goto-char (point-min))))
55213
a911edb6dadf (thumbs-delete-images): Fix formatting of prompt.
John Paul Wallington <jpw@pobox.com>
parents: 55206
diff changeset
587 (setq thumbs-image-num num
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
588 thumbs-current-image-filename img))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
590 (defun thumbs-previous-image ()
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
591 "Show the previous image."
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
592 (interactive)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
593 (let* ((i (- thumbs-image-num 1))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
594 (number (length (thumbs-file-alist))))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
595 (if (= i 0) (setq i (1- number)))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
596 (thumbs-show-image-num i)))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
597
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (defun thumbs-next-image ()
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
599 "Show the next image."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (let* ((i (1+ thumbs-image-num))
68289
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
602 (number (length (thumbs-file-alist))))
be0164ac55f8 (thumbs-buffer): New variable. Make it buffer local.
Nick Roberts <nickrob@snap.net.nz>
parents: 66568
diff changeset
603 (if (= i number) (setq i 1))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
604 (thumbs-show-image-num i)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
606 (defun thumbs-display-thumbs-buffer ()
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
607 "Display the associated thumbs buffer."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (interactive)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
609 (display-buffer thumbs-buffer))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (defun thumbs-redraw-buffer ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 "Redraw the current thumbs buffer."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (let ((p (point))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
614 (inhibit-read-only t)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
615 (files (thumbs-file-list)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
616 (erase-buffer)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
617 (thumbs-do-thumbs-insertion files)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
618 (goto-char p)))
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
619
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 (defun thumbs-mark ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 "Mark the image at point."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (interactive)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
623 (let ((elt (thumbs-current-image)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
624 (unless elt
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
625 (error "No image here"))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
626 (push elt thumbs-marked-list)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
627 (let ((inhibit-read-only t))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
628 (delete-char 1)
68409
7ca2eae4cee2 (thumbs-do-thumbs-insertion): Suppress message when
Nick Roberts <nickrob@snap.net.nz>
parents: 68373
diff changeset
629 (thumbs-insert-thumb elt t)))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
630 (when (eolp) (forward-char)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
631
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
632 (defun thumbs-unmark ()
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
633 "Unmark the image at point."
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
634 (interactive)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
635 (let ((elt (thumbs-current-image)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
636 (unless elt
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
637 (error "No image here"))
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
638 (setq thumbs-marked-list (delete elt thumbs-marked-list))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
639 (let ((inhibit-read-only t))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
640 (delete-char 1)
68409
7ca2eae4cee2 (thumbs-do-thumbs-insertion): Suppress message when
Nick Roberts <nickrob@snap.net.nz>
parents: 68373
diff changeset
641 (thumbs-insert-thumb elt nil)))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
642 (when (eolp) (forward-char)))
55206
c2c29cafaa74 (time-less-p): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 54193
diff changeset
643
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
644 ;; cleaning of old temp files
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
645 (mapc 'delete-file
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
646 (directory-files (thumbs-temp-dir) t thumbs-temp-prefix))
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
647
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 ;; Image modification routines
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 (defun thumbs-modify-image (action &optional arg)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 "Call convert to do ACTION on image with argument ARG.
60920
242e5edee3ce * complete.el, thumbs.el: Replace `legal' with `valid'.
Werner LEMBERG <wl@gnu.org>
parents: 59996
diff changeset
652 ACTION and ARG should be a valid convert command."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (interactive "sAction: \nsValue: ")
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
654 (let* ((buffer-read-only nil)
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
655 (old thumbs-current-tmp-filename)
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
656 (tmp (thumbs-temp-file)))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (erase-buffer)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
658 (thumbs-call-convert (or old thumbs-current-image-filename)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 tmp
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 action
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (or arg ""))
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
662 (save-excursion
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
663 (thumbs-insert-image tmp 'jpeg 0))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (setq thumbs-current-tmp-filename tmp)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 (defun thumbs-emboss-image (emboss)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 "Emboss the image with value EMBOSS."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (interactive "nEmboss value: ")
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
669 (if (or (< emboss 3) (> emboss 31) (zerop (% emboss 2)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
670 (error "Arg must be an odd number between 3 and 31"))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (thumbs-modify-image "emboss" (number-to-string emboss)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (defun thumbs-monochrome-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 "Turn the image to monochrome."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (thumbs-modify-image "monochrome"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 (defun thumbs-negate-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 "Negate the image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 (thumbs-modify-image "negate"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 (defun thumbs-rotate-left ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 "Rotate the image 90 degrees counter-clockwise."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (thumbs-modify-image "rotate" "270"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (defun thumbs-rotate-right ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 "Rotate the image 90 degrees clockwise."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (thumbs-modify-image "rotate" "90"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
693 (defun thumbs-current-image ()
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
694 "Return the name of the image file name at point."
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
695 (get-text-property (point) 'thumb-image-file))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
696
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (defun thumbs-forward-char ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 "Move forward one image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (forward-char)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
701 (while (and (not (eobp)) (not (thumbs-current-image)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
702 (forward-char))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (thumbs-show-name))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 (defun thumbs-backward-char ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 "Move backward one image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (forward-char -1)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
709 (while (and (not (bobp)) (not (thumbs-current-image)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
710 (forward-char -1))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (thumbs-show-name))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
713 (defun thumbs-backward-line ()
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
714 "Move up one line."
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
715 (interactive)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
716 (forward-line -1)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
717 (thumbs-show-name))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
718
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (defun thumbs-forward-line ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 "Move down one line."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (forward-line 1)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (thumbs-show-name))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
725 (defun thumbs-show-more-images (&optional arg)
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
726 "Show more than `thumbs-max-image-number' images, if present."
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
727 (interactive "P")
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
728 (or arg (setq arg 1))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
729 (setq thumbs-extra-images (+ thumbs-extra-images arg))
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
730 (thumbs-dired-show))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (defun thumbs-show-name ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 "Show the name of the current file."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (interactive)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
735 (let ((f (thumbs-current-image)))
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
736 (and f (message "%s [%s]" f (thumbs-file-size f)))))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (defun thumbs-save-current-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 "Save the current image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 (let ((f (or thumbs-current-tmp-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 thumbs-current-image-filename))
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
743 (sa (read-from-minibuffer "Save image file as: "
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 thumbs-current-image-filename)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (copy-file f sa)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 (defun thumbs-dired ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 "Use `dired' on the current thumbs directory."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (dired thumbs-current-dir))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 ;; thumbs-mode
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (defvar thumbs-mode-map
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (let ((map (make-sparse-keymap)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 (define-key map [return] 'thumbs-find-image-at-point)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
757 (define-key map [mouse-2] 'thumbs-mouse-find-image)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (define-key map [(meta return)] 'thumbs-find-image-at-point-other-window)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (define-key map [(control return)] 'thumbs-set-image-at-point-to-root-window)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (define-key map [delete] 'thumbs-delete-images)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (define-key map [right] 'thumbs-forward-char)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (define-key map [left] 'thumbs-backward-char)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (define-key map [up] 'thumbs-backward-line)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (define-key map [down] 'thumbs-forward-line)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
765 (define-key map "+" 'thumbs-show-more-images)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (define-key map "d" 'thumbs-dired)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 (define-key map "m" 'thumbs-mark)
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
768 (define-key map "u" 'thumbs-unmark)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
769 (define-key map "R" 'thumbs-rename-images)
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
770 (define-key map "x" 'thumbs-delete-images)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (define-key map "s" 'thumbs-show-name)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (define-key map "q" 'thumbs-kill-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 map)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 "Keymap for `thumbs-mode'.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
776 (put 'thumbs-mode 'mode-class 'special)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 (define-derived-mode thumbs-mode
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 fundamental-mode "thumbs"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 "Preview images in a thumbnails buffer"
68486
6511ba48ed7a (thumbs-marked-list): Make buffer-local and
Nick Roberts <nickrob@snap.net.nz>
parents: 68409
diff changeset
780 (setq buffer-read-only t))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 (defvar thumbs-view-image-mode-map
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 (let ((map (make-sparse-keymap)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 (define-key map [prior] 'thumbs-previous-image)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (define-key map [next] 'thumbs-next-image)
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
786 (define-key map "^" 'thumbs-display-thumbs-buffer)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
787 (define-key map "-" 'thumbs-shrink-image)
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
788 (define-key map "+" 'thumbs-enlarge-image)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 (define-key map "<" 'thumbs-rotate-left)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (define-key map ">" 'thumbs-rotate-right)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (define-key map "e" 'thumbs-emboss-image)
68373
3bff02a6d438 (thumbs-new-image-size): New function.
Nick Roberts <nickrob@snap.net.nz>
parents: 68362
diff changeset
792 (define-key map "r" 'thumbs-resize-image)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 (define-key map "s" 'thumbs-save-current-image)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 (define-key map "q" 'thumbs-kill-buffer)
56934
ff141f26a0cb (thumbs-view-image-mode-map): Fix `thumbs-set-root' command name typo.
John Paul Wallington <jpw@pobox.com>
parents: 55827
diff changeset
795 (define-key map "w" 'thumbs-set-root)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 map)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 "Keymap for `thumbs-view-image-mode'.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 ;; thumbs-view-image-mode
55827
c5c73c8c2b3e Don't include cl. Don't bother with old Emacs versions.
Richard M. Stallman <rms@gnu.org>
parents: 55221
diff changeset
800 (put 'thumbs-view-image-mode 'mode-class 'special)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 (define-derived-mode thumbs-view-image-mode
56934
ff141f26a0cb (thumbs-view-image-mode-map): Fix `thumbs-set-root' command name typo.
John Paul Wallington <jpw@pobox.com>
parents: 55827
diff changeset
802 fundamental-mode "image-view-mode"
ff141f26a0cb (thumbs-view-image-mode-map): Fix `thumbs-set-root' command name typo.
John Paul Wallington <jpw@pobox.com>
parents: 55827
diff changeset
803 (setq buffer-read-only t))
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 (defun thumbs-dired-setroot ()
62692
6dd34b690fa9 (thumbs-thumbsdir-max-size, thumbs-temp-file, thumbs-cleanup-thumbsdir,
Juanma Barranquero <lekktu@gmail.com>
parents: 60920
diff changeset
807 "In dired, call the setroot program on the image at point."
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (thumbs-call-setroot-command (dired-get-filename)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 ;; Modif to dired mode map
68362
3b10b20b3387 (thumbs-extra-images): New variable. Make it buffer-local
Nick Roberts <nickrob@snap.net.nz>
parents: 68340
diff changeset
812 (define-key dired-mode-map "\C-ta" 'thumbs-dired-show)
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 (define-key dired-mode-map "\C-tm" 'thumbs-dired-show-marked)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 (define-key dired-mode-map "\C-tw" 'thumbs-dired-setroot)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (provide 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817
62927
bb23fe0bf1d3 (thumbs-mode): Fix misuse of make-variable-buffer-local.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 62891
diff changeset
818 ;; arch-tag: f9ac1ef8-83fc-42c0-8069-1fae43fd2e5c
54186
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 ;;; thumbs.el ends here