Mercurial > emacs
annotate lisp/auto-show.el @ 15647:f898a38206ab
(normal-top-level-add-to-load-path):
Use directory-file-name since load-path elements don't end in /.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Fri, 12 Jul 1996 00:08:09 +0000 |
parents | 84acc3adcd63 |
children | 8134c62c03d0 |
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 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
40 (defvar auto-show-mode t |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
41 "*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
|
42 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
|
43 (set-default 'auto-show-mode nil) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
44 See also command `auto-show-mode'. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
45 This variable has no effect when lines are not being truncated.") |
10973 | 46 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
47 (make-variable-buffer-local 'auto-show-mode) |
10973 | 48 |
49 (defvar auto-show-shift-amount 8 | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
50 "*Extra columns to scroll. for automatic horizontal scrolling.") |
10973 | 51 |
52 (defvar 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
|
53 "*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
|
54 If point is before this column, we try to scroll to make the left margin |
10973 | 55 visible. Setting this to 0 disables this feature.") |
56 | |
57 (defun auto-show-truncationp () | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
58 "True if line truncation is enabled for the selected window." |
10973 | 59 (or truncate-lines |
60 (and truncate-partial-width-windows | |
61 (< (window-width) (frame-width))))) | |
62 | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
63 ;;;###autoload |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
64 (defun auto-show-mode (arg) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
65 "Turn automatic horizontal scroll mode on or off. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
66 With arg, turn auto scrolling on if arg is positive, off otherwise." |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
67 (interactive "P") |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
68 (setq auto-show-mode |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
69 (if (null arg) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
70 (not auto-show-mode) |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
71 (> (prefix-numeric-value arg) 0)))) |
10973 | 72 |
73 (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
|
74 "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
|
75 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
|
76 and longlines are being truncated in the selected window. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
77 See also the command `auto-show-toggle'." |
10973 | 78 (interactive) |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
79 (if (and auto-show-mode (auto-show-truncationp) |
10973 | 80 (equal (window-buffer) (current-buffer))) |
81 (let* ((col (current-column)) ;column on line point is at | |
82 (scroll (window-hscroll)) ;how far window is scrolled | |
83 (w-width (- (window-width) | |
84 (if (> scroll 0) | |
85 2 1))) ;how wide window is on the screen | |
86 (right-col (+ scroll w-width))) | |
87 (if (and (< col auto-show-show-left-margin-threshold) | |
88 (< col (window-width)) | |
89 (> scroll 0)) | |
90 (scroll-right scroll) | |
91 (if (< col scroll) ;to the left of the screen | |
92 (scroll-right (+ (- scroll col) auto-show-shift-amount)) | |
93 (if (or (> col right-col) ;to the right of the screen | |
94 (and (= col right-col) | |
95 (not (eolp)))) | |
96 (scroll-left (+ auto-show-shift-amount | |
97 (- col (+ scroll w-width)))) | |
98 ) | |
99 ) | |
100 ) | |
101 ) | |
102 ) | |
103 ) | |
104 | |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
105 ;; Do auto-scrolling after commands. |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
106 (add-hook 'post-command-hook 'auto-show-make-point-visible) |
10973 | 107 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
108 ;; 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
|
109 (add-hook 'comint-output-filter-functions 'auto-show-make-point-visible t) |
10973 | 110 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
111 (provide 'auto-show) |
10973 | 112 |
10974
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
113 ;; auto-show.el ends here |
4ef3ef45089f
Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents:
10973
diff
changeset
|
114 |