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