1 ;;; iimage.el --- Inline image minor mode.
3 ;; Copyright (C) 2004 Free Software Foundation
5 ;; Author: KOSEKI Yoshinori <kose@meadowy.org>
6 ;; Maintainer: KOSEKI Yoshinori <kose@meadowy.org>
7 ;; Keywords: multimedia
9 ;; This file is part of GNU Emacs.
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)
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.
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.
28 ;; Iimage is a minor mode that display a images, when image-filename
30 ;; http://www.netlaputa.ne.jp/~kose/Emacs/iimage.html
32 ;; Add to your `~/.emacs':
33 ;; (autoload 'iimage-mode "iimage" "SUpport Inline image minor mode." t)
35 ;; ** Display images in *Info* buffer.
37 ;; (add-hook 'info-mode-hook 'turn-on-iimage-mode)
39 ;; .texinfo: @file{file://foo.png}
40 ;; .info: `file://foo.png'
42 ;; ** Display images in Wiki buffer.
44 ;; (add-hook 'wiki-mode-hook 'turn-on-iimage-mode)
46 ;; wiki-file: [[foo.png]]
51 (require 'image-file
))
53 (defconst iimage-version
"1.0")
54 (defvar iimage-mode nil
)
55 (defvar iimage-mode-map nil
)
58 (unless iimage-mode-map
59 (setq iimage-mode-map
(make-sparse-keymap))
60 (define-key iimage-mode-map
"\C-l" 'iimage-recenter
))
62 (defun iimage-recenter (&optional arg
)
63 "Re-draw images and recenter."
65 (iimage-mode-buffer 0)
66 (iimage-mode-buffer 1)
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
)
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.
84 image filename regex exsamples:
92 (defun turn-on-iimage-mode ()
93 "Unconditionally turn on iimage mode."
97 (defun turn-off-iimage-mode ()
98 "Unconditionally turn off iimage mode."
102 (defun iimage-mode-buffer (arg)
103 "Display/Undisplay Images.
104 With numeric ARG, display the images if and only if ARG is positive."
106 (let ((ing (if (numberp arg
)
109 (modp (buffer-modified-p (current-buffer)))
110 file buffer-read-only
)
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
))
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)
123 (set-buffer-modified-p modp
)))
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
))
133 ;;; arch-tag: f6f8e29a-08f6-4a12-9496-51e67441ce65
134 ;;; iimage.el ends here