diff options
| author | Richard M. Stallman | 1995-03-12 09:05:52 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-03-12 09:05:52 +0000 |
| commit | 495a2b0aa04642a60f0ab29cdee03fedf5cacc88 (patch) | |
| tree | e582eb1086351764cb542dd3ff6c8a062ded7433 | |
| parent | ed17d24fe498d499b45e57cc1ba8f485cc41fa4f (diff) | |
| download | emacs-495a2b0aa04642a60f0ab29cdee03fedf5cacc88.tar.gz emacs-495a2b0aa04642a60f0ab29cdee03fedf5cacc88.zip | |
Initial revision
| -rw-r--r-- | lisp/auto-show.el | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/lisp/auto-show.el b/lisp/auto-show.el new file mode 100644 index 00000000000..d4384ef3369 --- /dev/null +++ b/lisp/auto-show.el | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | ;; LCD Archive Entry: | ||
| 2 | ;; auto-show|Pete Ware|ware@cis.ohio-state.edu| | ||
| 3 | ;; Automatically scroll horizontally| | ||
| 4 | ;; 95-02-24|1.9|~/misc/auto-show.el| | ||
| 5 | ;; | ||
| 6 | ;;; | ||
| 7 | ;;; Author: | ||
| 8 | ;;; | ||
| 9 | ;;; Pete Ware ware@cis.ohio-state.edu | ||
| 10 | ;;; CIS Dept, Ohio State University w/ (614) 292-8501 | ||
| 11 | ;;; 774 Dreese, 2015 Neil Ave. h/ (614) 791-1347 | ||
| 12 | ;;; Columbus, OH 43210 http://www.cis.ohio-state.edu/~ware | ||
| 13 | ;;; | ||
| 14 | ;;; | ||
| 15 | ;;; Modification history: | ||
| 16 | ;;; 02/24/95 Added auto-show-show-left-margin-threshold so that if | ||
| 17 | ;;; there is anyway for the left margin to be displayed it is. | ||
| 18 | ;;; 02/24/95 Only scroll window if it matches current buffer. Added | ||
| 19 | ;;; function for enabeling scrolling in comint buffers on output. | ||
| 20 | ;;; 02/13/95 Aded Kevin Broadey <KevinB@bartley.demon.co.uk> fix so that | ||
| 21 | ;;; it doesn't scroll if we are at window border and at the | ||
| 22 | ;;; end of the line (i.e. newline character) | ||
| 23 | ;;; 02/10/95 jeff.dwork@amd.com added auto-show-toggle function. | ||
| 24 | ;;; 02/08/95 Added auto-show-enable as per | ||
| 25 | ;;; jeff.dwork@amd.com (Jeff Dwork)'s suggestion. Cleaned up | ||
| 26 | ;;; documentation. | ||
| 27 | ;;; 02/07/95 Rewrote for emacs 19: much, much cleaner. Renamed auto-show | ||
| 28 | ;;; 8/6/90 Make next-line/previous-line do better job following movement. | ||
| 29 | ;;; 3/21/90 better calculation of w-width in e-make-point-visible | ||
| 30 | ;;; test for truncated windows | ||
| 31 | ;;; added substitute-in-keymap | ||
| 32 | ;;; renamed to auto-horizontal | ||
| 33 | ;;; added backward-delete-char | ||
| 34 | ;;; 8/13/88 Created | ||
| 35 | |||
| 36 | ;;; | ||
| 37 | ;;; This is a rewrite of auto-horizontal. It is comparable in | ||
| 38 | ;;; functionality to hscroll.el except it is not a minor mode and does | ||
| 39 | ;;; not use any timers. This file provides functions that | ||
| 40 | ;;; automatically scroll the window horizontally when the point moves | ||
| 41 | ;;; off the left or right side of the window. To load it just add: | ||
| 42 | ;;; (require 'auto-show) | ||
| 43 | ;;; to your .emacs. | ||
| 44 | ;;; | ||
| 45 | ;;; Setting the variable ``truncate-lines'' to non-nil causes long | ||
| 46 | ;;; lines to disappear off the end of the screen instead of wrapping | ||
| 47 | ;;; to the beginning of the next line. To make this the default for | ||
| 48 | ;;; all buffers add the following line to your .emacs (sans ;;;): | ||
| 49 | ;;; | ||
| 50 | ;;; (set-default 'truncate-lines t) | ||
| 51 | ;;; | ||
| 52 | |||
| 53 | ;;; However, I've found that I only want this when I'm editing C code. | ||
| 54 | ;;; Accordingly I have something like the following in my .emacs: | ||
| 55 | ;;; | ||
| 56 | ;;; (set-default 'truncate-lines nil) ; this is the original value | ||
| 57 | ;;; (defun my-c-mode-hook () | ||
| 58 | ;;; "Run when C-mode starts up. Changes ..." | ||
| 59 | ;;; ... set various personal preferences ... | ||
| 60 | ;;; (setq truncate-lines t)) | ||
| 61 | ;;; (add-hook 'c-mode-hook 'my-c-mode-hook) | ||
| 62 | ;;; | ||
| 63 | ;;; | ||
| 64 | ;;; As a finer level of control, one can still have truncated lines but | ||
| 65 | ;;; without the automatic left and right scrolling by setting the buffer | ||
| 66 | ;;; local variable ``auto-show-enable'' to nil. The default value is t. | ||
| 67 | ;;; The command ``auto-show-toggle'' will toggle the value of | ||
| 68 | ;;; ``auto-show-enable''. | ||
| 69 | ;;; | ||
| 70 | ;;; | ||
| 71 | ;;; I also like the output from my shell's (and other comint.el based commands) | ||
| 72 | ;;; to scroll on output. One can call: | ||
| 73 | ;;; | ||
| 74 | ;;; (auto-show-comint-make-point-visible) | ||
| 75 | ;;; | ||
| 76 | ;;; which adds auto-show-make-point-visible to comint-output-filter-functions. | ||
| 77 | |||
| 78 | (provide 'auto-show) | ||
| 79 | |||
| 80 | ;;;************************************************************ | ||
| 81 | ;;;* | ||
| 82 | ;;;* Define Automatic Horizontal Scrolling Functions | ||
| 83 | ;;;* | ||
| 84 | ;;;************************************************************ | ||
| 85 | |||
| 86 | (add-hook 'post-command-hook 'auto-show-make-point-visible) | ||
| 87 | |||
| 88 | (defvar auto-show-enable t | ||
| 89 | "*Allows one to turn off automatic horizontal scrolling on a per buffer | ||
| 90 | basis independent of whether truncate-lines is t. The default value is t. | ||
| 91 | To change the default: | ||
| 92 | (set-default 'auto-show-enable nil) | ||
| 93 | Any time auto-show-enable is changed it is only in the current buffer: | ||
| 94 | (setq auto-show-enable nil) | ||
| 95 | turns it on for this buffer. | ||
| 96 | See also command `auto-show-toggle'.") | ||
| 97 | |||
| 98 | (make-variable-buffer-local 'auto-show-enable) | ||
| 99 | |||
| 100 | (defvar auto-show-shift-amount 8 | ||
| 101 | "*Extra amount to shift a line when point is not visible.") | ||
| 102 | |||
| 103 | (defvar auto-show-show-left-margin-threshold 50 | ||
| 104 | "*Point must be before this column for us to try and make the left margin | ||
| 105 | visible. Setting this to 0 disables this feature.") | ||
| 106 | |||
| 107 | (defun auto-show-truncationp () | ||
| 108 | "True if truncation is on for current window." | ||
| 109 | (or truncate-lines | ||
| 110 | (and truncate-partial-width-windows | ||
| 111 | (< (window-width) (frame-width))))) | ||
| 112 | |||
| 113 | (defun auto-show-toggle () | ||
| 114 | "Toggle value of auto-show-enable." | ||
| 115 | (interactive) | ||
| 116 | (setq auto-show-enable (not auto-show-enable))) | ||
| 117 | |||
| 118 | (defun auto-show-make-point-visible (&optional ignore-arg) | ||
| 119 | "Scrolls the screen horizontally to make point visible but only if | ||
| 120 | auto-show-enable is non-nil and lines are truncated. See also variable | ||
| 121 | `auto-show-enable' and command `auto-show-toggle'." | ||
| 122 | (interactive) | ||
| 123 | (if (and auto-show-enable (auto-show-truncationp) | ||
| 124 | (equal (window-buffer) (current-buffer))) | ||
| 125 | (let* ((col (current-column)) ;column on line point is at | ||
| 126 | (scroll (window-hscroll)) ;how far window is scrolled | ||
| 127 | (w-width (- (window-width) | ||
| 128 | (if (> scroll 0) | ||
| 129 | 2 1))) ;how wide window is on the screen | ||
| 130 | (right-col (+ scroll w-width))) | ||
| 131 | (if (and (< col auto-show-show-left-margin-threshold) | ||
| 132 | (< col (window-width)) | ||
| 133 | (> scroll 0)) | ||
| 134 | (scroll-right scroll) | ||
| 135 | (if (< col scroll) ;to the left of the screen | ||
| 136 | (scroll-right (+ (- scroll col) auto-show-shift-amount)) | ||
| 137 | (if (or (> col right-col) ;to the right of the screen | ||
| 138 | (and (= col right-col) | ||
| 139 | (not (eolp)))) | ||
| 140 | (scroll-left (+ auto-show-shift-amount | ||
| 141 | (- col (+ scroll w-width)))) | ||
| 142 | ) | ||
| 143 | ) | ||
| 144 | ) | ||
| 145 | ) | ||
| 146 | ) | ||
| 147 | ) | ||
| 148 | |||
| 149 | (defun auto-show-comint-make-point-visible () | ||
| 150 | "Add a function to comint-output-filter-functions that auto-scrolls | ||
| 151 | left or right on output to the buffer. | ||
| 152 | |||
| 153 | NOTE: you should load comint mode before this as comint.el uses a | ||
| 154 | defvar to initialize comint-output-filter-functions to the default value." | ||
| 155 | (interactive) | ||
| 156 | (add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t) | ||
| 157 | ) | ||
| 158 | |||
| 159 | ;; end of auto-show.el | ||
| 160 | |||