annotate lisp/thumbs.el @ 54955:80952abb48b0

*** empty log message ***
author John Wiegley <johnw@newartisans.com>
date Sat, 17 Apr 2004 22:02:45 +0000
parents 318542a275c4
children c2c29cafaa74
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
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Author: Jean-Philippe Theberge <jphiltheberge@videotron.ca>
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Thanks: Alex Schroeder <alex@gnu.org> for maintaining the package at some time
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; The peoples at #emacs@freenode.net for numerous help
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; RMS for emacs and the GNU project.
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 ;; Keywords: Multimedia
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 (defconst thumbs-version "2.0")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; 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
17 ;; the Free Software Foundation; either version 2, or (at your option)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; any later version.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; GNU General Public License for more details.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Boston, MA 02111-1307, USA.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Commentary:
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; This package create two new mode: thumbs-mode and
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; thumbs-view-image-mode. It is used for images browsing and viewing
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; from within emacs. Minimal image manipulation functions are also
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; available via external programs.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; The 'convert' program from 'ImageMagick'
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; [URL:http://www.imagemagick.org/] is required.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; CHANGELOG
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; This is version 2.0
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 ;; USAGE
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 ;; 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
48 ;; That should be a directory containing image files.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; 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
50 ;; C-t a enter in thumbs-mode with all files in current-directory
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; In thumbs-mode, pressing <return> on a image will bring you in image view mode
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; for that image. C-h m will give you a list of available keybinding.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; History:
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
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; Code:
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 (require 'dired)
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 ;; Abort if in-line imaging isn't supported (i.e. Emacs-20.7)
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 (when (not (display-images-p))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (error "Your Emacs version (%S) doesn't support in-line images,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 was not compiled with image support or is run in console mode.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 Upgrade to Emacs 21.1 or newer, compile it with image support
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 or use a window-system"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 emacs-version))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; CUSTOMIZATIONS
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (defgroup thumbs nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 "Thumbnails previewer."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 :group 'multimedia)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (defcustom thumbs-thumbsdir
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (expand-file-name "~/.emacs-thumbs")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "*Directory to store thumbnails."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 :type 'directory
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (defcustom thumbs-geometry "100x100"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 "*Size of thumbnails."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (defcustom thumbs-per-line 5
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 "*Number of thumbnails per line to show in directory."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defcustom thumbs-thumbsdir-max-size 50000000
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "Max size for thumbnails directory.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 When it reach that size (in bytes), a warning is send."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defcustom thumbs-conversion-program
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (if (equal 'windows-nt system-type)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "convert.exe"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (or (executable-find "convert")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "/usr/X11R6/bin/convert"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 "*Name of conversion program for thumbnails generation.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 It must be 'convert'."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defcustom thumbs-setroot-command
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "xloadimage -onroot -fullscreen *"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 "Command to set the root window."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (defcustom thumbs-relief 5
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 "*Size of button-like border around thumbnails."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defcustom thumbs-margin 2
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "*Size of the margin around thumbnails.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 This is where you see the cursor."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (defcustom thumbs-thumbsdir-auto-clean t
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 "If set, delete older file in the thumbnails directory.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 Deletion is done at load time when the directory size is bigger
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 than 'thumbs-thumbsdir-max-size'."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 :type 'boolean
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (defcustom thumbs-image-resizing-step 10
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 "Step by wich to resize image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (defcustom thumbs-temp-dir
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 "/tmp/"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 "Temporary directory to use.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 Leaving it to default '/tmp/' can let another user
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 see some of your images."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 :type 'directory
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (defcustom thumbs-temp-prefix "emacsthumbs"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 "Prefix to add to temp files."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 :type 'string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 :group 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; Initialize some variable, for later use.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defvar thumbs-temp-file
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (concat thumbs-temp-dir thumbs-temp-prefix)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 "Temporary filesname for images.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (defvar thumbs-current-tmp-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 "Temporary filename of current image.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (defvar thumbs-current-image-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 "Filename of current image.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defvar thumbs-current-image-size
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 "Size of current image.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defvar thumbs-image-num
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 "Number of current image.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (defvar thumbs-current-dir
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 "Current directory.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defvar thumbs-markedL
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 "List of marked files.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; Make sure auto-image-file-mode is ON.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (auto-image-file-mode t)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;; Create the thumbs directory if it does not exists.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (setq thumbs-thumbsdir (expand-file-name thumbs-thumbsdir))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (when (not (file-directory-p thumbs-thumbsdir))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (progn
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (make-directory thumbs-thumbsdir)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (message "Creating thumbnails directory")))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (when (not (fboundp 'ignore-errors))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defmacro ignore-errors (&rest body)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 "Execute FORMS; if anz error occurs, return nil.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 Otherwise, return result of last FORM."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (let ((err (thumbs-gensym)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (list 'condition-case err (cons 'progn body) '(error nil)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (when (not (fboundp 'time-less-p))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (defun time-less-p (t1 t2)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 "Say whether time T1 is less than time T2."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (or (< (car t1) (car t2))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (and (= (car t1) (car t2))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (< (nth 1 t1) (nth 1 t2))))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (when (not (fboundp 'caddar))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (defun caddar (x)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 "Return the `car' of the `cdr' of the `cdr' of the `car' of X."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (car (cdr (cdr (car x))))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defvar thumbs-gensym-counter 0)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (defun thumbs-gensym (&optional arg)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 "Generate a new uninterned symbol.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 The name is made by appending a number to PREFIX, default \"Thumbs\"."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (let ((prefix (if (stringp arg) arg "Thumbs"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (num (if (integerp arg) arg
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (prog1
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 thumbs-gensym-counter
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (setq thumbs-gensym-counter (1+ thumbs-gensym-counter))))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (make-symbol (format "%s%d" prefix num))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defun thumbs-cleanup-thumbsdir ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 "Clean the thumbnails directory.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 If the total size of all files in 'thumbs-thumbsdir' is bigger than
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 'thumbs-thumbsdir-max-size', files are deleted until the max size is
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 reached."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (let* ((filesL
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (sort
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (mapcar
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (lambda (f)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (let ((fattribsL (file-attributes f)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 `(,(nth 4 fattribsL) ,(nth 7 fattribsL) ,f)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (directory-files thumbs-thumbsdir t (image-file-name-regexp)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 '(lambda (l1 l2) (time-less-p (car l1)(car l2)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (dirsize (apply '+ (mapcar (lambda (x) (cadr x)) filesL))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (while (> dirsize thumbs-thumbsdir-max-size)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (progn
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (message "Deleting file %s" (caddar filesL)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (delete-file (caddar filesL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (setq dirsize (- dirsize (cadar filesL)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (setq filesL (cdr filesL)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ;; Check the thumbsnail directory size and clean it if necessary.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (when thumbs-thumbsdir-auto-clean
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (thumbs-cleanup-thumbsdir))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (defun thumbs-call-convert (filein fileout action
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 &optional arg output-format action-prefix)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 "Call the convert program.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 FILEIN is the input file,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 FILEOUT is the output file,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ACTION is the command to send to convert.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 Optional argument are:
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ARG any arguments to the ACTION command,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 OUTPUT-FORMAT is the file format to output, default is jpeg
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ACTION-PREFIX is the symbol to place before the ACTION command
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (default to '-' but can sometime be '+')."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (let ((command (format "%s %s%s %s \"%s\" \"%s:%s\""
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 thumbs-conversion-program
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (or action-prefix "-")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 action
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (or arg "")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 filein
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (or output-format "jpeg")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 fileout)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (shell-command command)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun thumbs-increment-image-size-element (n d)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 "Increment number N by D percent."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (round (+ n (/ (* d n) 100))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (defun thumbs-decrement-image-size-element (n d)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 "Decrement number N by D percent."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (round (- n (/ (* d n) 100))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (defun thumbs-increment-image-size (s)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 "Increment S (a cons of width x heigh)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (cons
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (thumbs-increment-image-size-element (car s)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 thumbs-image-resizing-step)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (thumbs-increment-image-size-element (cdr s)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 thumbs-image-resizing-step)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (defun thumbs-decrement-image-size (s)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 "Decrement S (a cons of width x heigh)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (cons
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (thumbs-decrement-image-size-element (car s)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 thumbs-image-resizing-step)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (thumbs-decrement-image-size-element (cdr s)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 thumbs-image-resizing-step)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (defun thumbs-resize-image (&optional increment size)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 "Resize image in current buffer.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 if INCREMENT is set, make the image bigger, else smaller.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 Or, alternatively, a SIZE may be specified."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 ;; cleaning of old temp file
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (ignore-errors
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (apply 'delete-file
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (directory-files
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 thumbs-temp-dir t
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 thumbs-temp-prefix)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (let ((buffer-read-only nil)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (x (if size
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 size
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (if increment
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (thumbs-increment-image-size
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 thumbs-current-image-size)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (thumbs-decrement-image-size
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 thumbs-current-image-size))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (erase-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (thumbs-call-convert thumbs-current-image-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 tmp "sample"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (concat (number-to-string (car x)) "x"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (number-to-string (cdr x))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (thumbs-insert-image tmp 'jpeg 0)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (setq thumbs-current-tmp-filename tmp)))
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-resize-interactive (width height)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 "Resize Image interactively to specified WIDTH and HEIGHT."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (interactive "nWidth: \nnHeight: ")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (thumbs-resize-image nil (cons width height)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (defun thumbs-resize-image-size-down ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 "Resize image (smaller)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (thumbs-resize-image nil))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (defun thumbs-resize-image-size-up ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 "Resize image (bigger)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (thumbs-resize-image t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (defun thumbs-subst-char-in-string (orig rep string)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 "Replace occurrences of character ORIG with character REP in STRING.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 Return the resulting (new) string. -- (defun borowed to Dave Love)"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (let ((string (copy-sequence string))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (l (length string))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (i 0))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (while (< i l)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (if (= (aref string i) orig)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (aset string i rep))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (setq i (1+ i)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 string))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (defun thumbs-thumbname (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 "Return a thumbnail name for the image IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (concat thumbs-thumbsdir "/"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (thumbs-subst-char-in-string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 ?\ ?\_
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (apply
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 'concat
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (split-string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (expand-file-name img) "/")))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (defun thumbs-make-thumb (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 "Create the thumbnail for IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (let* ((fn (expand-file-name img))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (tn (thumbs-thumbname img)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (if (or (not (file-exists-p tn))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (not (equal (thumbs-file-size tn) thumbs-geometry)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (thumbs-call-convert fn tn "sample" thumbs-geometry))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 tn))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (defun thumbs-image-type (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 "Return image type from filename IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (cond ((string-match ".*\\.jpe?g\\'" img) 'jpeg)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 ((string-match ".*\\.xpm\\'" img) 'xpm)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 ((string-match ".*\\.xbm\\'" img) 'xbm)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 ((string-match ".*\\.gif\\'" img) 'gif)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 ((string-match ".*\\.bmp\\'" img) 'bmp)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 ((string-match ".*\\.png\\'" img) 'png)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 ((string-match ".*\\.tiff?\\'" img) 'tiff)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (defun thumbs-file-size (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (let ((i (image-size (find-image `((:type ,(thumbs-image-type img) :file ,img))) t)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (concat (number-to-string (round (car i)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 "x"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (number-to-string (round (cdr i))))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (defun thumbs-find-thumb (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 "Display the thumbnail for IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (interactive "f")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (find-file (thumbs-make-thumb img)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (defun thumbs-insert-image (img type relief &optional marked)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 "Insert image IMG at point.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 TYPE and RELIEF will be used in constructing the image; see `image'
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 in the emacs-lisp manual for further documentation.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 if MARKED is non-nil, the image is marked."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (let ((i `(image :type ,type
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 :file ,img
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 :relief ,relief
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 :conversion ,(if marked 'disabled)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 :margin ,thumbs-margin)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (insert-image i)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (setq thumbs-current-image-size
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (image-size i t))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (defun thumbs-insert-thumb (img &optional marked)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 "Insert the thumbnail for IMG at point.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 if MARKED is non-nil, the image is marked"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (thumbs-insert-image
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (thumbs-make-thumb img) 'jpeg thumbs-relief marked))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (defun thumbs-do-thumbs-insertion (L)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 "Insert all thumbs in list L."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (setq thumbs-fileL nil)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (let ((i 0))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (while L
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (when (= 0 (mod (setq i (1+ i)) thumbs-per-line))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (newline))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (setq thumbs-fileL (cons (cons (point)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (car L))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 thumbs-fileL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (thumbs-insert-thumb (car L)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (member (car L) thumbs-markedL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (setq L (cdr L)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (defun thumbs-show-thumbs-list (L &optional buffer-name same-window)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (funcall (if same-window 'switch-to-buffer 'pop-to-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (or buffer-name "*THUMB-View*"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (let ((inhibit-read-only t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (erase-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (thumbs-mode)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (make-variable-buffer-local 'thumbs-fileL)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq thumbs-fileL nil)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (thumbs-do-thumbs-insertion L)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (goto-char (point-min))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (setq thumbs-current-dir default-directory)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (make-variable-buffer-local 'thumbs-current-dir)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (defun thumbs-show-all-from-dir (dir &optional reg same-window)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 "Make a preview buffer for all images in DIR.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 Optional argument REG to select file matching a regexp,
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 and SAME-WINDOW to show thumbs in the same window."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (interactive "DDir: ")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (thumbs-show-thumbs-list
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (directory-files dir t
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (or reg (image-file-name-regexp)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (concat "*Thumbs: " dir) same-window))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (defun thumbs-dired-show-marked ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 "In Dired, make a thumbs buffer with all marked files."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (thumbs-show-thumbs-list (dired-get-marked-files) nil t))
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 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (defun thumbs-dired-show-all ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 "In dired, make a thumbs buffer with all files in current directory."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (thumbs-show-all-from-dir default-directory nil t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (defalias 'thumbs 'thumbs-show-all-from-dir)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (defun thumbs-find-image (img L &optional num otherwin)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (funcall
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (if otherwin 'switch-to-buffer-other-window 'switch-to-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (concat "*Image: " (file-name-nondirectory img) " - "
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (number-to-string (or num 0)) "*"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (thumbs-view-image-mode)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (let ((inhibit-read-only t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (setq thumbs-current-image-filename img
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 thumbs-current-tmp-filename nil
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 thumbs-image-num (or num 0))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (make-variable-buffer-local 'thumbs-current-image-filename)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (make-variable-buffer-local 'thumbs-current-tmp-filename)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (make-variable-buffer-local 'thumbs-current-image-size)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (make-variable-buffer-local 'thumbs-image-num)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (make-variable-buffer-local 'thumbs-fileL)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (setq thumbs-fileL L)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (delete-region (point-min)(point-max))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (thumbs-insert-image img (thumbs-image-type img) 0)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (defun thumbs-find-image-at-point (&optional img otherwin)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 "Display image IMG for thumbnail at point.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 use another window it OTHERWIN is t."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (let* ((L thumbs-fileL)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (n (point))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (i (or img (cdr (assoc n L)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (thumbs-find-image i L n otherwin)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (defun thumbs-find-image-at-point-other-window ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 "Display image for thumbnail at point in the preview buffer.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 Open another window."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (thumbs-find-image-at-point nil t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (defun thumbs-call-setroot-command (img)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 "Call the setroot program for IMG."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (run-hooks 'thumbs-before-setroot-hook)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (shell-command (replace-regexp-in-string
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 "\\*"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (shell-quote-argument (expand-file-name img))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 thumbs-setroot-command nil t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (run-hooks 'thumbs-after-setroot-hook))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (defun thumbs-set-image-at-point-to-root-window ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "Set the image at point as the desktop wallpaper."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (thumbs-call-setroot-command (cdr (assoc (point) thumbs-fileL))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (defun thumbs-set-root ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 "Set the current image as root."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (thumbs-call-setroot-command
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (or thumbs-current-tmp-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 thumbs-current-image-filename)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (defun thumbs-delete-images ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 "Delete the image at point (and it's thumbnail) (or marked files if any)."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (let ((f (or thumbs-markedL (list (cdr (assoc (point) thumbs-fileL))))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (if (yes-or-no-p "Really delete %d files?" (length f))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (progn
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (mapcar (lambda (x)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (setq thumbs-fileL (delete (rassoc x thumbs-fileL) thumbs-fileL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (delete-file x)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (delete-file (thumbs-thumbname x))) f)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (thumbs-redraw-buffer)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (defun thumbs-kill-buffer ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 "Kill the current buffer."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (let ((buffer (current-buffer)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (ignore-errors (delete-window (selected-window)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (kill-buffer buffer)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (defun thumbs-show-image-num (num)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 "Show the image with number NUM."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (let ((inhibit-read-only t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (delete-region (point-min)(point-max))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (let ((i (cdr (assoc num thumbs-fileL))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (thumbs-insert-image i (thumbs-image-type i) 0)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (sleep-for 2)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (rename-buffer (concat "*Image: "
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (file-name-nondirectory i)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 " - "
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (number-to-string num) "*")))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (setq thumbs-image-num num
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 thumbs-current-image-filename i)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 (defun thumbs-next-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 "Show next image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (let* ((i (1+ thumbs-image-num))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (l (caar thumbs-fileL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (num
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (cond ((assoc i thumbs-fileL) i)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 ((>= i l) 1)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (t (1+ i)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (thumbs-show-image-num num)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (defun thumbs-previous-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 "Show the previous image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (let* ((i (- thumbs-image-num 1))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (l (caar thumbs-fileL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (num
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (cond ((assoc i thumbs-fileL) i)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 ((<= i 1) l)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (t (- i 1)))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (thumbs-show-image-num num)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (defun thumbs-redraw-buffer ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 "Redraw the current thumbs buffer."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (let ((p (point))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (inhibit-read-only t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 (delete-region (point-min)(point-max))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (thumbs-do-thumbs-insertion (reverse (mapcar 'cdr thumbs-fileL)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (goto-char (1+ p))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (defun thumbs-mark ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 "Mark the image at point."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (setq thumbs-markedL (cons (cdr (assoc (point) thumbs-fileL)) thumbs-markedL))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (let ((inhibit-read-only t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (delete-char 1)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (thumbs-insert-thumb (cdr (assoc (point) thumbs-fileL)) t))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 (when (eolp)(forward-char)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 ;; Image modification routines
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (defun thumbs-modify-image (action &optional arg)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 "Call convert to do ACTION on image with argument ARG.
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 ACTION and ARG should be legal convert command."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (interactive "sAction: \nsValue: ")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 ;; cleaning of old temp file
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (mapc 'delete-file
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (directory-files
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 thumbs-temp-dir
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 t
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 thumbs-temp-prefix))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (let ((buffer-read-only nil)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (tmp (format "%s%s.jpg" thumbs-temp-file (thumbs-gensym))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (erase-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (thumbs-call-convert thumbs-current-image-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 tmp
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 action
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (or arg ""))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (thumbs-insert-image tmp 'jpeg 0)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (setq thumbs-current-tmp-filename tmp)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 (defun thumbs-emboss-image (emboss)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 "Emboss the image with value EMBOSS."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (interactive "nEmboss value: ")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (if (or (< emboss 3)(> emboss 31)(evenp emboss))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (error "Arg must be a odd number between 3 and 31"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (thumbs-modify-image "emboss" (number-to-string emboss)))
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-monochrome-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 "Turn the image to monochrome."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 (thumbs-modify-image "monochrome"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 (defun thumbs-negate-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 "Negate the image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (thumbs-modify-image "negate"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (defun thumbs-rotate-left ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 "Rotate the image 90 degrees counter-clockwise."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (thumbs-modify-image "rotate" "270"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (defun thumbs-rotate-right ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 "Rotate the image 90 degrees clockwise."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 (thumbs-modify-image "rotate" "90"))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (defun thumbs-forward-char ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 "Move forward one image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (forward-char)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 (when (eolp)(forward-char))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (thumbs-show-name))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (defun thumbs-backward-char ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 "Move backward one image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 (forward-char -1)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (thumbs-show-name))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (defun thumbs-forward-line ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 "Move down one line."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 (forward-line 1)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 (thumbs-show-name))
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-backward-line ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 "Move up one line."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (forward-line -1)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (thumbs-show-name))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (defun thumbs-show-name ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 "Show the name of the current file."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (let ((f (cdr (assoc (point) thumbs-fileL))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (message "%s [%s]" f (thumbs-file-size f))))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (defun thumbs-save-current-image ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 "Save the current image."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (let ((f (or thumbs-current-tmp-filename
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 thumbs-current-image-filename))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (sa (read-from-minibuffer "save file as: "
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 thumbs-current-image-filename)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (copy-file f sa)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (defun thumbs-dired ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 "Use `dired' on the current thumbs directory."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (dired thumbs-current-dir))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 ;; thumbs-mode
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 (defvar thumbs-mode-map
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (let ((map (make-sparse-keymap)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (define-key map [return] 'thumbs-find-image-at-point)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 (define-key map [(meta return)] 'thumbs-find-image-at-point-other-window)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (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
683 (define-key map [delete] 'thumbs-delete-images)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (define-key map [right] 'thumbs-forward-char)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (define-key map [left] 'thumbs-backward-char)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (define-key map [up] 'thumbs-backward-line)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (define-key map [down] 'thumbs-forward-line)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (define-key map "d" 'thumbs-dired)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (define-key map "m" 'thumbs-mark)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (define-key map "s" 'thumbs-show-name)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (define-key map "q" 'thumbs-kill-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 map)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 "Keymap for `thumbs-mode'.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (define-derived-mode thumbs-mode
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 fundamental-mode "thumbs"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 "Preview images in a thumbnails buffer"
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 (make-variable-buffer-local 'thumbs-markedL)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (setq thumbs-markedL nil))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 (defvar thumbs-view-image-mode-map
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (let ((map (make-sparse-keymap)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (define-key map [prior] 'thumbs-previous-image)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 (define-key map [next] 'thumbs-next-image)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 (define-key map "-" 'thumbs-resize-image-size-down)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (define-key map "+" 'thumbs-resize-image-size-up)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (define-key map "<" 'thumbs-rotate-left)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (define-key map ">" 'thumbs-rotate-right)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (define-key map "e" 'thumbs-emboss-image)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (define-key map "r" 'thumbs-resize-interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (define-key map "s" 'thumbs-save-current-image)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 (define-key map "q" 'thumbs-kill-buffer)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (define-key map "w" 'thunbs-set-root)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 map)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 "Keymap for `thumbs-view-image-mode'.")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 ;; thumbs-view-image-mode
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (define-derived-mode thumbs-view-image-mode
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 fundamental-mode "image-view-mode")
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 ;;;###autoload
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 (defun thumbs-dired-setroot ()
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 "In dired, Call the setroot program on the image at point."
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (interactive)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (thumbs-call-setroot-command (dired-get-filename)))
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 ;; Modif to dired mode map
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (define-key dired-mode-map "\C-ta" 'thumbs-dired-show-all)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 (define-key dired-mode-map "\C-tm" 'thumbs-dired-show-marked)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (define-key dired-mode-map "\C-tw" 'thumbs-dired-setroot)
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 (provide 'thumbs)
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 ;;; thumbs.el ends here
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735
5d76d17025c5 New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736
54193
318542a275c4 Resolve CVS conflicts
Miles Bader <miles@gnu.org>
parents: 54186
diff changeset
737 ;;; arch-tag: f9ac1ef8-83fc-42c0-8069-1fae43fd2e5c