]> code.delx.au - gnu-emacs/blobdiff - lisp/view.el
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs
[gnu-emacs] / lisp / view.el
index 11cbc79449fb1392a3aefd35eeb1858bf346c4fe..ff7d2c9deb19577a4aca6728a3a8a62b61f161ab 100644 (file)
@@ -1,7 +1,7 @@
 ;;; view.el --- peruse file or buffer without editing
 
-;; Copyright (C) 1985, 1989, 1994-1995, 1997, 2000-2011
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1989, 1994-1995, 1997, 2000-2016 Free Software
+;; Foundation, Inc.
 
 ;; Author: K. Shane Hartman
 ;; Maintainer: Inge Frick <inge@nada.kth.se>
@@ -199,6 +199,7 @@ This is local in each buffer, once it is used.")
     (define-key map "\C-?" 'View-scroll-page-backward)
     ;; (define-key map "f" 'View-scroll-page-forward)
     (define-key map " " 'View-scroll-page-forward)
+    (define-key map [?\S-\ ]  'View-scroll-page-backward)
     (define-key map "o" 'View-scroll-to-buffer-end)
     (define-key map ">" 'end-of-buffer)
     (define-key map "<" 'beginning-of-buffer)
@@ -309,20 +310,19 @@ this argument instead of explicitly setting `view-exit-action'.
 Do not set EXIT-ACTION to `kill-buffer' when BUFFER visits a
 file: Users may suspend viewing in order to modify the buffer.
 Exiting View mode will then discard the user's edits.  Setting
-EXIT-ACTION to `kill-buffer-if-not-modified' avoids this."
+EXIT-ACTION to `kill-buffer-if-not-modified' avoids this.
+
+This function does not enable View mode if the buffer's major-mode
+has a `special' mode-class, because such modes usually have their
+own View-like bindings."
   (interactive "bView buffer: ")
-  (if (with-current-buffer buffer
-       (and (eq (get major-mode 'mode-class)
-                'special)
-            (null buffer-file-name)))
-      (progn
-       (switch-to-buffer buffer)
-       (message "Not using View mode because the major mode is special"))
-    (switch-to-buffer buffer)
+  (switch-to-buffer buffer)
+  (if (eq (get major-mode 'mode-class) 'special)
+      (message "Not using View mode because the major mode is special")
     (view-mode-enter nil exit-action)))
 
 ;;;###autoload
-(defun view-buffer-other-window (buffer &optional not-return exit-action)
+(defun view-buffer-other-window (buffer &optional _not-return exit-action)
   "View BUFFER in View mode in another window.
 Emacs commands editing the buffer contents are not available;
 instead, a special set of commands (mostly letters and
@@ -336,14 +336,20 @@ Optional argument NOT-RETURN is ignored.
 
 Optional argument EXIT-ACTION is either nil or a function with buffer as
 argument.  This function is called when finished viewing buffer.  Use
-this argument instead of explicitly setting `view-exit-action'."
+this argument instead of explicitly setting `view-exit-action'.
+
+This function does not enable View mode if the buffer's major-mode
+has a `special' mode-class, because such modes usually have their
+own View-like bindings."
   (interactive "bIn other window view buffer:\nP")
   (let ((pop-up-windows t))
     (pop-to-buffer buffer t))
-  (view-mode-enter nil exit-action))
+  (if (eq (get major-mode 'mode-class) 'special)
+      (message "Not using View mode because the major mode is special")
+    (view-mode-enter nil exit-action)))
 
 ;;;###autoload
-(defun view-buffer-other-frame (buffer &optional not-return exit-action)
+(defun view-buffer-other-frame (buffer &optional _not-return exit-action)
   "View BUFFER in View mode in another frame.
 Emacs commands editing the buffer contents are not available;
 instead, a special set of commands (mostly letters and
@@ -357,11 +363,17 @@ Optional argument NOT-RETURN is ignored.
 
 Optional argument EXIT-ACTION is either nil or a function with buffer as
 argument.  This function is called when finished viewing buffer.  Use
-this argument instead of explicitly setting `view-exit-action'."
+this argument instead of explicitly setting `view-exit-action'.
+
+This function does not enable View mode if the buffer's major-mode
+has a `special' mode-class, because such modes usually have their
+own View-like bindings."
   (interactive "bView buffer in other frame: \nP")
   (let ((pop-up-frames t))
     (pop-to-buffer buffer t))
-  (view-mode-enter nil exit-action))
+  (if (eq (get major-mode 'mode-class) 'special)
+      (message "Not using View mode because the major mode is special")
+    (view-mode-enter nil exit-action)))
 \f
 ;;;###autoload
 (define-minor-mode view-mode
@@ -369,19 +381,24 @@ this argument instead of explicitly setting `view-exit-action'."
   ;; bindings instead of using the \\[] construction.  The reason for this
   ;; is that most commands have more than one key binding.
   "Toggle View mode, a minor mode for viewing text but not editing it.
-With prefix argument ARG, turn View mode on if ARG is positive, otherwise
-turn it off.
+With a prefix argument ARG, enable View mode if ARG is positive,
+and disable it otherwise.  If called from Lisp, enable View mode
+if ARG is omitted or nil.
+
+When View mode is enabled, commands that do not change the buffer
+contents are available as usual.  Kill commands insert text in
+kill buffers but do not delete.  Most other commands beep and
+tell the user that the buffer is read-only.
 
-Emacs commands that do not change the buffer contents are available as usual.
-Kill commands insert text in kill buffers but do not delete.  Other commands
-\(among them most letters and punctuation) beep and tell that the buffer is
-read-only.
 \\<view-mode-map>
-The following additional commands are provided.  Most commands take prefix
-arguments.  Page commands default to \"page size\" lines which is almost a whole
-window full, or number of lines set by \\[View-scroll-page-forward-set-page-size] or \\[View-scroll-page-backward-set-page-size].  Half page commands default to
-and set \"half page size\" lines which initially is half a window full.  Search
-commands default to a repeat count of one.
+
+The following additional commands are provided.  Most commands
+take prefix arguments.  Page commands default to \"page size\"
+lines which is almost a whole window, or number of lines set by
+\\[View-scroll-page-forward-set-page-size] or \\[View-scroll-page-backward-set-page-size].
+Half page commands default to and set \"half page size\" lines
+which initially is half a window full.  Search commands default
+to a repeat count of one.
 
 H, h, ?         This message.
 Digits provide prefix arguments.
@@ -391,8 +408,8 @@ Digits      provide prefix arguments.
 \\[View-scroll-to-buffer-end]  scroll so that buffer end is at last line of window.
 SPC    scroll forward \"page size\" lines.
          With prefix scroll forward prefix lines.
-DEL    scroll backward \"page size\" lines.
-         With prefix scroll backward prefix lines.
+DEL, S-SPC  scroll backward \"page size\" lines.
+             With prefix scroll backward prefix lines.
 \\[View-scroll-page-forward-set-page-size]     like  \\[View-scroll-page-forward]  but with prefix sets \"page size\" to prefix.
 \\[View-scroll-page-backward-set-page-size]    like  \\[View-scroll-page-backward]  but with prefix sets \"page size\" to prefix.
 \\[View-scroll-half-page-forward]      scroll forward \"half page size\" lines.  With prefix, sets
@@ -412,7 +429,7 @@ x   exchanges point and mark.
          Mark ring is pushed at start of every successful search and when
          jump to line occurs.  The mark is set on jump to buffer start or end.
 \\[point-to-register]  save current position in character register.
-'      go to position saved in character register.
+\\='   go to position saved in character register.
 s      do forward incremental search.
 r      do reverse incremental search.
 \\[View-search-regexp-forward] searches forward for regular expression, starting after current page.
@@ -445,15 +462,13 @@ then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to th
 
 Entry to view-mode runs the normal hook `view-mode-hook'."
   :lighter " View" :keymap view-mode-map
-  (if view-mode (view-mode-enable) (view-mode-disable)))
+  (if view-mode (view--enable) (view--disable)))
 \f
-(defun view-mode-enable ()
-  "Turn on View mode."
+(defun view--enable ()
   ;; Always leave view mode before changing major mode.
   ;; This is to guarantee that the buffer-read-only variable is restored.
-  (add-hook 'change-major-mode-hook 'view-mode-disable nil t)
-  (setq view-mode t
-       view-page-size nil
+  (add-hook 'change-major-mode-hook 'view--disable nil t)
+  (setq view-page-size nil
        view-half-page-size nil
        view-old-buffer-read-only buffer-read-only
        buffer-read-only t)
@@ -464,24 +479,26 @@ Entry to view-mode runs the normal hook `view-mode-hook'."
            (format "continue viewing %s"
                    (if (buffer-file-name)
                        (file-name-nondirectory (buffer-file-name))
-                     (buffer-name)))))
-  (force-mode-line-update)
-  (run-hooks 'view-mode-hook))
+                     (buffer-name))))))
 
+
+(define-obsolete-function-alias 'view-mode-enable 'view-mode "24.4")
 (defun view-mode-disable ()
   "Turn off View mode."
-  (remove-hook 'change-major-mode-hook 'view-mode-disable t)
+  (declare (obsolete view-mode "24.4"))
+  (view-mode -1))
+
+(defun view--disable ()
+  (remove-hook 'change-major-mode-hook 'view--disable t)
   (and view-overlay (delete-overlay view-overlay))
-  (force-mode-line-update)
-  ;; Calling toggle-read-only while View mode is enabled
+  ;; Calling read-only-mode while View mode is enabled
   ;; sets view-read-only to t as a buffer-local variable
-  ;; after exiting View mode.  That arranges that the next toggle-read-only
+  ;; after exiting View mode.  That arranges that the next read-only-mode
   ;; will reenable View mode.
-  ;; Cancelling View mode in any other way should cancel that, too,
-  ;; so that View mode stays off if toggle-read-only is called.
+  ;; Canceling View mode in any other way should cancel that, too,
+  ;; so that View mode stays off if read-only-mode is called.
   (if (local-variable-p 'view-read-only)
       (kill-local-variable 'view-read-only))
-  (setq view-mode nil)
   (if (boundp 'Helper-return-blurb)
       (setq Helper-return-blurb view-old-Helper-return-blurb))
   (if buffer-read-only
@@ -492,11 +509,12 @@ Entry to view-mode runs the normal hook `view-mode-hook'."
   "Update `view-return-to-alist' of buffer BUFFER.
 Remove from `view-return-to-alist' all entries referencing dead
 windows.  Optional argument ITEM non-nil means add ITEM to
-`view-return-to-alist' after purging.  For a decsription of items
+`view-return-to-alist' after purging.  For a description of items
 that can be added see the RETURN-TO-ALIST argument of the
 function `view-mode-exit'.  If `view-return-to-alist' contains an
 entry for the selected window, purge that entry from
 `view-return-to-alist' before adding ITEM."
+  (declare (obsolete "this function has no effect." "24.1"))
   (with-current-buffer buffer
     (when view-return-to-alist
       (let* ((list view-return-to-alist)
@@ -519,7 +537,6 @@ entry for the selected window, purge that entry from
     (when item
       (setq view-return-to-alist
            (cons item view-return-to-alist)))))
-(make-obsolete 'view-return-to-alist-update "this function has no effect." "24.1")
 
 ;;;###autoload
 (defun view-mode-enter (&optional quit-restore exit-action)
@@ -544,8 +561,7 @@ This function runs the normal hook `view-mode-hook'."
     (setq view-exit-action exit-action))
 
   (unless view-mode
-    (view-mode-enable)
-    (force-mode-line-update)
+    (view-mode 1)
     (unless view-inhibit-help-message
       (message "%s"
               (substitute-command-keys "\
@@ -572,7 +588,7 @@ current buffer. "
   (when view-mode
     (let ((buffer (window-buffer)))
       (unless view-no-disable-on-exit
-       (view-mode-disable))
+       (view-mode -1))
 
       (unless exit-only
        (cond
@@ -583,8 +599,7 @@ current buffer. "
          (quit-window)))
 
        (when exit-action
-         (funcall exit-action buffer))
-       (force-mode-line-update)))))
+         (funcall exit-action buffer))))))
 \f
 (defun View-exit ()
   "Exit View mode but stay in current buffer."
@@ -920,7 +935,7 @@ for highlighting the match that is found."
 
 (defun view-search (times regexp)
   ;; This function does the job for all the View-search- commands.
-  ;; Search for the TIMESt match for REGEXP.  If TIMES is negative
+  ;; Search for the TIMESth match for REGEXP.  If TIMES is negative
   ;; search backwards.  If REGEXP is nil use `view-last-regexp'.
   ;; Characters "!" and "@" have a special meaning at the beginning of
   ;; REGEXP and are removed from REGEXP before the search "!" means