]> code.delx.au - gnu-emacs/blobdiff - lisp/image-mode.el
(ispell-keep-choices-win, ispell-dictionary-alist, ispell-word,
[gnu-emacs] / lisp / image-mode.el
index c955a43214805d7d5c4f8e0a3ca579448007a339..eb08de1d6bbb12c7d0ba64d7be96a3296cdb42bf 100644 (file)
@@ -1,6 +1,6 @@
 ;;; image-mode.el --- support for visiting image files
 ;;
-;; Copyright (C) 2005 Free Software Foundation, Inc.
+;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
 ;;
 ;; Author: Richard Stallman <rms@gnu.org>
 ;; Keywords: multimedia
@@ -19,8 +19,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -60,16 +60,19 @@ to toggle between display as an image and display as text."
   (setq major-mode 'image-mode)
   (use-local-map image-mode-map)
   (add-hook 'change-major-mode-hook 'image-toggle-display-text nil t)
-  (if (not (get-text-property (point-min) 'display))
+  (if (and (display-images-p)
+          (not (get-text-property (point-min) 'display)))
       (image-toggle-display)
     ;; Set next vars when image is already displayed but local
     ;; variables were cleared by kill-all-local-variables
     (setq cursor-type nil truncate-lines t))
   (run-mode-hooks 'image-mode-hook)
-  (message (concat (substitute-command-keys
-                   "Type \\[image-toggle-display] to view the image as ")
-                  (if (get-text-property (point-min) 'display)
-                      "text" "an image") ".")))
+  (if (display-images-p)
+      (message "%s" (concat
+                    (substitute-command-keys
+                     "Type \\[image-toggle-display] to view as ")
+                    (if (get-text-property (point-min) 'display)
+                        "text" "an image") "."))))
 
 ;;;###autoload
 (define-minor-mode image-minor-mode
@@ -79,8 +82,15 @@ See the command `image-mode' for more information on this mode."
   nil " Image" image-mode-map
   :group 'image
   :version "22.1"
-  (unless (or (eq major-mode 'image-mode) image-minor-mode)
-    (use-local-map image-mode-map)))
+  (if (not image-minor-mode)
+      (image-toggle-display-text)
+    (if (get-text-property (point-min) 'display)
+       (setq cursor-type nil truncate-lines t))
+    (add-hook 'change-major-mode-hook (lambda () (image-minor-mode -1)) nil t)
+    (message "%s" (concat (substitute-command-keys
+                     "Type \\[image-toggle-display] to view the image as ")
+                    (if (get-text-property (point-min) 'display)
+                        "text" "an image") "."))))
 
 ;;;###autoload
 (defun image-mode-maybe ()
@@ -101,7 +111,8 @@ information on these modes."
                         elt))
                     auto-mode-alist))))
     (if (assoc-default buffer-file-name mode-alist 'string-match)
-       (let ((auto-mode-alist mode-alist))
+       (let ((auto-mode-alist mode-alist)
+             (magic-mode-alist nil))
          (set-auto-mode)
          (image-minor-mode t))
       (image-mode))))
@@ -111,6 +122,9 @@ information on these modes."
   (if (get-text-property (point-min) 'display)
       (image-toggle-display)))
 
+(defvar archive-superior-buffer)
+(defvar tar-superior-buffer)
+
 (defun image-toggle-display ()
   "Start or stop displaying an image file as the actual image.
 This command toggles between showing the text of the image file
@@ -130,11 +144,20 @@ and showing the image as an image."
            (message "Repeat this command to go back to displaying the image")))
     ;; Turn the image data into a real image, but only if the whole file
     ;; was inserted
-    (let* ((data
-           (string-make-unibyte
-            (buffer-substring-no-properties (point-min) (point-max))))
-          (image
-           (create-image data nil t))
+    (let* ((image
+           (if (and (buffer-file-name)
+                    (not (file-remote-p (buffer-file-name)))
+                    (not (buffer-modified-p))
+                    (not (and (boundp 'archive-superior-buffer)
+                              archive-superior-buffer))
+                    (not (and (boundp 'tar-superior-buffer)
+                              tar-superior-buffer)))
+               (progn (clear-image-cache)
+                      (create-image (buffer-file-name)))
+             (create-image
+              (string-make-unibyte
+               (buffer-substring-no-properties (point-min) (point-max)))
+              nil t)))
           (props
            `(display ,image
                      intangible ,image