Mercurial > emacs
annotate lisp/iimage.el @ 58140:b72ba185298b
(desktop-buffer-mode-handlers, desktop-after-read-hook,
desktop-clear-preserve-buffers-regexp, desktop-file-name-format,
desktop-globals-to-clear, desktop-no-desktop-file-hook, desktop-path,
desktop-save): Add :version.
author | Lars Hansen <larsh@soem.dk> |
---|---|
date | Thu, 11 Nov 2004 19:02:31 +0000 |
parents | 401149ed59c0 |
children | 3933597e185e |
rev | line source |
---|---|
55525 | 1 ;;; iimage.el --- Inline image minor mode. |
2 | |
3 ;; Copyright (C) 2004 Free Software Foundation | |
4 | |
5 ;; Author: KOSEKI Yoshinori <kose@meadowy.org> | |
6 ;; Maintainer: KOSEKI Yoshinori <kose@meadowy.org> | |
7 ;; Keywords: multimedia | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
28 ;; Iimage is a minor mode that displays images, when image-filename |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
29 ;; exists in the buffer. |
55525 | 30 ;; http://www.netlaputa.ne.jp/~kose/Emacs/iimage.html |
31 ;; | |
32 ;; Add to your `~/.emacs': | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
33 ;; (autoload 'iimage-mode "iimage" "Support Inline image minor mode." t) |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
34 ;; (autoload 'turn-on-iimage-mode "iimage" "Turn on Inline image minor mode." t) |
55525 | 35 ;; |
36 ;; ** Display images in *Info* buffer. | |
37 ;; | |
38 ;; (add-hook 'info-mode-hook 'turn-on-iimage-mode) | |
39 ;; | |
40 ;; .texinfo: @file{file://foo.png} | |
41 ;; .info: `file://foo.png' | |
42 ;; | |
43 ;; ** Display images in Wiki buffer. | |
44 ;; | |
45 ;; (add-hook 'wiki-mode-hook 'turn-on-iimage-mode) | |
46 ;; | |
47 ;; wiki-file: [[foo.png]] | |
48 | |
49 ;;; Code: | |
50 | |
51 (eval-when-compile | |
52 (require 'image-file)) | |
53 | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
54 (defconst iimage-version "1.1") |
55525 | 55 (defvar iimage-mode nil) |
56 (defvar iimage-mode-map nil) | |
57 | |
58 ;; Set up key map. | |
59 (unless iimage-mode-map | |
60 (setq iimage-mode-map (make-sparse-keymap)) | |
61 (define-key iimage-mode-map "\C-l" 'iimage-recenter)) | |
62 | |
63 (defun iimage-recenter (&optional arg) | |
64 "Re-draw images and recenter." | |
65 (interactive "P") | |
66 (iimage-mode-buffer 0) | |
67 (iimage-mode-buffer 1) | |
68 (recenter arg)) | |
69 | |
70 (defvar iimage-mode-image-filename-regex | |
71 (concat "[-+./_0-9a-zA-Z]+\\." | |
72 (regexp-opt (nconc (mapcar #'upcase | |
73 image-file-name-extensions) | |
74 image-file-name-extensions) | |
75 t))) | |
76 | |
77 (defvar iimage-mode-image-regex-alist | |
78 `((,(concat "\\(`?file://\\|\\[\\[\\|<\\|`\\)?" | |
79 "\\(" iimage-mode-image-filename-regex "\\)" | |
80 "\\(\\]\\]\\|>\\|'\\)?") . 2)) | |
81 "*Alist of filename REGEXP vs NUM. | |
82 Each element looks like (REGEXP . NUM). | |
83 NUM specifies which parenthesized expression in the regexp. | |
84 | |
85 image filename regex exsamples: | |
86 file://foo.png | |
87 `file://foo.png' | |
88 \\[\\[foo.gif]] | |
89 <foo.png> | |
90 foo.JPG | |
91 ") | |
92 | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
93 (defvar iimage-mode-image-search-path nil |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
94 "*List of directories to search for image files for iimage-mode.") |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
95 |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
96 ;;;###autoload |
55525 | 97 (defun turn-on-iimage-mode () |
98 "Unconditionally turn on iimage mode." | |
99 (interactive) | |
100 (iimage-mode 1)) | |
101 | |
102 (defun turn-off-iimage-mode () | |
103 "Unconditionally turn off iimage mode." | |
104 (interactive) | |
105 (iimage-mode 0)) | |
106 | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
107 ;; Emacs21.3 or earlier does not heve locate-file. |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
108 (if (fboundp 'locate-file) |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
109 (defalias 'iimage-locate-file 'locate-file) |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
110 (defun iimage-locate-file (filename path) |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
111 (locate-library filename t path))) |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
112 |
55525 | 113 (defun iimage-mode-buffer (arg) |
114 "Display/Undisplay Images. | |
115 With numeric ARG, display the images if and only if ARG is positive." | |
116 (interactive) | |
117 (let ((ing (if (numberp arg) | |
118 (> arg 0) | |
119 iimage-mode)) | |
120 (modp (buffer-modified-p (current-buffer))) | |
121 file buffer-read-only) | |
122 (save-excursion | |
123 (goto-char (point-min)) | |
124 (dolist (pair iimage-mode-image-regex-alist) | |
125 (while (re-search-forward (car pair) nil t) | |
126 (if (and (setq file (match-string (cdr pair))) | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
127 (setq file (iimage-locate-file file |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
128 (cons default-directory |
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
129 iimage-mode-image-search-path)))) |
55525 | 130 (if ing |
131 (add-text-properties (match-beginning 0) (match-end 0) | |
132 (list 'display (create-image file))) | |
133 (remove-text-properties (match-beginning 0) (match-end 0) | |
134 '(display))))))) | |
135 (set-buffer-modified-p modp))) | |
136 | |
56331
401149ed59c0
(turn-on-iimage-mode, iimage-mode): Add autoload cookies.
Eli Zaretskii <eliz@gnu.org>
parents:
55532
diff
changeset
|
137 ;;;###autoload |
55525 | 138 (define-minor-mode iimage-mode |
139 "Toggle inline image minor mode." | |
140 nil " iImg" iimage-mode-map | |
141 (run-hooks 'iimage-mode-hook) | |
142 (iimage-mode-buffer iimage-mode)) | |
143 | |
144 (provide 'iimage) | |
145 | |
55532
c9cc17f13ff4
Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents:
55525
diff
changeset
|
146 ;;; arch-tag: f6f8e29a-08f6-4a12-9496-51e67441ce65 |
55525 | 147 ;;; iimage.el ends here |