Mercurial > emacs
annotate lisp/auto-show.el @ 23953:c8cdb4e487cb
(Fsingle_key_description): Handle (control ?x) etc.
(Fkey_description): Handle lists like vectors.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 29 Dec 1998 22:53:25 +0000 |
parents | 93652fd3234d |
children | 4bdc30f27628 |
rev | line source |
---|---|
13337 | 1 ;;; auto-show.el --- perform automatic horizontal scrolling as point moves |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
2 ;;; This file is in the public domain. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
3 |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
4 ;;; Keywords: scroll display minor-mode |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
5 ;;; Author: Pete Ware <ware@cis.ohio-state.edu> |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
6 ;;; Maintainer: FSF |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
7 |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
8 ;;; Commentary: |
10973 | 9 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
10 ;;; This file provides functions that |
10973 | 11 ;;; automatically scroll the window horizontally when the point moves |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
12 ;;; off the left or right side of the window. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
13 |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
14 ;;; Once this library is loaded, automatic horizontal scrolling |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
15 ;;; occurs whenever long lines are being truncated. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
16 ;;; To request truncation of long lines, set the variable |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
17 ;;; Setting the variable `truncate-lines' to non-nil. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
18 ;;; You can do this for all buffers as follows: |
10973 | 19 ;;; |
20 ;;; (set-default 'truncate-lines t) | |
21 | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
22 ;;; Here is how to do it for C mode only: |
10973 | 23 ;;; |
24 ;;; (set-default 'truncate-lines nil) ; this is the original value | |
25 ;;; (defun my-c-mode-hook () | |
26 ;;; "Run when C-mode starts up. Changes ..." | |
27 ;;; ... set various personal preferences ... | |
28 ;;; (setq truncate-lines t)) | |
29 ;;; (add-hook 'c-mode-hook 'my-c-mode-hook) | |
30 ;;; | |
31 ;;; | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
32 ;;; As a finer level of control, you can still have truncated lines but |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
33 ;;; without the automatic horizontal scrolling by setting the buffer |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
34 ;;; local variable `auto-show-mode' to nil. The default value is t. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
35 ;;; The command `auto-show-mode' toggles the value of the variable |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
36 ;;; `auto-show-mode'. |
10973 | 37 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
38 ;;; Code: |
10973 | 39 |
20451 | 40 (defgroup auto-show nil |
41 "Perform automatic horizontal scrolling as point moves." | |
42 :group 'editing) | |
43 | |
44 (defcustom auto-show-mode t | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
45 "*Non-nil enables automatic horizontal scrolling, when lines are truncated. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
46 The default value is t. To change the default, do this: |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
47 (set-default 'auto-show-mode nil) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
48 See also command `auto-show-mode'. |
16979
8134c62c03d0
(auto-show-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
49 This variable has no effect when lines are not being truncated. |
20451 | 50 This variable is automatically local in each buffer where it is set." |
51 :type 'boolean | |
52 :group 'auto-show) | |
10973 | 53 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
54 (make-variable-buffer-local 'auto-show-mode) |
10973 | 55 |
20451 | 56 (defcustom auto-show-shift-amount 8 |
57 "*Extra columns to scroll. for automatic horizontal scrolling." | |
58 :type 'integer | |
59 :group 'auto-show) | |
10973 | 60 |
20451 | 61 (defcustom auto-show-show-left-margin-threshold 50 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
62 "*Threshold column for automatic horizontal scrolling to the right. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
63 If point is before this column, we try to scroll to make the left margin |
20451 | 64 visible. Setting this to 0 disables this feature." |
65 :type 'integer | |
66 :group 'auto-show) | |
10973 | 67 |
68 (defun auto-show-truncationp () | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
69 "True if line truncation is enabled for the selected window." |
10973 | 70 (or truncate-lines |
71 (and truncate-partial-width-windows | |
72 (< (window-width) (frame-width))))) | |
73 | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
74 ;;;###autoload |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
75 (defun auto-show-mode (arg) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
76 "Turn automatic horizontal scroll mode on or off. |
16979
8134c62c03d0
(auto-show-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
77 With arg, turn auto scrolling on if arg is positive, off otherwise. |
8134c62c03d0
(auto-show-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
78 This mode is enabled or disabled for each buffer individually. |
8134c62c03d0
(auto-show-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
79 It takes effect only when `truncate-lines' is non-nil." |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
80 (interactive "P") |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
81 (setq auto-show-mode |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
82 (if (null arg) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
83 (not auto-show-mode) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
84 (> (prefix-numeric-value arg) 0)))) |
10973 | 85 |
86 (defun auto-show-make-point-visible (&optional ignore-arg) | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
87 "Scroll horizontally to make point visible, if that is enabled. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
88 This function only does something if `auto-show-mode' is non-nil |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
89 and longlines are being truncated in the selected window. |
16979
8134c62c03d0
(auto-show-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13337
diff
changeset
|
90 See also the command `auto-show-mode'." |
10973 | 91 (interactive) |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
92 (if (and auto-show-mode (auto-show-truncationp) |
10973 | 93 (equal (window-buffer) (current-buffer))) |
94 (let* ((col (current-column)) ;column on line point is at | |
95 (scroll (window-hscroll)) ;how far window is scrolled | |
96 (w-width (- (window-width) | |
97 (if (> scroll 0) | |
98 2 1))) ;how wide window is on the screen | |
99 (right-col (+ scroll w-width))) | |
100 (if (and (< col auto-show-show-left-margin-threshold) | |
101 (< col (window-width)) | |
102 (> scroll 0)) | |
103 (scroll-right scroll) | |
104 (if (< col scroll) ;to the left of the screen | |
105 (scroll-right (+ (- scroll col) auto-show-shift-amount)) | |
106 (if (or (> col right-col) ;to the right of the screen | |
107 (and (= col right-col) | |
108 (not (eolp)))) | |
109 (scroll-left (+ auto-show-shift-amount | |
110 (- col (+ scroll w-width)))) | |
111 ) | |
112 ) | |
113 ) | |
114 ) | |
115 ) | |
116 ) | |
117 | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
118 ;; Do auto-scrolling after commands. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
119 (add-hook 'post-command-hook 'auto-show-make-point-visible) |
10973 | 120 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
121 ;; Do auto-scrolling in comint buffers after process output also. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
122 (add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t) |
10973 | 123 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
124 (provide 'auto-show) |
10973 | 125 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
126 ;; auto-show.el ends here |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
127 |