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