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
|
|
28 ;; Iimage is a minor mode that display a images, when image-filename
|
|
29 ;; exists in buffer.
|
|
30 ;; http://www.netlaputa.ne.jp/~kose/Emacs/iimage.html
|
|
31 ;;
|
|
32 ;; Add to your `~/.emacs':
|
|
33 ;; (autoload 'iimage-mode "iimage" "SUpport Inline image minor mode." t)
|
|
34 ;;
|
|
35 ;; ** Display images in *Info* buffer.
|
|
36 ;;
|
|
37 ;; (add-hook 'info-mode-hook 'turn-on-iimage-mode)
|
|
38 ;;
|
|
39 ;; .texinfo: @file{file://foo.png}
|
|
40 ;; .info: `file://foo.png'
|
|
41 ;;
|
|
42 ;; ** Display images in Wiki buffer.
|
|
43 ;;
|
|
44 ;; (add-hook 'wiki-mode-hook 'turn-on-iimage-mode)
|
|
45 ;;
|
|
46 ;; wiki-file: [[foo.png]]
|
|
47
|
|
48 ;;; Code:
|
|
49
|
|
50 (eval-when-compile
|
|
51 (require 'image-file))
|
|
52
|
|
53 (defconst iimage-version "1.0")
|
|
54 (defvar iimage-mode nil)
|
|
55 (defvar iimage-mode-map nil)
|
|
56
|
|
57 ;; Set up key map.
|
|
58 (unless iimage-mode-map
|
|
59 (setq iimage-mode-map (make-sparse-keymap))
|
|
60 (define-key iimage-mode-map "\C-l" 'iimage-recenter))
|
|
61
|
|
62 (defun iimage-recenter (&optional arg)
|
|
63 "Re-draw images and recenter."
|
|
64 (interactive "P")
|
|
65 (iimage-mode-buffer 0)
|
|
66 (iimage-mode-buffer 1)
|
|
67 (recenter arg))
|
|
68
|
|
69 (defvar iimage-mode-image-filename-regex
|
|
70 (concat "[-+./_0-9a-zA-Z]+\\."
|
|
71 (regexp-opt (nconc (mapcar #'upcase
|
|
72 image-file-name-extensions)
|
|
73 image-file-name-extensions)
|
|
74 t)))
|
|
75
|
|
76 (defvar iimage-mode-image-regex-alist
|
|
77 `((,(concat "\\(`?file://\\|\\[\\[\\|<\\|`\\)?"
|
|
78 "\\(" iimage-mode-image-filename-regex "\\)"
|
|
79 "\\(\\]\\]\\|>\\|'\\)?") . 2))
|
|
80 "*Alist of filename REGEXP vs NUM.
|
|
81 Each element looks like (REGEXP . NUM).
|
|
82 NUM specifies which parenthesized expression in the regexp.
|
|
83
|
|
84 image filename regex exsamples:
|
|
85 file://foo.png
|
|
86 `file://foo.png'
|
|
87 \\[\\[foo.gif]]
|
|
88 <foo.png>
|
|
89 foo.JPG
|
|
90 ")
|
|
91
|
|
92 (defun turn-on-iimage-mode ()
|
|
93 "Unconditionally turn on iimage mode."
|
|
94 (interactive)
|
|
95 (iimage-mode 1))
|
|
96
|
|
97 (defun turn-off-iimage-mode ()
|
|
98 "Unconditionally turn off iimage mode."
|
|
99 (interactive)
|
|
100 (iimage-mode 0))
|
|
101
|
|
102 (defun iimage-mode-buffer (arg)
|
|
103 "Display/Undisplay Images.
|
|
104 With numeric ARG, display the images if and only if ARG is positive."
|
|
105 (interactive)
|
|
106 (let ((ing (if (numberp arg)
|
|
107 (> arg 0)
|
|
108 iimage-mode))
|
|
109 (modp (buffer-modified-p (current-buffer)))
|
|
110 file buffer-read-only)
|
|
111 (save-excursion
|
|
112 (goto-char (point-min))
|
|
113 (dolist (pair iimage-mode-image-regex-alist)
|
|
114 (while (re-search-forward (car pair) nil t)
|
|
115 (if (and (setq file (match-string (cdr pair)))
|
|
116 (setq file (expand-file-name file default-directory))
|
|
117 (file-exists-p file))
|
|
118 (if ing
|
|
119 (add-text-properties (match-beginning 0) (match-end 0)
|
|
120 (list 'display (create-image file)))
|
|
121 (remove-text-properties (match-beginning 0) (match-end 0)
|
|
122 '(display)))))))
|
|
123 (set-buffer-modified-p modp)))
|
|
124
|
|
125 (define-minor-mode iimage-mode
|
|
126 "Toggle inline image minor mode."
|
|
127 nil " iImg" iimage-mode-map
|
|
128 (run-hooks 'iimage-mode-hook)
|
|
129 (iimage-mode-buffer iimage-mode))
|
|
130
|
|
131 (provide 'iimage)
|
|
132
|
|
133 ;;; iimage.el ends here
|