diff options
Diffstat (limited to 'lisp/view.el')
-rw-r--r-- | lisp/view.el | 169 |
1 files changed, 81 insertions, 88 deletions
diff --git a/lisp/view.el b/lisp/view.el index 026c1ece304..3476ced3f79 100644 --- a/lisp/view.el +++ b/lisp/view.el @@ -1,4 +1,4 @@ -;;; view.el --- peruse file or buffer without editing +;;; view.el --- peruse file or buffer without editing -*- lexical-binding: t -*- ;; Copyright (C) 1985, 1989, 1994-1995, 1997, 2000-2021 Free Software ;; Foundation, Inc. @@ -26,9 +26,9 @@ ;; This package provides the `view' minor mode documented in the Emacs ;; user's manual. -;; View mode entry and exit is done through the functions view-mode-enter -;; and view-mode-exit. Use these functions to enter or exit view-mode from -;; emacs lisp programs. +;; View mode entry and exit is done through the functions `view-mode-enter' +;; and `view-mode-exit'. Use these functions to enter or exit `view-mode' from +;; Emacs Lisp programs. ;; We use both view- and View- as prefix for symbols. View- is used as ;; prefix for commands that have a key binding. view- is used for commands ;; without key binding. The purpose of this is to make it easier for a @@ -36,11 +36,11 @@ ;;; Suggested key bindings: ;; -;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v -;; (define-key ctl-x-5-map "v" 'view-file-other-frame) ; ^x5v +;; (define-key ctl-x-4-map "v" #'view-file-other-window) ; ^x4v +;; (define-key ctl-x-5-map "v" #'view-file-other-frame) ; ^x5v ;; -;; You could also bind view-file, view-buffer, view-buffer-other-window and -;; view-buffer-other-frame to keys. +;; You could also bind `view-file', `view-buffer', `view-buffer-other-window' and +;; `view-buffer-other-frame' to keys. ;;; Code: @@ -51,31 +51,27 @@ :group 'text) (defcustom view-highlight-face 'highlight - "The face used for highlighting the match found by View mode search." - :type 'face - :group 'view) + "The face used for highlighting the match found by View mode search." + :type 'face) (defcustom view-scroll-auto-exit nil "Non-nil means scrolling past the end of buffer exits View mode. A value of nil means attempting to scroll past the end of the buffer, only rings the bell and gives a message on how to leave." - :type 'boolean - :group 'view) + :type 'boolean) (defcustom view-try-extend-at-buffer-end nil "Non-nil means try to load more of file when reaching end of buffer. This variable is mainly intended to be temporarily set to non-nil by -the F command in view-mode, but you can set it to t if you want the action +the F command in `view-mode', but you can set it to t if you want the action for all scroll commands in view mode." - :type 'boolean - :group 'view) + :type 'boolean) ;;;###autoload (defcustom view-remove-frame-by-deleting t "Determine how View mode removes a frame no longer needed. If nil, make an icon of the frame. If non-nil, delete the frame." :type 'boolean - :group 'view :version "23.1") (defcustom view-exits-all-viewing-windows nil @@ -84,15 +80,13 @@ Commands that restore windows when finished viewing a buffer, apply to all windows that display the buffer and have restore information. If `view-exits-all-viewing-windows' is nil, only the selected window is considered for restoring." - :type 'boolean - :group 'view) + :type 'boolean) (defcustom view-inhibit-help-message nil "Non-nil inhibits the help message shown upon entering View mode. This setting takes effect only when View mode is entered via an interactive command; otherwise the help message is not shown." :type 'boolean - :group 'view :version "22.1") ;;;###autoload @@ -103,8 +97,7 @@ functions that enable or disable view mode.") (defcustom view-mode-hook nil "Normal hook run when starting to view a buffer or file." - :type 'hook - :group 'view) + :type 'hook) (defvar-local view-old-buffer-read-only nil) @@ -154,62 +147,62 @@ This is local in each buffer, once it is used.") ;; Some redundant "less"-like key bindings below have been commented out. (defvar view-mode-map (let ((map (make-sparse-keymap))) - (define-key map "C" 'View-kill-and-leave) - (define-key map "c" 'View-leave) - (define-key map "Q" 'View-quit-all) - (define-key map "E" 'View-exit-and-edit) - ;; (define-key map "v" 'View-exit) - (define-key map "e" 'View-exit) - (define-key map "q" 'View-quit) - ;; (define-key map "N" 'View-search-last-regexp-backward) - (define-key map "p" 'View-search-last-regexp-backward) - (define-key map "n" 'View-search-last-regexp-forward) - ;; (define-key map "?" 'View-search-regexp-backward) ; Less does this. - (define-key map "\\" 'View-search-regexp-backward) - (define-key map "/" 'View-search-regexp-forward) - (define-key map "r" 'isearch-backward) - (define-key map "s" 'isearch-forward) - (define-key map "m" 'point-to-register) - (define-key map "'" 'register-to-point) - (define-key map "x" 'exchange-point-and-mark) - (define-key map "@" 'View-back-to-mark) - (define-key map "." 'set-mark-command) - (define-key map "%" 'View-goto-percent) - ;; (define-key map "G" 'View-goto-line-last) - (define-key map "g" 'View-goto-line) - (define-key map "=" 'what-line) - (define-key map "F" 'View-revert-buffer-scroll-page-forward) - ;; (define-key map "k" 'View-scroll-line-backward) - (define-key map "y" 'View-scroll-line-backward) - ;; (define-key map "j" 'View-scroll-line-forward) - (define-key map "\n" 'View-scroll-line-forward) - (define-key map "\r" 'View-scroll-line-forward) - (define-key map "u" 'View-scroll-half-page-backward) - (define-key map "d" 'View-scroll-half-page-forward) - (define-key map "z" 'View-scroll-page-forward-set-page-size) - (define-key map "w" 'View-scroll-page-backward-set-page-size) - ;; (define-key map "b" 'View-scroll-page-backward) - (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) - (define-key map "-" 'negative-argument) - (define-key map "9" 'digit-argument) - (define-key map "8" 'digit-argument) - (define-key map "7" 'digit-argument) - (define-key map "6" 'digit-argument) - (define-key map "5" 'digit-argument) - (define-key map "4" 'digit-argument) - (define-key map "3" 'digit-argument) - (define-key map "2" 'digit-argument) - (define-key map "1" 'digit-argument) - (define-key map "0" 'digit-argument) - (define-key map "H" 'describe-mode) - (define-key map "?" 'describe-mode) ; Maybe do as less instead? See above. - (define-key map "h" 'describe-mode) + (define-key map "C" #'View-kill-and-leave) + (define-key map "c" #'View-leave) + (define-key map "Q" #'View-quit-all) + (define-key map "E" #'View-exit-and-edit) + ;; (define-key map "v" #'View-exit) + (define-key map "e" #'View-exit) + (define-key map "q" #'View-quit) + ;; (define-key map "N" #'View-search-last-regexp-backward) + (define-key map "p" #'View-search-last-regexp-backward) + (define-key map "n" #'View-search-last-regexp-forward) + ;; (define-key map "?" #'View-search-regexp-backward) ; Less does this. + (define-key map "\\" #'View-search-regexp-backward) + (define-key map "/" #'View-search-regexp-forward) + (define-key map "r" #'isearch-backward) + (define-key map "s" #'isearch-forward) + (define-key map "m" #'point-to-register) + (define-key map "'" #'register-to-point) + (define-key map "x" #'exchange-point-and-mark) + (define-key map "@" #'View-back-to-mark) + (define-key map "." #'set-mark-command) + (define-key map "%" #'View-goto-percent) + ;; (define-key map "G" #'View-goto-line-last) + (define-key map "g" #'View-goto-line) + (define-key map "=" #'what-line) + (define-key map "F" #'View-revert-buffer-scroll-page-forward) + ;; (define-key map "k" #'View-scroll-line-backward) + (define-key map "y" #'View-scroll-line-backward) + ;; (define-key map "j" #'View-scroll-line-forward) + (define-key map "\n" #'View-scroll-line-forward) + (define-key map "\r" #'View-scroll-line-forward) + (define-key map "u" #'View-scroll-half-page-backward) + (define-key map "d" #'View-scroll-half-page-forward) + (define-key map "z" #'View-scroll-page-forward-set-page-size) + (define-key map "w" #'View-scroll-page-backward-set-page-size) + ;; (define-key map "b" #'View-scroll-page-backward) + (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) + (define-key map "-" #'negative-argument) + (define-key map "9" #'digit-argument) + (define-key map "8" #'digit-argument) + (define-key map "7" #'digit-argument) + (define-key map "6" #'digit-argument) + (define-key map "5" #'digit-argument) + (define-key map "4" #'digit-argument) + (define-key map "3" #'digit-argument) + (define-key map "2" #'digit-argument) + (define-key map "1" #'digit-argument) + (define-key map "0" #'digit-argument) + (define-key map "H" #'describe-mode) + (define-key map "?" #'describe-mode) ; Maybe do as less instead? See above. + (define-key map "h" #'describe-mode) map)) ;;; Commands that enter or exit view mode. @@ -220,7 +213,7 @@ This is local in each buffer, once it is used.") ;; types C-x C-q again to return to view mode. ;;;###autoload (defun kill-buffer-if-not-modified (buf) - "Like `kill-buffer', but does nothing if the buffer is modified." + "Like `kill-buffer', but does nothing if buffer BUF is modified." (let ((buf (get-buffer buf))) (and buf (not (buffer-modified-p buf)) (kill-buffer buf)))) @@ -305,7 +298,7 @@ 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. -This function does not enable View mode if the buffer's major-mode +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: ") @@ -331,7 +324,7 @@ 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 function does not enable View mode if the buffer's major-mode +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") @@ -358,7 +351,7 @@ 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 function does not enable View mode if the buffer's major-mode +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") @@ -662,8 +655,8 @@ previous state and go to previous buffer or window." (recenter '(1))) (defun view-page-size-default (lines) - ;; If LINES is nil, 0, or larger than `view-window-size', return nil. - ;; Otherwise, return LINES. + "If LINES is nil, 0, or larger than `view-window-size', return nil. +Otherwise, return LINES." (and lines (not (zerop (setq lines (prefix-numeric-value lines)))) (<= (abs lines) @@ -671,7 +664,7 @@ previous state and go to previous buffer or window." (abs lines))) (defun view-set-half-page-size-default (lines) - ;; Get and maybe set half page size. + "Get and maybe set half page size." (if (not lines) (or view-half-page-size (/ (view-window-size) 2)) (setq view-half-page-size @@ -749,7 +742,7 @@ invocations return to earlier marks." (if (view-really-at-end) (view-end-message))))) (defun view-really-at-end () - ;; Return true if buffer end visible. Maybe revert buffer and test. + "Return non-nil if buffer end visible. Maybe revert buffer and test." (and (or (null scroll-error-top-bottom) (eobp)) (pos-visible-in-window-p (point-max)) (let ((buf (current-buffer)) @@ -772,7 +765,7 @@ invocations return to earlier marks." (pos-visible-in-window-p (point-max))))))) (defun view-end-message () - ;; Tell that we are at end of buffer. + "Tell that we are at end of buffer." (goto-char (point-max)) (if (window-parameter nil 'quit-restore) (message "End of buffer. Type %s to quit viewing." @@ -979,7 +972,7 @@ for highlighting the match that is found." ;; https://lists.gnu.org/r/bug-gnu-emacs/2007-09/msg00073.html (defun view-search-no-match-lines (times regexp) "Search for the TIMESth occurrence of a line with no match for REGEXP. -If such a line is found, return non-nil and set the match-data to that line. +If such a line is found, return non-nil and set the match data to that line. If TIMES is negative, search backwards." (let ((step (if (>= times 0) 1 (setq times (- times)) |