aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1997-10-16 18:20:16 +0000
committerKarl Heuer1997-10-16 18:20:16 +0000
commitcae551977cab69d462ae589776f3e12833a41b6b (patch)
tree5e1115eda6e11908499a4d302aa1f9e8f7712dfe
parenta6351b48608188297bf7e7a4861490fa85d4183a (diff)
downloademacs-cae551977cab69d462ae589776f3e12833a41b6b.tar.gz
emacs-cae551977cab69d462ae589776f3e12833a41b6b.zip
Some changes in comments and documentation.
View mode hooked into the customize tree. (view): New custom group. (view-highlight-face, view-scroll-auto-exit) (view-try-extend-at-buffer-end) (view-remove-frame-by-deleting, view-mode-hook): Defined by defcustom instead of by defvar. (view-mode-enter): Install exit-action also when view-mode is already on. Small rewrite using unless. (view-mode, view-mode-exit, view-scroll-lines, view-really-at-end) (view-search): Small rewrite using when or unless.
-rw-r--r--lisp/view.el130
1 files changed, 79 insertions, 51 deletions
diff --git a/lisp/view.el b/lisp/view.el
index 6c5b7446e17..8d7de369d20 100644
--- a/lisp/view.el
+++ b/lisp/view.el
@@ -30,7 +30,7 @@
30;; and view-mode-exit. Use these functions to enter or exit view-mode from 30;; and view-mode-exit. Use these functions to enter or exit view-mode from
31;; emacs lisp programs. 31;; emacs lisp programs.
32;; We use both view- and View- as prefix for symbols. View- is used as 32;; We use both view- and View- as prefix for symbols. View- is used as
33;; prefix for commands that have a key binding. view- is used for commands 33;; prefix for commands that have a key binding. view- is used for commands
34;; without key binding. The purpose of this is to make it easier for a 34;; without key binding. The purpose of this is to make it easier for a
35;; user to use command name completion. 35;; user to use command name completion.
36 36
@@ -44,45 +44,70 @@
44 44
45;;; Code: 45;;; Code:
46 46
47;;;###autoload 47(defgroup view nil
48(defvar view-highlight-face 'highlight 48 "Peruse file or buffer without editing."
49 "*The face used for highlighting the match found by View mode search.") 49 :link '(function-link view-mode)
50 :link '(custom-manual "(emacs)Misc File Ops")
51 :group 'wp
52 :group 'editing)
53
54(defcustom view-read-only nil
55 "*Non-nil means buffers visiting files read-only, do it in view mode."
56 :type 'boolean
57 :group 'view)
58
59(defcustom view-highlight-face 'highlight
60 "*The face used for highlighting the match found by View mode search."
61 :type 'face
62 :group 'view)
50 63
51;; `view-mode-auto-exit' is replaced by the following option variable which 64;; `view-mode-auto-exit' is replaced by the following option variable which
52;; only says if scrolling past buffer end should leave view mode or not, it 65;; only says if scrolling past buffer end should leave view mode or not, it
53;; doesn't say if leaving view mode should restore windows or not. The latter 66;; doesn't say if leaving view mode should restore windows or not. The latter
54;; is now controlled by the presence of a value in `view-return-to-alist'. 67;; is now controlled by the presence of a value in `view-return-to-alist'.
55;;;###autoload 68(defcustom view-scroll-auto-exit nil
56(defvar view-scroll-auto-exit nil
57 "*Non-nil means scrolling past the end of buffer exits View mode. 69 "*Non-nil means scrolling past the end of buffer exits View mode.
58nil means attempting to scroll past the end of the buffer, 70nil means attempting to scroll past the end of the buffer,
59only rings the bell and gives a message on how to leave.") 71only rings the bell and gives a message on how to leave."
72 :type 'boolean
73 :group 'view)
60 74
61;;;###autoload 75(defcustom view-try-extend-at-buffer-end nil
62(defvar view-try-extend-at-buffer-end nil
63 "*Non-nil means try load more of file when reaching end of buffer. 76 "*Non-nil means try load more of file when reaching end of buffer.
64This variable is mainly intended to be temporarily set to non-nil by 77This variable is mainly intended to be temporarily set to non-nil by
65the F command in view-mode, but you can set it to t if you want the action 78the F command in view-mode, but you can set it to t if you want the action
66for all scroll commands in view mode.") 79for all scroll commands in view mode."
80 :type 'boolean
81 :group 'view)
67 82
68(defvar view-remove-frame-by-deleting nil 83(defcustom view-remove-frame-by-deleting nil
69 "*Determine how to View mode removes a frame no longer needed. 84 "*Determine how View mode removes a frame no longer needed.
70If nil, make an icon of the frame. If non-nil, delete the frame.") 85If nil, make an icon of the frame. If non-nil, delete the frame."
86 :type 'boolean
87 :group 'view)
71 88
72;;;###autoload 89(defcustom view-exits-all-viewing-windows nil
73(defvar view-exits-all-viewing-windows nil
74 "*Non-nil means restore all windows used to view buffer. 90 "*Non-nil means restore all windows used to view buffer.
75Commands that restore windows when finished viewing a buffer, apply to all 91Commands that restore windows when finished viewing a buffer, apply to all
76windows that display the buffer and have restore information in 92windows that display the buffer and have restore information in
77`view-return-to-alist'.") 93`view-return-to-alist'.
94If view-exits-all-viewing-windows is nil only the selected window is
95considered for restoring."
96 :type 'boolean
97 :group 'view)
78 98
79;;;###autoload 99;;;###autoload
80(defvar view-mode nil "Non-nil if View mode is enabled.") 100(defvar view-mode nil
101 "Non-nil if View mode is enabled.
102Don't change this variable directly, you must change it by one of the
103functions that enable or disable view mode.")
81;;;###autoload 104;;;###autoload
82(make-variable-buffer-local 'view-mode) 105(make-variable-buffer-local 'view-mode)
83 106
84(defvar view-mode-hook nil 107(defcustom view-mode-hook nil
85 "Normal hook run when starting to view a buffer or file.") 108 "Normal hook run when starting to view a buffer or file."
109 :type 'hook
110 :group 'view)
86 111
87(defvar view-old-buffer-read-only nil) 112(defvar view-old-buffer-read-only nil)
88(make-variable-buffer-local 'view-old-buffer-read-only) 113(make-variable-buffer-local 'view-old-buffer-read-only)
@@ -136,6 +161,7 @@ This is local in each buffer, once it is used.")
136 (cons '(view-mode " View") minor-mode-alist))) 161 (cons '(view-mode " View") minor-mode-alist)))
137 162
138;; Define keymap inside defvar to make it easier to load changes. 163;; Define keymap inside defvar to make it easier to load changes.
164;; Some redundant "less"-like key bindings below have been commented out.
139(defvar view-mode-map 165(defvar view-mode-map
140 (let ((map (make-sparse-keymap))) 166 (let ((map (make-sparse-keymap)))
141 (define-key map "C" 'View-kill-and-leave) 167 (define-key map "C" 'View-kill-and-leave)
@@ -398,12 +424,10 @@ to that buffer.
398 424
399Entry to view-mode runs the normal hook `view-mode-hook'." 425Entry to view-mode runs the normal hook `view-mode-hook'."
400 (interactive "P") 426 (interactive "P")
401 (cond 427 (unless (and arg ; Do nothing if already OK.
402 ((and arg 428 (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode)))
403 (if (> (prefix-numeric-value arg) 0) view-mode (not view-mode))) 429 (if view-mode (view-mode-disable)
404 ()) ; Do nothing if already OK. 430 (view-mode-enable))))
405 (view-mode (view-mode-disable))
406 (t (view-mode-enable))))
407 431
408(defun view-mode-enable () 432(defun view-mode-enable ()
409 "Turn on View mode." 433 "Turn on View mode."
@@ -459,10 +483,9 @@ This function runs the normal hook `view-mode-hook'."
459 (let ((entry (assq (car return-to) view-return-to-alist))) 483 (let ((entry (assq (car return-to) view-return-to-alist)))
460 (if entry (setcdr entry (cdr return-to)) 484 (if entry (setcdr entry (cdr return-to))
461 (setq view-return-to-alist (cons return-to view-return-to-alist))))) 485 (setq view-return-to-alist (cons return-to view-return-to-alist)))))
462 (if view-mode ; Do nothing if already in view mode. 486 (if exit-action (setq view-exit-action exit-action))
463 nil 487 (unless view-mode ; Do nothing if already in view mode.
464 (view-mode-enable) 488 (view-mode-enable)
465 (if exit-action (setq view-exit-action exit-action))
466 (force-mode-line-update) 489 (force-mode-line-update)
467 (message "%s" 490 (message "%s"
468 (substitute-command-keys "\ 491 (substitute-command-keys "\
@@ -470,8 +493,7 @@ Type \\[help-command] for help, \\[describe-mode] for commands, \\[View-quit] to
470 493
471(defun view-mode-exit (&optional return-to-alist exit-action all-win) 494(defun view-mode-exit (&optional return-to-alist exit-action all-win)
472 "Exit view-mode in various ways, depending on optional arguments. 495 "Exit view-mode in various ways, depending on optional arguments.
473RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after 496RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after exit.
474exit.
475EXIT-ACTION is nil or a function that is called with current buffer as 497EXIT-ACTION is nil or a function that is called with current buffer as
476argument. 498argument.
477RETURN-TO-ALIST is an alist that for some of the windows displaying the 499RETURN-TO-ALIST is an alist that for some of the windows displaying the
@@ -538,10 +560,9 @@ corresponding OLD-WINDOW is a live window, then select OLD-WINDOW."
538 (setq alist (cdr alist))) 560 (setq alist (cdr alist)))
539 (if (window-live-p old-window) ; still existing window 561 (if (window-live-p old-window) ; still existing window
540 (select-window old-window)) 562 (select-window old-window))
541; (if (and exit-action (not (get-buffer-window buffer))) 563 (when exit-action
542 (if exit-action 564 (setq view-exit-action nil)
543 (progn (setq view-exit-action nil) 565 (funcall exit-action buffer))
544 (funcall exit-action buffer)))
545 (force-mode-line-update)))) 566 (force-mode-line-update))))
546 567
547(defun View-exit () 568(defun View-exit ()
@@ -672,8 +693,8 @@ Also set the mark at the position where point was."
672 ;; window full. 693 ;; window full.
673 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines)))) 694 (if (or (null lines) (zerop (setq lines (prefix-numeric-value lines))))
674 (setq lines default)) 695 (setq lines default))
675 (if (< lines 0) 696 (when (< lines 0)
676 (progn (setq backward (not backward)) (setq lines (- lines)))) 697 (setq backward (not backward)) (setq lines (- lines)))
677 (setq default (view-page-size-default nil)) ; Max scrolled at a time. 698 (setq default (view-page-size-default nil)) ; Max scrolled at a time.
678 (if maxdefault (setq lines (min lines default))) 699 (if maxdefault (setq lines (min lines default)))
679 (cond 700 (cond
@@ -697,20 +718,21 @@ Also set the mark at the position where point was."
697 (let ((buf (current-buffer)) 718 (let ((buf (current-buffer))
698 (bufname (buffer-name)) 719 (bufname (buffer-name))
699 (file (buffer-file-name))) 720 (file (buffer-file-name)))
700 (or (not view-try-extend-at-buffer-end) 721 (when (and view-try-extend-at-buffer-end
701 (not file) 722 file
702 (verify-visited-file-modtime buf) 723 (not (verify-visited-file-modtime buf))
703 (not (file-exists-p file)) 724 (file-exists-p file)
704 (and (buffer-modified-p buf) 725 (or (not (buffer-modified-p buf))
705 (setq file (file-name-nondirectory file)) 726 (progn
706 (not (yes-or-no-p 727 (setq file (file-name-nondirectory file))
707 (format 728 (yes-or-no-p
708 "File %s changed on disk. Discard your edits%s? " 729 (format
709 file 730 "File %s changed on disk. Discard your edits%s? "
710 (if (string= bufname file) "" 731 file
711 (concat " in " bufname)))))) 732 (if (string= bufname file) ""
712 (progn (revert-buffer t t t) 733 (concat " in " bufname)))))))
713 (pos-visible-in-window-p (point-max))))))) 734 (revert-buffer t t t)
735 (pos-visible-in-window-p (point-max))))))
714 736
715(defun view-end-message () 737(defun view-end-message ()
716 ;; Tell that we are at end of buffer. 738 ;; Tell that we are at end of buffer.
@@ -872,6 +894,12 @@ for highlighting the match that is found."
872 894
873(defun view-search (times regexp) 895(defun view-search (times regexp)
874 ;; This function does the job for all the View-search- commands. 896 ;; This function does the job for all the View-search- commands.
897 ;; Search for the TIMESt match for REGEXP. If TIMES is negative
898 ;; search backwards. If REGEXP is nil use `view-last-regexp'.
899 ;; Charcters "!" and "@" have a special meaning at the beginning of
900 ;; REGEXP and are removed from REGEXP before the search "!" means
901 ;; search for lines with no match for REGEXP. "@" means search in
902 ;; the whole buffer, don't start searching from the present point.
875 (let (where no end ln) 903 (let (where no end ln)
876 (cond 904 (cond
877 ((and regexp (> (length regexp) 0) 905 ((and regexp (> (length regexp) 0)
@@ -885,7 +913,7 @@ for highlighting the match that is found."
885 (setq view-last-regexp (if no (list regexp) regexp))) 913 (setq view-last-regexp (if no (list regexp) regexp)))
886 ((consp view-last-regexp) 914 ((consp view-last-regexp)
887 (setq regexp (car view-last-regexp)) 915 (setq regexp (car view-last-regexp))
888 (if (not (setq no (not no))) (setq view-last-regexp regexp))) 916 (unless (setq no (not no)) (setq view-last-regexp regexp)))
889 (view-last-regexp (setq regexp view-last-regexp) 917 (view-last-regexp (setq regexp view-last-regexp)
890 (if no (setq view-last-regexp (list regexp)))) 918 (if no (setq view-last-regexp (list regexp))))
891 (t (error "No previous View-mode search"))) 919 (t (error "No previous View-mode search")))