• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/

Lines Matching +defs:set +defs:window +defs:buffer

1 ;;; view.el --- peruse file or buffer without editing
41 ;; (define-key ctl-x-4-map "v" 'view-file-other-window) ; ^x4v
44 ;; You could also bind view-file, view-buffer, view-buffer-other-window and
45 ;; view-buffer-other-frame to keys.
51 "Peruse file or buffer without editing."
63 ;; only says if scrolling past buffer end should leave view mode or not, it
67 "*Non-nil means scrolling past the end of buffer exits View mode.
68 A value of nil means attempting to scroll past the end of the buffer,
73 (defcustom view-try-extend-at-buffer-end nil
74 "*Non-nil means try to load more of file when reaching end of buffer.
75 This variable is mainly intended to be temporarily set to non-nil by
76 the F command in view-mode, but you can set it to t if you want the action
88 "*Non-nil means restore all windows used to view buffer.
89 Commands that restore windows when finished viewing a buffer, apply to all
90 windows that display the buffer and have restore information in
92 If `view-exits-all-viewing-windows' is nil, only the selected window is
109 (make-variable-buffer-local 'view-mode)
112 "Normal hook run when starting to view a buffer or file."
117 (defvar view-old-buffer-read-only nil)
118 (make-variable-buffer-local 'view-old-buffer-read-only)
121 (make-variable-buffer-local 'view-old-Helper-return-blurb)
128 If nil that means use the window size.")
129 (make-variable-buffer-local 'view-page-size)
133 If nil that means use half the window size.")
134 (make-variable-buffer-local 'view-half-page-size)
137 (make-variable-buffer-local 'view-last-regexp) ; Global is better???
140 "What to do with used windows and where to go when finished viewing buffer.
141 This is local in each buffer being viewed.
142 It is added to by `view-mode-enter' when starting to view a buffer and
143 subtracted from by `view-mode-exit' when finished viewing the buffer.
147 (make-variable-buffer-local 'view-return-to-alist)
151 "nil or a function with one argument (a buffer) called when finished viewing.
152 This is local in each buffer being viewed.
153 The \\[view-file] and \\[view-file-other-window] commands may set this to
154 `kill-buffer'.")
155 (make-variable-buffer-local 'view-exit-action)
160 This is set in certain buffers by specialized features such as help commands
165 This is local in each buffer, once it is used.")
166 (make-variable-buffer-local 'view-overlay)
200 (define-key map "." 'set-mark-command)
205 (define-key map "F" 'View-revert-buffer-scroll-page-forward)
213 (define-key map "z" 'View-scroll-page-forward-set-page-size)
214 (define-key map "w" 'View-scroll-page-backward-set-page-size)
219 (define-key map "o" 'View-scroll-to-buffer-end)
220 (define-key map ">" 'end-of-buffer)
221 (define-key map "<" 'beginning-of-buffer)
247 "View FILE in View mode, returning to previous buffer when done.
248 Emacs commands editing the buffer contents are not available; instead,
249 a special set of commands (mostly letters and punctuation)
250 are defined for moving around in the buffer.
257 (let ((had-a-buf (get-file-buffer file))
258 (buffer (find-file-noselect file)))
259 (if (eq (with-current-buffer buffer
263 (switch-to-buffer buffer)
265 (view-buffer buffer (and (not had-a-buf) 'kill-buffer)))))
268 (defun view-file-other-window (file)
269 "View FILE in View mode in another window.
270 Return that window to its previous buffer when done.
271 Emacs commands editing the buffer contents are not available; instead,
272 a special set of commands (mostly letters and punctuation)
273 are defined for moving around in the buffer.
278 (interactive "fIn other window view file: ")
280 (let ((had-a-buf (get-file-buffer file)))
281 (view-buffer-other-window (find-file-noselect file) nil
282 (and (not had-a-buf) 'kill-buffer))))
287 Maybe delete other frame and/or return to previous buffer when done.
288 Emacs commands editing the buffer contents are not available; instead,
289 a special set of commands (mostly letters and punctuation)
290 are defined for moving around in the buffer.
297 (let ((had-a-buf (get-file-buffer file)))
298 (view-buffer-other-frame (find-file-noselect file) nil
299 (and (not had-a-buf) 'kill-buffer))))
303 (defun view-buffer (buffer &optional exit-action)
304 "View BUFFER in View mode, returning to previous buffer when done.
305 Emacs commands editing the buffer contents are not available; instead,
306 a special set of commands (mostly letters and punctuation)
307 are defined for moving around in the buffer.
313 Optional argument EXIT-ACTION is either nil or a function with buffer as
314 argument. This function is called when finished viewing buffer.
317 (interactive "bView buffer: ")
318 (let ((undo-window (list (window-buffer) (window-start) (window-point))))
319 (switch-to-buffer buffer)
320 (view-mode-enter (cons (selected-window) (cons nil undo-window))
324 (defun view-buffer-other-window (buffer &optional not-return exit-action)
325 "View BUFFER in View mode in another window.
326 Return to previous buffer when done, unless optional NOT-RETURN is non-nil.
327 Emacs commands editing the buffer contents are not available; instead,
328 a special set of commands (mostly letters and punctuation)
329 are defined for moving around in the buffer.
335 Optional argument EXIT-ACTION is either nil or a function with buffer as
336 argument. This function is called when finished viewing buffer.
338 (interactive "bIn other window view buffer:\nP")
339 (let* ((win ; This window will be selected by
340 (get-lru-window)) ; switch-to-buffer-other-window below.
343 (cons (selected-window)
344 (if (eq win (selected-window))
345 t ; Has to make new window.
347 (window-buffer win) ; Other windows old buffer.
348 (window-start win)
349 (window-point win)))))))
350 (switch-to-buffer-other-window buffer)
351 (view-mode-enter (and return-to (cons (selected-window) return-to))
355 (defun view-buffer-other-frame (buffer &optional not-return exit-action)
357 Return to previous buffer when done, unless optional NOT-RETURN is non-nil.
358 Emacs commands editing the buffer contents are not available; instead,
359 a special set of commands (mostly letters and punctuation)
360 are defined for moving around in the buffer.
366 Optional argument EXIT-ACTION is either nil or a function with buffer as
367 argument. This function is called when finished viewing buffer.
369 (interactive "bView buffer in other frame: \nP")
371 (and (not not-return) (cons (selected-window) t)))) ; Old window.
372 (switch-to-buffer-other-frame buffer)
373 (view-mode-enter (and return-to (cons (selected-window) return-to))
385 Emacs commands that do not change the buffer contents are available as usual.
387 \(among them most letters and punctuation) beep and tell that the buffer is
392 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
393 and set \"half page size\" lines which initially is half a window full. Search
399 \\[beginning-of-buffer] move to the beginning of buffer.
400 > move to the end of buffer.
401 \\[View-scroll-to-buffer-end] scroll so that buffer end is at last line of window.
406 \\[View-scroll-page-forward-set-page-size] like \\[View-scroll-page-forward] but with prefix sets \"page size\" to prefix.
407 \\[View-scroll-page-backward-set-page-size] like \\[View-scroll-page-backward] but with prefix sets \"page size\" to prefix.
414 \\[View-revert-buffer-scroll-page-forward] revert-buffer if necessary and scroll forward.
417 \\[View-goto-percent] goes prefix argument (default 100) percent into buffer.
419 . set the mark.
423 jump to line occurs. The mark is set on jump to buffer start or end.
431 search at beginning (end for backward search) of buffer.
435 \\[View-quit] quit View mode, restoring this window and buffer to previous state.
437 \\[View-exit] exit View mode but stay in current buffer. Use this if you started
438 viewing a buffer (file) and find out you want to edit it.
439 This command restores the previous read-only status of the buffer.
440 \\[View-exit-and-edit] exit View mode, and make the current buffer editable
443 \\[View-leave] quit View mode and maybe switch buffers, but don't kill this buffer.
444 \\[View-kill-and-leave] quit View mode, kill current buffer and go back to other buffer.
447 entered by view-file, view-file-other-window, view-file-other-frame, or
448 \\[dired-view-file] \(\\[view-file], \\[view-file-other-window],
450 then \\[View-quit] will try to kill the current buffer.
451 If view-mode was entered from another buffer, by \\[view-buffer],
452 \\[view-buffer-other-window], \\[view-buffer-other frame], \\[view-file],
453 \\[view-file-other-window], or \\[view-file-other-frame],
454 then \\[View-leave], \\[View-quit] and \\[View-kill-and-leave] will return to that buffer.
467 ;; This is to guarantee that the buffer-read-only variable is restored.
472 view-old-buffer-read-only buffer-read-only
473 buffer-read-only t
478 (if (buffer-file-name)
479 (file-name-nondirectory (buffer-file-name))
480 (buffer-name))))
490 ;; sets view-read-only to t as a buffer-local variable
499 (if buffer-read-only
500 (setq buffer-read-only view-old-buffer-read-only)))
504 Enter View mode and set up exit from view mode depending on optional arguments.
505 If RETURN-TO is non-nil it is added as an element to the buffer local alist
507 Save EXIT-ACTION in buffer local variable `view-exit-action'.
508 It should be either nil or a function that takes a buffer as argument.
513 WINDOW is a window used for viewing.
514 OLD-WINDOW is nil or the window to select after viewing.
517 2) t Delete WINDOW or, if it is the only window, its frame.
518 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text
520 4) quit-window Do `quit-window' in WINDOW.
542 EXIT-ACTION is nil or a function that is called with current buffer as
545 current buffer, associate information on what to do with those windows.
548 Otherwise only the selected window is affected (if it is on RETURN-TO-ALIST).
551 WINDOW is a window displaying the current buffer.
552 OLD-WINDOW is nil or a window to select after viewing.
555 2) t Delete WINDOW and, if it is the only window, its frame.
556 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text
558 4) quit-window Do `quit-window' in WINDOW.
560 If one of the WINDOW in RETURN-TO-ALIST is the selected window and the
561 corresponding OLD-WINDOW is a live window, then select OLD-WINDOW."
565 (let* ((buffer (current-buffer))
566 window notlost
567 (sel-old (assq (selected-window) return-to-alist))
571 (sel-old ; Only selected window.
573 (old-window (if sel-old (car (cdr sel-old)))))
577 (or (not (window-live-p old-window))
578 (eq buffer (window-buffer old-window)))
579 (setq a (assq old-window alist)))
581 (setq old-window (car (cdr a))))
582 (if (or (zerop c) (not (window-live-p old-window)))
583 (setq old-window (selected-window)))))
588 (if (and (window-live-p (setq window (car (car alist))))
589 (eq buffer (window-buffer window)))
590 (let ((frame (window-frame window))
592 (if all-win (select-window window))
595 (buffer-live-p (car old-buf-info)))
596 (set-window-buffer window (car old-buf-info)) ; old-buf
597 (set-window-start window (car (cdr old-buf-info)))
598 (set-window-point window (car (cdr (cdr old-buf-info)))))
599 ((eq old-buf-info 'quit-window)
600 (quit-window)) ; Case 4.
602 ((not (one-window-p t)) (delete-window))
607 (setq notlost t) ; Keep the window. See below.
609 ;; If a frame is removed by iconifying it, then the window is not
617 (if (window-live-p old-window) ; still existing window
618 (select-window old-window))
621 (funcall exit-action buffer))
626 "Exit View mode but stay in current buffer."
632 "Exit View mode and make the current buffer editable."
634 (let ((view-old-buffer-read-only nil)
639 "Quit View mode and maybe switch buffers, but don't kill this buffer."
644 "Quit View mode, trying to restore window and buffer to previous state.
645 Maybe kill this buffer. Try to restore selected window to previous state
646 and go to previous buffer or window."
652 Maybe kill current buffer. Try to restore all windows viewing buffer to
653 previous state and go to previous buffer or window."
658 "Quit View mode, kill current buffer and return to previous buffer."
660 (view-mode-exit view-return-to-alist (or view-exit-action 'kill-buffer) t))
666 (defun view-window-size ()
668 (1- (window-height)))
684 ;; Center point in window.
685 (recenter (/ (view-window-size) 2)))
689 (let ((default (- (view-window-size) next-screen-context-lines)))
694 (defun view-set-half-page-size-default (lines)
695 ;; Get and maybe set half page size.
697 (/ (view-window-size) 2))
700 (/ (view-window-size) 2)
704 ;;; Commands for moving around in the buffer.
707 "Move to end (or prefix PERCENT) of buffer in View mode.
709 Also set the mark at the position where point was."
734 Also set the mark at the position where point was."
741 "Return to last mark set in View mode, else beginning of file.
742 Display that line at the center of the window.
756 ;; window full.
775 (move-to-window-line -1)
779 ;; Return true if buffer end visible. Maybe revert buffer and test.
780 (and (pos-visible-in-window-p (point-max))
781 (let ((buf (current-buffer))
782 (bufname (buffer-name))
783 (file (buffer-file-name)))
784 (or (not view-try-extend-at-buffer-end)
788 (when (buffer-modified-p buf)
797 (revert-buffer t t t)
798 (pos-visible-in-window-p (point-max)))))))
801 ;; Tell that we are at end of buffer.
804 (message "End of buffer. Type %s to quit viewing."
808 (message "End of buffer")))
811 (defun View-scroll-to-buffer-end ()
812 "Scroll backward or forward so that buffer end is at last line of window."
814 (let ((p (if (pos-visible-in-window-p (point-max)) (point))))
822 \"page size\" is whole window full, or number of lines set by
823 \\[View-scroll-page-forward-set-page-size] or
824 \\[View-scroll-page-backward-set-page-size].
825 If LINES is more than a window-full, only the last window-full is shown."
835 (defun View-scroll-page-forward-set-page-size (&optional lines)
839 If LINES is omitted or = 0, sets \"page size\" to window height and
841 \"page size\" to the minimum of window height and the absolute value of LINES.
848 (defun View-scroll-page-backward-set-page-size (&optional lines)
850 See also `View-scroll-page-forward-set-page-size'."
859 to minimum of LINES and one window-full."
871 If LINES is not omitted, the \"half page size\" is set to the minimum of
872 window height and the absolute value of LINES.
873 LINES=0 resets \"half page size\" to half window height."
875 (view-scroll-lines lines nil (view-set-half-page-size-default lines) t))
881 (view-scroll-lines lines t (view-set-half-page-size-default lines) t))
883 (defun View-revert-buffer-scroll-page-forward (&optional lines)
884 "Scroll forward, reverting buffer if needed, in View mode.
885 If buffer has not been changed and the corresponding file is newer, first
886 revert the buffer, then scroll.
890 If you don't specify a prefix argument, it uses the number of lines set by
891 \\[View-scroll-page-forward-set-page-size] or
892 \\[View-scroll-page-backward-set-page-size].
893 If LINES is more than a window-full, only the last window-full is shown."
896 (view-try-extend-at-buffer-end t))
903 Displays line found at center of window. Sets mark at starting position and
908 @ means search all the buffer i.e. start search at the beginning of buffer.
922 Displays line found at center of window. Sets mark at starting position and
927 @ means search all the buffer i.e. start search at the end of buffer.
940 Displays line found at center of window. Sets mark at starting position and
950 Displays line found at center of window. Sets mark at starting position and
965 ;; the whole buffer, don't start searching from the present point.
985 (move-to-window-line (if (< times 0) 0 -1)))