annotate lisp/auto-show.el @ 25298:866b59632531

Move provide to end. (three-step-help): Customize.
author Dave Love <fx@gnu.org>
date Mon, 16 Aug 1999 23:06:06 +0000
parents 1a84afcdb8f9
children 222e261cc577
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 10974
diff changeset
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
24812
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
4 ;;; Keywords: scroll display convenience
10974
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
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;;;
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;;; (set-default 'truncate-lines t)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;;
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; (set-default 'truncate-lines nil) ; this is the original value
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; (defun my-c-mode-hook ()
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; "Run when C-mode starts up. Changes ..."
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; ... set various personal preferences ...
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; (setq truncate-lines t))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; (add-hook 'c-mode-hook 'my-c-mode-hook)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;;
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
10974
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
38 ;;; Code:
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
20451
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
40 (defgroup auto-show nil
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
41 "Perform automatic horizontal scrolling as point moves."
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
42 :group 'editing)
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
43
24812
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
44 ;;;###autoload
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
45 (defcustom auto-show-mode nil
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
46 "Non-nil means do automatic horizontal scrolling, when lines are truncated.
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
47
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
48 This variable is automatically local in each buffer where it is set.
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
49
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
50 Setting this variable directly does not take effect;
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
51 use either \\[customize] or the function `auto-show-mode'."
25180
1a84afcdb8f9 (auto-show-mode): Fix :set.
Dave Love <fx@gnu.org>
parents: 24901
diff changeset
52 :set (lambda (symbol value) (auto-show-mode (if value 1 0)))
24812
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
53 :require 'auto-show
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
54 :initialize 'custom-initialize-default
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
55 :link '(emacs-commentary-link "auto-show.el")
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
56 :version "20.4"
20451
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
57 :type 'boolean
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
58 :group 'auto-show)
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
10974
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
60 (make-variable-buffer-local 'auto-show-mode)
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
20451
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
62 (defcustom auto-show-shift-amount 8
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
63 "*Extra columns to scroll. for automatic horizontal scrolling."
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
64 :type 'integer
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
65 :group 'auto-show)
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
20451
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
67 (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
68 "*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
69 If point is before this column, we try to scroll to make the left margin
20451
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
70 visible. Setting this to 0 disables this feature."
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
71 :type 'integer
93652fd3234d Customized.
Andreas Schwab <schwab@suse.de>
parents: 16979
diff changeset
72 :group 'auto-show)
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (defun auto-show-truncationp ()
10974
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
75 "True if line truncation is enabled for the selected window."
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (or truncate-lines
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (and truncate-partial-width-windows
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (< (window-width) (frame-width)))))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
10974
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
80 ;;;###autoload
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
81 (defun auto-show-mode (arg)
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
82 "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
83 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
84 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
85 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
86 (interactive "P")
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
87 (setq auto-show-mode
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
88 (if (null arg)
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
89 (not auto-show-mode)
24812
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
90 (> (prefix-numeric-value arg) 0)))
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
91 (when auto-show-mode
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
92 ;; Do auto-scrolling after commands.
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
93 (add-hook 'post-command-hook 'auto-show-make-point-visible)
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
94 ;; Do auto-scrolling in comint buffers after process output also.
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
95 (add-hook 'comint-output-filter-functions
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
96 'auto-show-make-point-visible t)))
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (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
99 "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
100 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
101 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
102 See also the command `auto-show-mode'."
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (interactive)
10974
4ef3ef45089f Unconditionally add to comint-output-filter-functions.
Richard M. Stallman <rms@gnu.org>
parents: 10973
diff changeset
104 (if (and auto-show-mode (auto-show-truncationp)
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (equal (window-buffer) (current-buffer)))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (let* ((col (current-column)) ;column on line point is at
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (scroll (window-hscroll)) ;how far window is scrolled
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (w-width (- (window-width)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (if (> scroll 0)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 2 1))) ;how wide window is on the screen
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (right-col (+ scroll w-width)))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (if (and (< col auto-show-show-left-margin-threshold)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (< col (window-width))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (> scroll 0))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (scroll-right scroll)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (if (< col scroll) ;to the left of the screen
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (scroll-right (+ (- scroll col) auto-show-shift-amount))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (if (or (> col right-col) ;to the right of the screen
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (and (= col right-col)
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (not (eolp))))
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (scroll-left (+ auto-show-shift-amount
24812
4bdc30f27628 Don't change hooks on loading.
Karl Heuer <kwzh@gnu.org>
parents: 20451
diff changeset
122 (- col (+ scroll w-width))))))))))
10973
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
a937df996aa4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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