annotate lisp/modes/auto-show.el @ 0:376386a54a3c r19-14

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