diff options
| author | Miles Bader | 2000-09-29 13:52:39 +0000 |
|---|---|---|
| committer | Miles Bader | 2000-09-29 13:52:39 +0000 |
| commit | 75e5b373ce74bd58470f7df29c36582bdb931428 (patch) | |
| tree | 355002399ae3c3bc97b9bda7756bd4b5b5948354 | |
| parent | dc3cd20f619344cad3343ee3555920c8fe8e65d9 (diff) | |
| download | emacs-75e5b373ce74bd58470f7df29c36582bdb931428.tar.gz emacs-75e5b373ce74bd58470f7df29c36582bdb931428.zip | |
(image-file-name-extensions): New variable.
(image-file-name-regexps): Renamed from `image-file-regexps'.
New default value is nil. Call `auto-image-file-mode'.
(image-file-name-regexp): New function.
(auto-image-file-mode): New minor mode.
(insert-image-file): Don't make conditional on the image-file
handler being enabled.
(image-file-handler): Make the call here conditional instead.
(set-image-file-handler-enabled, enable-image-file-handler)
(disable-image-file-handler): Functions removed.
| -rw-r--r-- | lisp/ChangeLog | 16 | ||||
| -rw-r--r-- | lisp/image-file.el | 133 |
2 files changed, 94 insertions, 55 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2b24f5e6035..b0caf1d0672 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,19 @@ | |||
| 1 | 2000-09-29 Miles Bader <miles@gnu.org> | ||
| 2 | |||
| 3 | * image-file.el (image-file-name-extensions): New variable. | ||
| 4 | (image-file-name-regexps): Renamed from `image-file-regexps'. | ||
| 5 | New default value is nil. Call `auto-image-file-mode'. | ||
| 6 | (image-file-name-regexp): New function. | ||
| 7 | (auto-image-file-mode): New minor mode. | ||
| 8 | (insert-image-file): Don't make conditional on the image-file | ||
| 9 | handler being enabled. | ||
| 10 | (image-file-handler): Make the call here conditional instead. | ||
| 11 | (set-image-file-handler-enabled, enable-image-file-handler) | ||
| 12 | (disable-image-file-handler): Functions removed. | ||
| 13 | |||
| 14 | * emacs-lisp/authors.el (authors-print): Rephrase many-files | ||
| 15 | string. | ||
| 16 | |||
| 1 | 2000-09-29 Gerd Moellmann <gerd@gnu.org> | 17 | 2000-09-29 Gerd Moellmann <gerd@gnu.org> |
| 2 | 18 | ||
| 3 | * textmodes/tex-mode.el (latex-outline-regexp): Don't use `list*'; | 19 | * textmodes/tex-mode.el (latex-outline-regexp): Don't use `list*'; |
diff --git a/lisp/image-file.el b/lisp/image-file.el index 4eb5c335dcc..a3a23efcc09 100644 --- a/lisp/image-file.el +++ b/lisp/image-file.el | |||
| @@ -35,36 +35,88 @@ | |||
| 35 | 35 | ||
| 36 | (require 'image) | 36 | (require 'image) |
| 37 | 37 | ||
| 38 | ;;;###autoload | 38 | |
| 39 | (defcustom image-file-handler-enabled nil | 39 | (defcustom image-file-name-extensions |
| 40 | "True if visiting an image file will actually display the image. | 40 | '("png" "jpeg" "jpg" "gif" "tiff" "xbm" "xpm") |
| 41 | A file is considered an image file if its filename matches one of the | 41 | "*A list of image-file filename extensions. |
| 42 | regexps in `image-file-regexps'. | 42 | Filenames having one of these extensions are considered image files, |
| 43 | 43 | in addition to those matching `image-file-name-regexps'. | |
| 44 | Setting this variable directly does not take effect; | 44 | |
| 45 | use either \\[customize] or the function `set-image-file-handler-enabled'." | 45 | See `auto-image-file-mode'; if `auto-image-file-mode' is enabled, |
| 46 | :type 'boolean | 46 | setting this variable directly does not take effect unless |
| 47 | :set (lambda (sym val) (set-image-file-handler-enabled val)) | 47 | `auto-image-file-mode' is re-enabled; this happens automatically the |
| 48 | variable is set using \\[customize]." | ||
| 49 | :type '(repeat string) | ||
| 50 | :set (lambda (sym val) | ||
| 51 | (set-default sym val) | ||
| 52 | (when auto-image-file-mode | ||
| 53 | ;; Re-initialize the image-file handler | ||
| 54 | (auto-image-file-mode t))) | ||
| 48 | :initialize 'custom-initialize-default | 55 | :initialize 'custom-initialize-default |
| 49 | :require 'image-file | ||
| 50 | :group 'image) | 56 | :group 'image) |
| 51 | 57 | ||
| 52 | (defcustom image-file-regexps | 58 | (defcustom image-file-name-regexps nil |
| 53 | '("\\.png$" "\\.jpeg$" "\\.jpg$" "\\.gif$" "\\.tiff$" "\\.x[bp]m$") | 59 | "*A list of regexps matching image-file filenames. |
| 54 | "*A list of regexps matching files that should be displayed as images. | 60 | Filenames matching one of these regexps are considered image files, |
| 61 | in addition to those with an extension in `image-file-name-extensions'. | ||
| 55 | 62 | ||
| 56 | Setting this variable directly does not take effect until the next time | 63 | See `auto-image-file-mode'; if `auto-image-file-mode' is enabled, |
| 57 | `set-image-file-handler-enabled' is called (which happens automatically | 64 | setting this variable directly does not take effect unless |
| 58 | when using \\[customize]." | 65 | `auto-image-file-mode' is re-enabled; this happens automatically the |
| 66 | variable is set using \\[customize]." | ||
| 59 | :type '(repeat regexp) | 67 | :type '(repeat regexp) |
| 60 | :set (lambda (sym val) | 68 | :set (lambda (sym val) |
| 61 | (set-default sym val) | 69 | (set-default sym val) |
| 62 | (when image-file-handler-enabled | 70 | (when auto-image-file-mode |
| 63 | ;; Re-initialize the image-file handler | 71 | ;; Re-initialize the image-file handler |
| 64 | (set-image-file-handler-enabled t))) | 72 | (auto-image-file-mode t))) |
| 65 | :initialize 'custom-initialize-default | 73 | :initialize 'custom-initialize-default |
| 66 | :group 'image) | 74 | :group 'image) |
| 67 | 75 | ||
| 76 | |||
| 77 | ;;;###autoload | ||
| 78 | (defun image-file-name-regexp () | ||
| 79 | "Return a regular expression that matches image-file filenames." | ||
| 80 | (let ((exts-regexp | ||
| 81 | (and image-file-name-extensions | ||
| 82 | (concat "\\." | ||
| 83 | (regexp-opt image-file-name-extensions t) | ||
| 84 | "\\'")))) | ||
| 85 | (if image-file-name-regexps | ||
| 86 | (mapconcat 'identity | ||
| 87 | (if exts-regexp | ||
| 88 | (cons exts-regexp image-file-regexps) | ||
| 89 | image-file-regexps) | ||
| 90 | "\\|") | ||
| 91 | exts-regexp))) | ||
| 92 | |||
| 93 | |||
| 94 | ;;;###autoload | ||
| 95 | (define-minor-mode auto-image-file-mode | ||
| 96 | "Toggle visiting of image files as images. | ||
| 97 | With prefix argument ARG, turn on if positive, otherwise off. | ||
| 98 | Returns non-nil if the new state is enabled. | ||
| 99 | |||
| 100 | Image files are those whose name has an extension in | ||
| 101 | `image-file-name-extensions', or matches a regexp in | ||
| 102 | `image-file-name-regexps'." | ||
| 103 | nil | ||
| 104 | nil | ||
| 105 | nil | ||
| 106 | :global t | ||
| 107 | :group 'image | ||
| 108 | ;; Remove existing handler | ||
| 109 | (let ((existing-entry | ||
| 110 | (rassq 'image-file-handler file-name-handler-alist))) | ||
| 111 | (when existing-entry | ||
| 112 | (setq file-name-handler-alist | ||
| 113 | (delq existing-entry file-name-handler-alist)))) | ||
| 114 | ;; Add new handler, if enabled | ||
| 115 | (when auto-image-file-mode | ||
| 116 | (push (cons (image-file-name-regexp) 'image-file-handler) | ||
| 117 | file-name-handler-alist))) | ||
| 118 | |||
| 119 | |||
| 68 | ;;;###autoload | 120 | ;;;###autoload |
| 69 | (defun insert-image-file (file &optional visit beg end replace) | 121 | (defun insert-image-file (file &optional visit beg end replace) |
| 70 | "Insert the image file FILE into the current buffer. | 122 | "Insert the image file FILE into the current buffer. |
| @@ -74,12 +126,14 @@ the command `insert-file-contents'." | |||
| 74 | (image-file-call-underlying #'insert-file-contents-literally | 126 | (image-file-call-underlying #'insert-file-contents-literally |
| 75 | 'insert-file-contents | 127 | 'insert-file-contents |
| 76 | file visit beg end replace))) | 128 | file visit beg end replace))) |
| 77 | (when (and image-file-handler-enabled (or (null beg) (zerop beg)) (null end)) | 129 | ;; Turn the image data into a real image, but only if the whole file |
| 78 | ;; Make image into a picture, but only if the whole file was inserted | 130 | ;; was inserted |
| 131 | (when (and (or (null beg) (zerop beg)) (null end)) | ||
| 79 | (let* ((ibeg (point)) | 132 | (let* ((ibeg (point)) |
| 80 | (iend (+ (point) (cadr rval))) | 133 | (iend (+ (point) (cadr rval))) |
| 81 | (data | 134 | (data |
| 82 | (string-make-unibyte (buffer-substring-no-properties ibeg iend))) | 135 | (string-make-unibyte |
| 136 | (buffer-substring-no-properties ibeg iend))) | ||
| 83 | (image | 137 | (image |
| 84 | (create-image data nil t)) | 138 | (create-image data nil t)) |
| 85 | (props | 139 | (props |
| @@ -99,7 +153,8 @@ the command `insert-file-contents'." | |||
| 99 | "File name handler for inserting image files. | 153 | "File name handler for inserting image files. |
| 100 | OPERATION is the operation to perform, on ARGS. | 154 | OPERATION is the operation to perform, on ARGS. |
| 101 | See `file-name-handler-alist' for details." | 155 | See `file-name-handler-alist' for details." |
| 102 | (if (eq operation 'insert-file-contents) | 156 | (if (and (eq operation 'insert-file-contents) |
| 157 | auto-image-file-mode) | ||
| 103 | (apply #'insert-image-file args) | 158 | (apply #'insert-image-file args) |
| 104 | ;; We don't handle OPERATION, use another handler or the default | 159 | ;; We don't handle OPERATION, use another handler or the default |
| 105 | (apply #'image-file-call-underlying operation operation args))) | 160 | (apply #'image-file-call-underlying operation operation args))) |
| @@ -114,38 +169,6 @@ Optional argument ARGS are the arguments to call FUNCTION with." | |||
| 114 | (inhibit-file-name-operation operation)) | 169 | (inhibit-file-name-operation operation)) |
| 115 | (apply function args))) | 170 | (apply function args))) |
| 116 | 171 | ||
| 117 | ;;;###autoload | ||
| 118 | (defun set-image-file-handler-enabled (enabled) | ||
| 119 | "Enable or disable visiting image files as real images, as per ENABLED. | ||
| 120 | The regexp in `image-file-regexp' is used to determine which filenames are | ||
| 121 | considered image files." | ||
| 122 | ;; Remove existing handler | ||
| 123 | (let ((existing-entry (rassq 'image-file-handler file-name-handler-alist))) | ||
| 124 | (when existing-entry | ||
| 125 | (setq file-name-handler-alist | ||
| 126 | (delq existing-entry file-name-handler-alist)))) | ||
| 127 | ;; Add new handler | ||
| 128 | (when enabled | ||
| 129 | (let ((regexp | ||
| 130 | (concat "\\(" | ||
| 131 | (mapconcat 'identity image-file-regexps "\\|") | ||
| 132 | "\\)"))) | ||
| 133 | (setq file-name-handler-alist | ||
| 134 | (cons (cons regexp 'image-file-handler) file-name-handler-alist)))) | ||
| 135 | (setq-default image-file-handler-enabled enabled)) | ||
| 136 | |||
| 137 | ;;;###autoload | ||
| 138 | (defun enable-image-file-handler () | ||
| 139 | "Enable visiting image files as real images. | ||
| 140 | The regexp in `image-file-regexp' is used to determine which filenames are | ||
| 141 | considered image files." | ||
| 142 | (interactive) | ||
| 143 | (set-image-file-handler-enabled t)) | ||
| 144 | |||
| 145 | (defun disable-image-file-handler () | ||
| 146 | "Disable visiting image files as real images." | ||
| 147 | (interactive) | ||
| 148 | (set-image-file-handler-enabled nil)) | ||
| 149 | 172 | ||
| 150 | (provide 'image-file) | 173 | (provide 'image-file) |
| 151 | 174 | ||