0
|
1 ;;; auto-show.el --- perform automatic horizontal scrolling as point moves
|
155
|
2
|
|
3 ;; This file is in the public domain.
|
0
|
4
|
155
|
5 ;; Author: Pete Ware <ware@cis.ohio-state.edu>
|
|
6 ;; Modified by: Ben Wing <wing@666.com>
|
|
7 ;; Maintainer: XEmacs Development Team
|
|
8 ;; Keywords: extensions, internal
|
0
|
9
|
2
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
|
26
|
155
|
27 ;;; Synched up with: Emacs/Mule zeta.
|
0
|
28
|
|
29 ;;; Commentary:
|
|
30
|
155
|
31 ;; This file provides functions that
|
|
32 ;; automatically scroll the window horizontally when the point moves
|
|
33 ;; off the left or right side of the window.
|
0
|
34
|
155
|
35 ;; Once this library is loaded, automatic horizontal scrolling
|
|
36 ;; occurs whenever long lines are being truncated.
|
|
37 ;; To request truncation of long lines, set the variable
|
|
38 ;; Setting the variable `truncate-lines' to non-nil.
|
|
39 ;; You can do this for all buffers as follows:
|
|
40 ;;
|
|
41 ;; (set-default 'truncate-lines t)
|
0
|
42
|
155
|
43 ;; Here is how to do it for C mode only:
|
|
44 ;;
|
|
45 ;; (set-default 'truncate-lines nil) ; this is the original value
|
|
46 ;; (defun my-c-mode-hook ()
|
|
47 ;; "Run when C-mode starts up. Changes ..."
|
|
48 ;; ... set various personal preferences ...
|
|
49 ;; (setq truncate-lines t))
|
|
50 ;; (add-hook 'c-mode-hook 'my-c-mode-hook)
|
|
51 ;;
|
|
52 ;;
|
|
53 ;; As a finer level of control, you can still have truncated lines but
|
|
54 ;; without the automatic horizontal scrolling by setting the buffer
|
|
55 ;; local variable `auto-show-mode' to nil. The default value is t.
|
|
56 ;; The command `auto-show-mode' toggles the value of the variable
|
|
57 ;; `auto-show-mode'.
|
0
|
58
|
|
59 ;;; Code:
|
|
60
|
167
|
61 (defgroup auto-show nil
|
|
62 "Perform automatic horizontal scrolling as point moves."
|
|
63 :group 'display
|
|
64 :group 'extensions)
|
|
65
|
|
66 ;; This is preloaded, so we don't need special :set, :require, etc.
|
|
67 (defcustom auto-show-mode t
|
0
|
68 "*Non-nil enables automatic horizontal scrolling, when lines are truncated.
|
|
69 The default value is t. To change the default, do this:
|
|
70 (set-default 'auto-show-mode nil)
|
|
71 See also command `auto-show-mode'.
|
155
|
72 This variable has no effect when lines are not being truncated.
|
167
|
73 This variable is automatically local in each buffer where it is set."
|
|
74 :type 'boolean
|
|
75 :group 'auto-show)
|
0
|
76
|
|
77 (make-variable-buffer-local 'auto-show-mode)
|
|
78
|
167
|
79 (defcustom auto-show-shift-amount 8
|
|
80 "*Extra columns to scroll. for automatic horizontal scrolling."
|
|
81 :type 'integer
|
|
82 :group 'auto-show)
|
0
|
83
|
167
|
84 (defcustom auto-show-show-left-margin-threshold 50
|
0
|
85 "*Threshold column for automatic horizontal scrolling to the right.
|
|
86 If point is before this column, we try to scroll to make the left margin
|
167
|
87 visible. Setting this to 0 disables this feature."
|
|
88 :type 'number
|
|
89 :group 'auto-show)
|
0
|
90
|
|
91 (defun auto-show-truncationp ()
|
|
92 "True if line truncation is enabled for the selected window."
|
2
|
93 ;; XEmacs change (use specifiers)
|
0
|
94 ;; ### There should be a more straightforward way to do this from elisp.
|
|
95 (or truncate-lines
|
|
96 (and truncate-partial-width-windows
|
|
97 (< (+ (window-width)
|
|
98 (specifier-instance left-margin-width)
|
|
99 (specifier-instance right-margin-width))
|
|
100 (frame-width)))))
|
|
101
|
|
102 (defun auto-show-mode (arg)
|
|
103 "Turn automatic horizontal scroll mode on or off.
|
155
|
104 With arg, turn auto scrolling on if arg is positive, off otherwise.
|
|
105 This mode is enabled or disabled for each buffer individually.
|
|
106 It takes effect only when `truncate-lines' is non-nil."
|
0
|
107 (interactive "P")
|
|
108 (setq auto-show-mode
|
|
109 (if (null arg)
|
|
110 (not auto-show-mode)
|
|
111 (> (prefix-numeric-value arg) 0))))
|
|
112
|
2
|
113 ;; XEmacs addition:
|
0
|
114 (defvar auto-show-inhibiting-commands
|
|
115 '(scrollbar-char-left
|
|
116 scrollbar-char-right
|
|
117 scrollbar-page-left
|
|
118 scrollbar-page-right
|
|
119 scrollbar-to-left
|
|
120 scrollbar-to-right
|
|
121 scrollbar-horizontal-drag)
|
|
122 "Commands that inhibit auto-show behavior.
|
|
123 This normally includes the horizontal scrollbar commands.")
|
|
124
|
2
|
125 ;; XEmacs addition:
|
0
|
126 (defun auto-show-should-take-action-p ()
|
|
127 (and auto-show-mode (auto-show-truncationp)
|
|
128 (equal (window-buffer) (current-buffer))
|
|
129 (not (memq this-command auto-show-inhibiting-commands))))
|
|
130
|
|
131 ;; XEmacs addition:
|
|
132 (defun auto-show-make-region-visible (start end)
|
|
133 "Move point in such a way that the region (START, END) is visible.
|
|
134 This only does anything if auto-show-mode is enabled, and it doesn't
|
|
135 actually do any horizontal scrolling; rather, it just sets things up so
|
|
136 that the region will be visible when `auto-show-make-point-visible'
|
|
137 is next called (this happens after every command)."
|
|
138 (if (auto-show-should-take-action-p)
|
|
139 (let* ((col (current-column)) ;column on line point is at
|
|
140 (scroll (window-hscroll));how far window is scrolled
|
|
141 (w-width (- (window-width)
|
|
142 (if (> scroll 0)
|
|
143 2 1))) ;how wide window is on the screen
|
|
144 (right-col (+ scroll w-width))
|
|
145 (start-col (save-excursion (goto-char start) (current-column)))
|
|
146 (end-col (save-excursion (goto-char end) (current-column))))
|
|
147 (cond ((and (>= start-col scroll)
|
|
148 (<= end-col right-col))
|
|
149 ;; already completely visible
|
|
150 nil)
|
|
151 ((< start-col scroll)
|
|
152 (scroll-right (- scroll start-col)))
|
|
153 (t
|
|
154 (scroll-left (- end-col right-col)))))))
|
|
155
|
|
156 (defun auto-show-make-point-visible (&optional ignore-arg)
|
|
157 "Scroll horizontally to make point visible, if that is enabled.
|
|
158 This function only does something if `auto-show-mode' is non-nil
|
|
159 and longlines are being truncated in the selected window.
|
155
|
160 See also the command `auto-show-mode'."
|
0
|
161 (interactive)
|
2
|
162 ;; XEmacs change
|
0
|
163 (if (auto-show-should-take-action-p)
|
|
164 (let* ((col (current-column)) ;column on line point is at
|
|
165 (scroll (window-hscroll)) ;how far window is scrolled
|
|
166 (w-width (- (window-width)
|
|
167 (if (> scroll 0)
|
|
168 2 1))) ;how wide window is on the screen
|
|
169 (right-col (+ scroll w-width)))
|
|
170 (if (and (< col auto-show-show-left-margin-threshold)
|
|
171 (< col (window-width))
|
|
172 (> scroll 0))
|
|
173 (scroll-right scroll)
|
|
174 (if (< col scroll) ;to the left of the screen
|
|
175 (scroll-right (+ (- scroll col) auto-show-shift-amount))
|
|
176 (if (or (> col right-col) ;to the right of the screen
|
|
177 (and (= col right-col)
|
|
178 (not (eolp))))
|
|
179 (scroll-left (+ auto-show-shift-amount
|
167
|
180 (- col (+ scroll w-width))))))))))
|
0
|
181
|
|
182 ;; XEmacs change:
|
|
183 ;; #### instead of this, we kludgily call it from the C code, to make sure
|
|
184 ;; that it's done after any other things on post-command-hook (which might
|
|
185 ;; move point).
|
|
186 ;; Do auto-scrolling after commands.
|
|
187 ;;(add-hook 'post-command-hook 'auto-show-make-point-visible)
|
|
188
|
|
189 ;; If being dumped, turn it on right away.
|
155
|
190 (when (boundp 'load-gc)
|
|
191 (auto-show-mode 1))
|
0
|
192
|
|
193 ;; Do auto-scrolling in comint buffers after process output also.
|
|
194 ; XEmacs -- don't do this now, it messes up comint.
|
|
195 ;(add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t)
|
|
196
|
|
197 (provide 'auto-show)
|
|
198
|
|
199 ;; auto-show.el ends here
|