1 ;;; gimpedit.el --- Edit files with GIMP
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: Wed May 23 14:59:50 2007
5 (defconst gimpedit:version "0.31") ;;Version:
6 ;; Last-Updated: 2009-11-03 Tue
11 ;; Features that might be required by this library:
13 ;; `setup-helper', `w32-reg-iface', `w32-regdat'.
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; Simple interface to start editing with GIMP.
21 ;; If you want to edit files from within Emacs see the doc string of
22 ;; `gimpedit-edit-buffer'.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 ;; This program is free software; you can redistribute it and/or
32 ;; modify it under the terms of the GNU General Public License as
33 ;; published by the Free Software Foundation; either version 2, or
34 ;; (at your option) any later version.
36 ;; This program is distributed in the hope that it will be useful,
37 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
38 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 ;; General Public License for more details.
41 ;; You should have received a copy of the GNU General Public License
42 ;; along with this program; see the file COPYING. If not, write to
43 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
44 ;; Floor, Boston, MA 02110-1301, USA.
46 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 (eval-and-compile (require 'w32-regdat nil t))
52 ;; (message "%S" (gimpedit-get-remote-command))
53 (defun gimpedit-get-remote-command ()
54 (if (featurep 'w32-regdat)
56 (let ((cmd (w32-regdat-gimp-win-remote-cmd))
58 (while (< 0 (length cmd))
60 ((or (string-match (rx string-start
67 (string-match (rx string-start
69 (0+ (not (any space))))
72 (setq cmd-list (cons (match-string-no-properties 1 cmd) cmd-list))
73 (setq cmd (substring cmd (match-end 0))))))
75 (if (memq system-type '(windows-nt))
78 (dolist (num '(2 3 4 5 6 7 8 9))
79 (setq prog (concat (getenv "ProgramFiles")
80 "\\GIMP-2.0\\bin\\gimp-2."
81 (number-to-string num)
83 (when (file-exists-p prog)
84 (throw 'found-prog prog)))))
88 (defgroup gimpedit nil
89 "Customization group for GIMP."
93 (defcustom gimpedit-remote-command (gimpedit-get-remote-command)
94 "Program name to use when calling GIMP remotely.
95 This could be be the full path to the program used when opening
96 files with GIMP or a just the program file name if it is in the
101 The value is fetched from the registry on MS Windows if
102 possible or is else given the default value:
104 \"C:\\Program Files\\GIMP-2.0\\bin\\gimp-2.6.exe\"
106 On other system it has the default value
109 :type '(choice (file :tag "Full file name" :must-match t)
110 (string :tag "File name (must be in path)"))
114 (defun gimpedit-edit-file (image-file &optional extra-args)
115 "Edit IMAGE-FILE with GIMP.
116 See also `gimpedit-edit-file'."
117 (interactive (list (or (get-char-property (point) 'image-file)
118 (read-file-name "Image to edit in GIMP: "))))
119 (setq image-file (expand-file-name image-file))
120 (apply 'call-process gimpedit-remote-command
124 (reverse (cons image-file (reverse extra-args))))
125 (let ((msg " Asked GIMP to open %s - you may have to switch to GIMP"))
126 (put-text-property 0 (length msg) 'face 'highlight msg)
127 (message msg (file-name-nondirectory image-file))))
130 (defun gimpedit-edit-buffer ()
131 "Edit image file in current buffer with GIMP.
132 See also `gimpedit-edit-file'.
134 You may also be interested in gimpedit-mode with which you can edit
135 gimp files from within Emacs using GIMP's scripting
138 URL `http://www.emacswiki.org/emacs/GimpMode'"
140 (unless (buffer-file-name)
142 "Can't edit in GIMP because this buffer does not have a file name."))
143 (gimpedit-edit-file (buffer-file-name)))
146 (defun gimpedit-can-edit (file-name)
148 (member (downcase (file-name-extension file-name))
149 '("png" "gif" "jpg" "jpeg"))))
151 ;; (defcustom gimpedit-point-key-bindings '(([(control ?c) ?&] gimpedit-edit-file))
152 ;; "Key bindings suggested for image links etc."
153 ;; :type '(repeat (list key-sequence function))
156 ;; (defun gimpedit-add-point-bindings (map)
157 ;; "Add `gimpedit-point-key-bindings' to point keymap MAP.
158 ;; Set it up like this:
160 ;; (eval-after-load 'gimpedit
161 ;; '(gimpedit-add-point-bindings MY-MAP))
163 ;; There must also be a character property `image-file' at point for this
165 ;; (dolist (binding gimpedit-point-key-bindings)
166 ;; (let ((key (nth 0 binding))
167 ;; (fun (nth 1 binding)))
168 ;; (define-key map key fun))))
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172 ;;; gimpedit.el ends here