annotate lisp/hscroll.el @ 22258:30576834668c

(loaddefs.el): Load it earlier, and GC before and after and a few more times later on.
author Richard M. Stallman <rms@gnu.org>
date Tue, 26 May 1998 20:56:22 +0000
parents 808ecc2eaa84
children 7d763e90da82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1 ;;; hscroll.el: Minor mode to automatically scroll truncated lines horizontally
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2 ;;; Copyright (C) 1992, 1993, 1995, 1996 Free Software Foundation, Inc.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
4 ;; Author: Wayne Mesard <wmesard@esd.sgi.com>
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5 ;; Keywords: display
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12 ;; any later version.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
24 ;;; Commentary:a
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
25 ;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26 ;; Automatically scroll horizontally when the point moves off the
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 ;; left or right edge of the window.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29 ;; - Type "M-x hscroll-mode" to enable it in the current buffer.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;; - Type "M-x hscroll-global-mode" to enable it in every buffer.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;; - "turn-on-hscroll" is useful in mode hooks as in:
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;; (add-hook 'text-mode-hook 'turn-on-hscroll)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;; - hscroll-margin controls how close the cursor can get to the edge
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; of the window.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; - hscroll-step-percent controls how far to jump once we decide to do so.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;; Most users won't want to mess with the other variables defined
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;; here. But they're all documented, and they all start with
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 ;; "hscroll-" if you're curious.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;; Oh, you should also know that if you set the hscroll-margin and
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43 ;; hscroll-step-percent large enough, you can get an interesting, but
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;; undesired ping-pong effect as the point bounces from one edge to
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45 ;; the other.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 ;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47 ;; wmesard@sgi.com
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49 ;;; Code:
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
51 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 ;;; PUBLIC VARIABLES
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55 (defvar hscroll-version "2.2")
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
57 (defgroup hscroll nil
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
58 "Minor mode to automatically scroll truncated lines horizontally."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
59 :group 'editing)
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
60
20765
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
61
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
62 (defcustom hscroll-global-mode nil
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
63 "Toggle horizontal scrolling.
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
64 You must modify via \\[customize] for this variable to have an effect."
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
65 :set (lambda (symbol value)
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
66 (hscroll-global-mode (if value 1 -1)))
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
67 :initialize 'custom-initialize-default
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
68 :group 'hscroll
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
69 :type 'boolean
21670
808ecc2eaa84 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20765
diff changeset
70 :require 'hscroll
808ecc2eaa84 *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20765
diff changeset
71 :version "20.3")
20765
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
72
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
73 (defcustom hscroll-margin 5
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 "*How many columns away from the edge of the window point is allowed to get
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
75 before HScroll will horizontally scroll the window."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
76 :group 'hscroll
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
77 :type 'integer)
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
79 (defcustom hscroll-snap-threshold 30
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 "*When point is this many columns (or less) from the left edge of the document,
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 don't do any horizontal scrolling. In other words, be biased towards the left
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 edge of the document.
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
83 Set this variable to zero to disable this bias."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
84 :group 'hscroll
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
85 :type 'integer)
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
87 (defcustom hscroll-step-percent 25
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 "*How far away to place the point from the window's edge when scrolling.
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
89 Expressed as a percentage of the window's width."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
90 :group 'hscroll
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
91 :type 'integer)
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
93 (defcustom hscroll-mode-name " Hscr"
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 "*Horizontal scrolling mode line indicator.
19420
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
95 Set this to nil to conserve valuable mode line space."
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
96 :group 'hscroll
681823a203b6 Customized.
Richard M. Stallman <rms@gnu.org>
parents: 16583
diff changeset
97 :type 'string)
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
98
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
99 (or (assq 'hscroll-mode minor-mode-alist)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
100 (setq minor-mode-alist
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
101 (cons '(hscroll-mode hscroll-mode-name) minor-mode-alist)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
102
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105 ;;; PRIVATE VARIABLES
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 (defvar hscroll-mode nil
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 "Non-nil if HScroll mode is enabled.")
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 (make-variable-buffer-local 'hscroll-mode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 (defvar hscroll-old-truncate-local nil)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 (defvar hscroll-old-truncate-was-global nil)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 (make-variable-buffer-local 'hscroll-old-truncate)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 (make-variable-buffer-local 'hscroll-old-truncate-was-global)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 (defvar hscroll-old-truncate-default nil)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 ;;; PUBLIC COMMANDS
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 ;;;###autoload
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125 (defun turn-on-hscroll ()
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 "Unconditionally turn on Hscroll mode in the current buffer."
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127 (hscroll-mode 1))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129 ;;;###autoload
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (defun hscroll-mode (&optional arg)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 "Toggle HScroll mode in the current buffer.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 With ARG, turn HScroll mode on if ARG is positive, off otherwise.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 In HScroll mode, truncated lines will automatically scroll left or
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 right when point gets near either edge of the window.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 See also \\[hscroll-global-mode]."
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (interactive "P")
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 (make-local-hook 'post-command-hook)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 (let ((newmode (if (null arg)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 (not hscroll-mode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 (> (prefix-numeric-value arg) 0))))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 (if newmode
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 ;; turn it on
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 (if (not hscroll-mode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 ;; it was off
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (let ((localp (local-variable-p 'truncate-lines)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 (if localp
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 (setq hscroll-old-truncate-local truncate-lines))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 (setq hscroll-old-truncate-was-global (not localp))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 (setq truncate-lines t)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 (add-hook 'post-command-hook
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 (function hscroll-window-maybe) nil t)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 ;; turn it off
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 (if hscroll-mode
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 ;; it was on
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 (progn
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 (if hscroll-old-truncate-was-global
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 (kill-local-variable 'truncate-lines)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 (setq truncate-lines hscroll-old-truncate-local))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (if (not truncate-lines)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (set-window-hscroll (selected-window) 0))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 (remove-hook 'post-command-hook
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 (function hscroll-window-maybe) t)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 )
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 (setq hscroll-mode newmode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (force-mode-line-update nil)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 ;;;###autoload
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (defun hscroll-global-mode (&optional arg)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 "Toggle HScroll mode in all buffers.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 With ARG, turn HScroll mode on if ARG is positive, off otherwise.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 If a buffer ever has HScroll mode set locally (via \\[hscroll-mode]),
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 it will forever use the local value (i.e., \\[hscroll-global-mode]
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 will have no effect on it).
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 See also \\[hscroll-mode]."
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 (interactive "P")
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 (let* ((oldmode (default-value 'hscroll-mode))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 (newmode (if (null arg)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 (not oldmode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 (> (prefix-numeric-value arg) 0))))
20765
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
186 (setq hscroll-global-mode newmode)
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 (if newmode
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 ;; turn it on
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189 (if (not hscroll-mode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 ;; it was off
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 (progn
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (setq hscroll-old-truncate-default (default-value truncate-lines))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (setq hscroll-old-truncate-was-global t)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (setq-default truncate-lines t)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (add-hook 'post-command-hook (function hscroll-window-maybe))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 ;; turn it off
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 (if hscroll-mode
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 ;; it was on
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 (progn
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 (setq-default truncate-lines hscroll-old-truncate-default)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (remove-hook 'post-command-hook (function hscroll-window-maybe))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 )
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 (setq-default hscroll-mode newmode)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 (force-mode-line-update t)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 (defun hscroll-window-maybe ()
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211 "Scroll horizontally if point is off or nearly off the edge of the window.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 This is called automatically when in HScroll mode, but it can be explicitly
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 invoked as well (i.e., it can be bound to a key)."
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
214 (interactive)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
215 ;; Only consider scrolling if truncate-lines is true,
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 ;; the window is already scrolled or partial-widths is true and this is
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
217 ;; a partial width window. See display_text_line() in xdisp.c.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
218 (if (and hscroll-mode
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
219 (or truncate-lines
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
220 (not (zerop (window-hscroll)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
221 (and truncate-partial-width-windows
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222 (< (window-width) (frame-width)))))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 (let ((linelen (save-excursion (end-of-line) (current-column)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 (rightmost-char (+ (window-width) (window-hscroll)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 )
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226 (if (< (current-column) hscroll-snap-threshold)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 (set-window-hscroll
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228 (selected-window)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229 (- (window-hscroll)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 (if (>= (current-column)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231 (- rightmost-char hscroll-margin
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 ;; Off-by-one if the left edge is scrolled
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233 (if (not (zerop (window-hscroll))) 1 0)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 ;; Off by one if the right edge is scrolled
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235 (if (> linelen rightmost-char) 1 0)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 ))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
237 ;; Scroll to the left a proportion of the window's width.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
238 (set-window-hscroll
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239 (selected-window)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 (- (+ (current-column)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 (/ (* (window-width) hscroll-step-percent) 100))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242 (window-width)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243 (if (< (current-column) (+ (window-hscroll) hscroll-margin))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 ;; Scroll to the right a proportion of the window's width.
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 (set-window-hscroll
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 (selected-window)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 (- (current-column) (/ (* (window-width) hscroll-step-percent) 100)))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 )))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 )))
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
250
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
251 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
252 ;;; It's not a bug, it's a *feature*
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
253 ;;;
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254
20765
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
255 (if hscroll-global-mode
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
256 (hscroll-global-mode 1))
2bdc3877262b (hscroll-global-mode): New customize variable to automatically load the
Stephen Eglen <stephen@gnu.org>
parents: 19420
diff changeset
257
16583
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 (provide 'hscroll)
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259
483fc45a80b6 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 ;;; hscroll.el ends here