diff options
| author | Juri Linkov | 2005-03-25 19:57:21 +0000 |
|---|---|---|
| committer | Juri Linkov | 2005-03-25 19:57:21 +0000 |
| commit | d90e651e6e5900a57f061d4e691c5e9409322ff9 (patch) | |
| tree | c2c6ba97fd7c9d817a901aac2211322af93cb975 | |
| parent | 5341e481c898eed728a270628e225f80b9de0506 (diff) | |
| download | emacs-d90e651e6e5900a57f061d4e691c5e9409322ff9.tar.gz emacs-d90e651e6e5900a57f061d4e691c5e9409322ff9.zip | |
Optimize image filename extension regexps in
autoload cookies. Associate .x[bp]m with `image-mode-maybe'
in `auto-mode-alist'.
(image-mode): Add `image-toggle-display-text' to local hook
`change-major-mode-hook'. Display the image as an image by
default. Set `cursor-type' and `truncate-lines' if the image
is already displayed. Take into account the current mode (image
or text) in message.
(image-minor-mode): New minor mode.
(image-mode-maybe, image-toggle-display-text): New functions.
(image-toggle-display): Use called-interactively-p.
Let-bind `inhibit-read-only' to t.
| -rw-r--r-- | lisp/image-mode.el | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 0d2b221ee8b..c955a432148 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -36,18 +36,12 @@ | |||
| 36 | 36 | ||
| 37 | (require 'image) | 37 | (require 'image) |
| 38 | 38 | ||
| 39 | ;;;###autoload (push '("\\.jpg\\'" . image-mode) auto-mode-alist) | 39 | ;;;###autoload (push '("\\.jpe?g\\'" . image-mode) auto-mode-alist) |
| 40 | ;;;###autoload (push '("\\.jpeg\\'" . image-mode) auto-mode-alist) | 40 | ;;;###autoload (push '("\\.png\\'" . image-mode) auto-mode-alist) |
| 41 | ;;;###autoload (push '("\\.gif\\'" . image-mode) auto-mode-alist) | 41 | ;;;###autoload (push '("\\.gif\\'" . image-mode) auto-mode-alist) |
| 42 | ;;;###autoload (push '("\\.png\\'" . image-mode) auto-mode-alist) | 42 | ;;;###autoload (push '("\\.tiff?\\'" . image-mode) auto-mode-alist) |
| 43 | ;;;###autoload (push '("\\.tiff\\'" . image-mode) auto-mode-alist) | 43 | ;;;###autoload (push '("\\.p[bpgn]m\\'" . image-mode) auto-mode-alist) |
| 44 | ;;;###autoload (push '("\\.tif\\'" . image-mode) auto-mode-alist) | 44 | ;;;###autoload (push '("\\.x[bp]m\\'" . image-mode-maybe) auto-mode-alist) |
| 45 | ;;;###autoload (push '("\\.xbm\\'" . image-mode) auto-mode-alist) | ||
| 46 | ;;;###autoload (push '("\\.xpm\\'" . image-mode) auto-mode-alist) | ||
| 47 | ;;;###autoload (push '("\\.pbm\\'" . image-mode) auto-mode-alist) | ||
| 48 | ;;;###autoload (push '("\\.pgm\\'" . image-mode) auto-mode-alist) | ||
| 49 | ;;;###autoload (push '("\\.ppm\\'" . image-mode) auto-mode-alist) | ||
| 50 | ;;;###autoload (push '("\\.pnm\\'" . image-mode) auto-mode-alist) | ||
| 51 | 45 | ||
| 52 | (defvar image-mode-map | 46 | (defvar image-mode-map |
| 53 | (let ((map (make-sparse-keymap))) | 47 | (let ((map (make-sparse-keymap))) |
| @@ -65,9 +59,57 @@ to toggle between display as an image and display as text." | |||
| 65 | (setq mode-name "Image") | 59 | (setq mode-name "Image") |
| 66 | (setq major-mode 'image-mode) | 60 | (setq major-mode 'image-mode) |
| 67 | (use-local-map image-mode-map) | 61 | (use-local-map image-mode-map) |
| 62 | (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t) | ||
| 63 | (if (not (get-text-property (point-min) 'display)) | ||
| 64 | (image-toggle-display) | ||
| 65 | ;; Set next vars when image is already displayed but local | ||
| 66 | ;; variables were cleared by kill-all-local-variables | ||
| 67 | (setq cursor-type nil truncate-lines t)) | ||
| 68 | (run-mode-hooks 'image-mode-hook) | 68 | (run-mode-hooks 'image-mode-hook) |
| 69 | (message (substitute-command-keys | 69 | (message (concat (substitute-command-keys |
| 70 | "Type \\[image-toggle-display] to view the image as an image."))) | 70 | "Type \\[image-toggle-display] to view the image as ") |
| 71 | (if (get-text-property (point-min) 'display) | ||
| 72 | "text" "an image") "."))) | ||
| 73 | |||
| 74 | ;;;###autoload | ||
| 75 | (define-minor-mode image-minor-mode | ||
| 76 | "Toggle Image minor mode. | ||
| 77 | With arg, turn Image minor mode on if arg is positive, off otherwise. | ||
| 78 | See the command `image-mode' for more information on this mode." | ||
| 79 | nil " Image" image-mode-map | ||
| 80 | :group 'image | ||
| 81 | :version "22.1" | ||
| 82 | (unless (or (eq major-mode 'image-mode) image-minor-mode) | ||
| 83 | (use-local-map image-mode-map))) | ||
| 84 | |||
| 85 | ;;;###autoload | ||
| 86 | (defun image-mode-maybe () | ||
| 87 | "Set major or minor mode for image files. | ||
| 88 | Set Image major mode only when there are no other major modes | ||
| 89 | associated with a filename in `auto-mode-alist'. When an image | ||
| 90 | filename matches another major mode in `auto-mode-alist' then | ||
| 91 | set that major mode and Image minor mode. | ||
| 92 | |||
| 93 | See commands `image-mode' and `image-minor-mode' for more | ||
| 94 | information on these modes." | ||
| 95 | (interactive) | ||
| 96 | (let* ((mode-alist | ||
| 97 | (delq nil (mapcar | ||
| 98 | (lambda (elt) | ||
| 99 | (unless (memq (or (car-safe (cdr elt)) (cdr elt)) | ||
| 100 | '(image-mode image-mode-maybe)) | ||
| 101 | elt)) | ||
| 102 | auto-mode-alist)))) | ||
| 103 | (if (assoc-default buffer-file-name mode-alist 'string-match) | ||
| 104 | (let ((auto-mode-alist mode-alist)) | ||
| 105 | (set-auto-mode) | ||
| 106 | (image-minor-mode t)) | ||
| 107 | (image-mode)))) | ||
| 108 | |||
| 109 | (defun image-toggle-display-text () | ||
| 110 | "Showing the text of the image file." | ||
| 111 | (if (get-text-property (point-min) 'display) | ||
| 112 | (image-toggle-display))) | ||
| 71 | 113 | ||
| 72 | (defun image-toggle-display () | 114 | (defun image-toggle-display () |
| 73 | "Start or stop displaying an image file as the actual image. | 115 | "Start or stop displaying an image file as the actual image. |
| @@ -84,7 +126,8 @@ and showing the image as an image." | |||
| 84 | (set-buffer-modified-p modified) | 126 | (set-buffer-modified-p modified) |
| 85 | (kill-local-variable 'cursor-type) | 127 | (kill-local-variable 'cursor-type) |
| 86 | (kill-local-variable 'truncate-lines) | 128 | (kill-local-variable 'truncate-lines) |
| 87 | (message "Repeat this command to go back to displaying the image")) | 129 | (if (called-interactively-p) |
| 130 | (message "Repeat this command to go back to displaying the image"))) | ||
| 88 | ;; Turn the image data into a real image, but only if the whole file | 131 | ;; Turn the image data into a real image, but only if the whole file |
| 89 | ;; was inserted | 132 | ;; was inserted |
| 90 | (let* ((data | 133 | (let* ((data |
| @@ -100,6 +143,7 @@ and showing the image as an image." | |||
| 100 | ;; read-only when we're visiting the file (as | 143 | ;; read-only when we're visiting the file (as |
| 101 | ;; opposed to just inserting it). | 144 | ;; opposed to just inserting it). |
| 102 | read-only t front-sticky (read-only))) | 145 | read-only t front-sticky (read-only))) |
| 146 | (inhibit-read-only t) | ||
| 103 | (buffer-undo-list t) | 147 | (buffer-undo-list t) |
| 104 | (modified (buffer-modified-p))) | 148 | (modified (buffer-modified-p))) |
| 105 | (add-text-properties (point-min) (point-max) props) | 149 | (add-text-properties (point-min) (point-max) props) |
| @@ -110,7 +154,8 @@ and showing the image as an image." | |||
| 110 | ;; This just makes the arrow displayed in the right fringe | 154 | ;; This just makes the arrow displayed in the right fringe |
| 111 | ;; area look correct when the image is wider than the window. | 155 | ;; area look correct when the image is wider than the window. |
| 112 | (setq truncate-lines t) | 156 | (setq truncate-lines t) |
| 113 | (message "Repeat this command to go back to displaying the file as text")))) | 157 | (if (called-interactively-p) |
| 158 | (message "Repeat this command to go back to displaying the file as text"))))) | ||
| 114 | 159 | ||
| 115 | (provide 'image-mode) | 160 | (provide 'image-mode) |
| 116 | 161 | ||