Mercurial > emacs
annotate lisp/longlines.el @ 79656:b3ebc6fbb476
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 29 Dec 2007 19:26:14 +0000 |
parents | 3516a7d8862b |
children | 73661ddc7ac7 |
rev | line source |
---|---|
61110 | 1 ;;; longlines.el --- automatically wrap long lines |
2 | |
75347 | 3 ;; Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
61110 | 4 |
5 ;; Authors: Kai Grossjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> | |
6 ;; Alex Schroeder <alex@gnu.org> | |
7 ;; Chong Yidong <cyd@stupidchicken.com> | |
8 ;; Maintainer: Chong Yidong <cyd@stupidchicken.com> | |
66465
9a896c723ab2
* longlines.el (longlines-mode): Bind after-change-functions to
Chong Yidong <cyd@stupidchicken.com>
parents:
66453
diff
changeset
|
9 ;; Keywords: convenience, wp |
61110 | 10 |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
78088
diff
changeset
|
15 ;; the Free Software Foundation; either version 3, or (at your option) |
61110 | 16 ;; any later version. |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
61110 | 27 |
28 ;;; Commentary: | |
29 | |
30 ;; Some text editors save text files with long lines, and they | |
31 ;; automatically break these lines at whitespace, without actually | |
32 ;; inserting any newline characters. When doing `M-q' in Emacs, you | |
33 ;; are inserting newline characters. Longlines mode provides a file | |
34 ;; format which wraps the long lines when reading a file and unwraps | |
35 ;; the lines when saving the file. It can also wrap and unwrap | |
36 ;; automatically as editing takes place. | |
37 | |
38 ;; Special thanks to Rod Smith for many useful bug reports. | |
39 | |
40 ;;; Code: | |
41 | |
42 (defgroup longlines nil | |
43 "Automatic wrapping of long lines when loading files." | |
44 :group 'fill) | |
45 | |
46 (defcustom longlines-auto-wrap t | |
72225
1d3db748db52
(longlines-show-region): Make it work on read-only buffers as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71873
diff
changeset
|
47 "Non-nil means long lines are automatically wrapped after each command. |
61110 | 48 Otherwise, you can perform filling using `fill-paragraph' or |
49 `auto-fill-mode'. In any case, the soft newlines will be removed | |
50 when the file is saved to disk." | |
51 :group 'longlines | |
52 :type 'boolean) | |
53 | |
54 (defcustom longlines-wrap-follows-window-size nil | |
72225
1d3db748db52
(longlines-show-region): Make it work on read-only buffers as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71873
diff
changeset
|
55 "Non-nil means wrapping and filling happen at the edge of the window. |
61110 | 56 Otherwise, `fill-column' is used, regardless of the window size. This |
57 does not work well when the buffer is displayed in multiple windows | |
79120
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
58 with differing widths. |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
59 |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
60 If the value is an integer, that specifies the distance from the |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
61 right edge of the window at which wrapping occurs. For any other |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
62 non-nil value, wrapping occurs 2 characters from the right edge." |
61110 | 63 :group 'longlines |
64 :type 'boolean) | |
65 | |
66 (defcustom longlines-show-hard-newlines nil | |
72225
1d3db748db52
(longlines-show-region): Make it work on read-only buffers as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71873
diff
changeset
|
67 "Non-nil means each hard newline is marked on the screen. |
63557
6a1d35d4ea03
(longlines-mode, longlines-show-hard-newlines): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
63198
diff
changeset
|
68 \(The variable `longlines-show-effect' controls what they look like.) |
61110 | 69 You can also enable the display temporarily, using the command |
75226
7257e69d3378
(longlines-show-hard-newlines): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
74234
diff
changeset
|
70 `longlines-show-hard-newlines'." |
61110 | 71 :group 'longlines |
72 :type 'boolean) | |
73 | |
74 (defcustom longlines-show-effect (propertize "|\n" 'face 'escape-glyph) | |
72225
1d3db748db52
(longlines-show-region): Make it work on read-only buffers as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71873
diff
changeset
|
75 "A string to display when showing hard newlines. |
61110 | 76 This is used when `longlines-show-hard-newlines' is on." |
77 :group 'longlines | |
78 :type 'string) | |
79 | |
80 ;; Internal variables | |
81 | |
82 (defvar longlines-wrap-beg nil) | |
83 (defvar longlines-wrap-end nil) | |
84 (defvar longlines-wrap-point nil) | |
85 (defvar longlines-showing nil) | |
78447
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
86 (defvar longlines-decoded nil) |
61110 | 87 |
88 (make-variable-buffer-local 'longlines-wrap-beg) | |
89 (make-variable-buffer-local 'longlines-wrap-end) | |
90 (make-variable-buffer-local 'longlines-wrap-point) | |
91 (make-variable-buffer-local 'longlines-showing) | |
78447
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
92 (make-variable-buffer-local 'longlines-decoded) |
61110 | 93 |
94 ;; Mode | |
95 | |
96 ;;;###autoload | |
97 (define-minor-mode longlines-mode | |
98 "Toggle Long Lines mode. | |
99 In Long Lines mode, long lines are wrapped if they extend beyond | |
100 `fill-column'. The soft newlines used for line wrapping will not | |
101 show up when the text is yanked or saved to disk. | |
102 | |
63557
6a1d35d4ea03
(longlines-mode, longlines-show-hard-newlines): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
63198
diff
changeset
|
103 If the variable `longlines-auto-wrap' is non-nil, lines are automatically |
61110 | 104 wrapped whenever the buffer is changed. You can always call |
105 `fill-paragraph' to fill individual paragraphs. | |
106 | |
63557
6a1d35d4ea03
(longlines-mode, longlines-show-hard-newlines): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
63198
diff
changeset
|
107 If the variable `longlines-show-hard-newlines' is non-nil, hard newlines |
6a1d35d4ea03
(longlines-mode, longlines-show-hard-newlines): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
63198
diff
changeset
|
108 are indicated with a symbol." |
61289
78b96a3ee117
(longlines-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents:
61125
diff
changeset
|
109 :group 'longlines :lighter " ll" |
61110 | 110 (if longlines-mode |
111 ;; Turn on longlines mode | |
112 (progn | |
113 (use-hard-newlines 1 'never) | |
114 (set (make-local-variable 'require-final-newline) nil) | |
115 (add-to-list 'buffer-file-format 'longlines) | |
116 (add-hook 'change-major-mode-hook 'longlines-mode-off nil t) | |
67021
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
117 (add-hook 'before-revert-hook 'longlines-before-revert-hook nil t) |
61110 | 118 (make-local-variable 'buffer-substring-filters) |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
119 (make-local-variable 'longlines-auto-wrap) |
66088
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
120 (set (make-local-variable 'isearch-search-fun-function) |
67701 | 121 'longlines-search-function) |
61110 | 122 (add-to-list 'buffer-substring-filters 'longlines-encode-string) |
123 (when longlines-wrap-follows-window-size | |
79120
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
124 (let ((dw (if (and (integerp longlines-wrap-follows-window-size) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
125 (>= longlines-wrap-follows-window-size 0) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
126 (< longlines-wrap-follows-window-size |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
127 (window-width))) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
128 longlines-wrap-follows-window-size |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
129 2))) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
130 (set (make-local-variable 'fill-column) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
131 (- (window-width) dw))) |
61110 | 132 (add-hook 'window-configuration-change-hook |
133 'longlines-window-change-function nil t)) | |
134 (let ((buffer-undo-list t) | |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
135 (inhibit-read-only t) |
66465
9a896c723ab2
* longlines.el (longlines-mode): Bind after-change-functions to
Chong Yidong <cyd@stupidchicken.com>
parents:
66453
diff
changeset
|
136 (after-change-functions nil) |
61110 | 137 (mod (buffer-modified-p))) |
138 ;; Turning off undo is OK since (spaces + newlines) is | |
139 ;; conserved, except for a corner case in | |
140 ;; longlines-wrap-lines that we'll never encounter from here | |
66453
ce840b1d13ad
* longlines.el (longlines-mode): Remove narrowing before
Chong Yidong <cyd@stupidchicken.com>
parents:
66132
diff
changeset
|
141 (save-restriction |
ce840b1d13ad
* longlines.el (longlines-mode): Remove narrowing before
Chong Yidong <cyd@stupidchicken.com>
parents:
66132
diff
changeset
|
142 (widen) |
78447
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
143 (unless longlines-decoded |
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
144 (longlines-decode-buffer) |
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
145 (setq longlines-decoded t)) |
67673
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
146 (longlines-wrap-region (point-min) (point-max))) |
61110 | 147 (set-buffer-modified-p mod)) |
148 (when (and longlines-show-hard-newlines | |
149 (not longlines-showing)) | |
150 (longlines-show-hard-newlines)) | |
66995
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
151 |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
152 ;; Hacks to make longlines play nice with various modes. |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
153 (cond ((eq major-mode 'mail-mode) |
67213
818361523ce8
* longlines.el (longlines-mode): Add mail-setup-hook.
Chong Yidong <cyd@stupidchicken.com>
parents:
67120
diff
changeset
|
154 (add-hook 'mail-setup-hook 'longlines-decode-buffer nil t) |
66995
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
155 (or mail-citation-hook |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
156 (add-hook 'mail-citation-hook 'mail-indent-citation nil t)) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
157 (add-hook 'mail-citation-hook 'longlines-decode-region nil t)) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
158 ((eq major-mode 'message-mode) |
67031
9dbc51935e01
(longlines-mode): Add a message-setup-hook.
Chong Yidong <cyd@stupidchicken.com>
parents:
67024
diff
changeset
|
159 (add-hook 'message-setup-hook 'longlines-decode-buffer nil t) |
66995
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
160 (make-local-variable 'message-indent-citation-function) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
161 (if (not (listp message-indent-citation-function)) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
162 (setq message-indent-citation-function |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
163 (list message-indent-citation-function))) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
164 (add-to-list 'message-indent-citation-function |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
165 'longlines-decode-region t))) |
66996
cf7bf8dadf78
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
66995
diff
changeset
|
166 |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
167 (add-hook 'after-change-functions 'longlines-after-change-function nil t) |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
168 (add-hook 'post-command-hook 'longlines-post-command-function nil t) |
66996
cf7bf8dadf78
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
66995
diff
changeset
|
169 (when longlines-auto-wrap |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
170 (auto-fill-mode 0))) |
61110 | 171 ;; Turn off longlines mode |
172 (setq buffer-file-format (delete 'longlines buffer-file-format)) | |
173 (if longlines-showing | |
174 (longlines-unshow-hard-newlines)) | |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
175 (let ((buffer-undo-list t) |
66465
9a896c723ab2
* longlines.el (longlines-mode): Bind after-change-functions to
Chong Yidong <cyd@stupidchicken.com>
parents:
66453
diff
changeset
|
176 (after-change-functions nil) |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
177 (inhibit-read-only t)) |
78447
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
178 (if longlines-decoded |
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
179 (save-restriction |
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
180 (widen) |
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
181 (longlines-encode-region (point-min) (point-max)) |
65140a5dc349
(longlines-decoded): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents:
78236
diff
changeset
|
182 (setq longlines-decoded nil)))) |
61110 | 183 (remove-hook 'change-major-mode-hook 'longlines-mode-off t) |
184 (remove-hook 'after-change-functions 'longlines-after-change-function t) | |
185 (remove-hook 'post-command-hook 'longlines-post-command-function t) | |
67021
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
186 (remove-hook 'before-revert-hook 'longlines-before-revert-hook t) |
61110 | 187 (remove-hook 'window-configuration-change-hook |
188 'longlines-window-change-function t) | |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
189 (when longlines-wrap-follows-window-size |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
190 (kill-local-variable 'fill-column)) |
66088
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
191 (kill-local-variable 'isearch-search-fun-function) |
65312
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
192 (kill-local-variable 'require-final-newline) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
193 (kill-local-variable 'buffer-substring-filters) |
915d671fef52
*** empty log message ***
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
194 (kill-local-variable 'use-hard-newlines))) |
61110 | 195 |
196 (defun longlines-mode-off () | |
197 "Turn off longlines mode. | |
198 This function exists to be called by `change-major-mode-hook' when the | |
199 major mode changes." | |
200 (longlines-mode 0)) | |
201 | |
202 ;; Showing the effect of hard newlines in the buffer | |
203 | |
204 (defun longlines-show-hard-newlines (&optional arg) | |
205 "Make hard newlines visible by adding a face. | |
206 With optional argument ARG, make the hard newlines invisible again." | |
207 (interactive "P") | |
208 (let ((buffer-undo-list t) | |
209 (mod (buffer-modified-p))) | |
210 (if arg | |
211 (longlines-unshow-hard-newlines) | |
212 (setq longlines-showing t) | |
213 (longlines-show-region (point-min) (point-max))) | |
214 (set-buffer-modified-p mod))) | |
215 | |
216 (defun longlines-show-region (beg end) | |
217 "Make hard newlines between BEG and END visible." | |
218 (let* ((pmin (min beg end)) | |
219 (pmax (max beg end)) | |
72225
1d3db748db52
(longlines-show-region): Make it work on read-only buffers as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71873
diff
changeset
|
220 (pos (text-property-not-all pmin pmax 'hard nil)) |
1d3db748db52
(longlines-show-region): Make it work on read-only buffers as well.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
71873
diff
changeset
|
221 (inhibit-read-only t)) |
61110 | 222 (while pos |
223 (put-text-property pos (1+ pos) 'display | |
224 (copy-sequence longlines-show-effect)) | |
64216
6c19076eecb0
(longlines-show-region, longlines-unshow-hard-newlines):
Richard M. Stallman <rms@gnu.org>
parents:
64091
diff
changeset
|
225 (setq pos (text-property-not-all (1+ pos) pmax 'hard nil))))) |
61110 | 226 |
227 (defun longlines-unshow-hard-newlines () | |
228 "Make hard newlines invisible again." | |
229 (interactive) | |
230 (setq longlines-showing nil) | |
64216
6c19076eecb0
(longlines-show-region, longlines-unshow-hard-newlines):
Richard M. Stallman <rms@gnu.org>
parents:
64091
diff
changeset
|
231 (let ((pos (text-property-not-all (point-min) (point-max) 'hard nil))) |
61110 | 232 (while pos |
233 (remove-text-properties pos (1+ pos) '(display)) | |
64216
6c19076eecb0
(longlines-show-region, longlines-unshow-hard-newlines):
Richard M. Stallman <rms@gnu.org>
parents:
64091
diff
changeset
|
234 (setq pos (text-property-not-all (1+ pos) (point-max) 'hard nil))))) |
61110 | 235 |
236 ;; Wrapping the paragraphs. | |
237 | |
238 (defun longlines-wrap-region (beg end) | |
239 "Wrap each successive line, starting with the line before BEG. | |
240 Stop when we reach lines after END that don't need wrapping, or the | |
241 end of the buffer." | |
78088
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
242 (let ((mod (buffer-modified-p))) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
243 (setq longlines-wrap-point (point)) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
244 (goto-char beg) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
245 (forward-line -1) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
246 ;; Two successful longlines-wrap-line's in a row mean successive |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
247 ;; lines don't need wrapping. |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
248 (while (null (and (longlines-wrap-line) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
249 (or (eobp) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
250 (and (>= (point) end) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
251 (longlines-wrap-line)))))) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
252 (goto-char longlines-wrap-point) |
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
253 (set-buffer-modified-p mod))) |
61110 | 254 |
255 (defun longlines-wrap-line () | |
256 "If the current line needs to be wrapped, wrap it and return nil. | |
257 If wrapping is performed, point remains on the line. If the line does | |
258 not need to be wrapped, move point to the next line and return t." | |
259 (if (longlines-set-breakpoint) | |
67033
1a383aa3be8a
longlines.el (longlines-wrap-line): Preserve marker positions.
Chong Yidong <cyd@stupidchicken.com>
parents:
67031
diff
changeset
|
260 (progn (insert-before-markers ?\n) |
1a383aa3be8a
longlines.el (longlines-wrap-line): Preserve marker positions.
Chong Yidong <cyd@stupidchicken.com>
parents:
67031
diff
changeset
|
261 (backward-char 1) |
1a383aa3be8a
longlines.el (longlines-wrap-line): Preserve marker positions.
Chong Yidong <cyd@stupidchicken.com>
parents:
67031
diff
changeset
|
262 (delete-char -1) |
1a383aa3be8a
longlines.el (longlines-wrap-line): Preserve marker positions.
Chong Yidong <cyd@stupidchicken.com>
parents:
67031
diff
changeset
|
263 (forward-char 1) |
61110 | 264 nil) |
265 (if (longlines-merge-lines-p) | |
266 (progn (end-of-line) | |
267 ;; After certain commands (e.g. kill-line), there may be two | |
268 ;; successive soft newlines in the buffer. In this case, we | |
269 ;; replace these two newlines by a single space. Unfortunately, | |
270 ;; this breaks the conservation of (spaces + newlines), so we | |
271 ;; have to fiddle with longlines-wrap-point. | |
67120
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
272 (if (or (prog1 (bolp) (forward-char 1)) (eolp)) |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
273 (progn |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
274 (delete-char -1) |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
275 (if (> longlines-wrap-point (point)) |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
276 (setq longlines-wrap-point |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
277 (1- longlines-wrap-point)))) |
74234
d966c458c782
(longlines-wrap-line): "?\ " -> "?\s".
Juanma Barranquero <lekktu@gmail.com>
parents:
73330
diff
changeset
|
278 (insert-before-markers-and-inherit ?\s) |
67120
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
279 (backward-char 1) |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
280 (delete-char -1) |
d3b833785ae6
(longlines-wrap-line): Reorder wrapping to "insert
David Kastrup <dak@gnu.org>
parents:
67033
diff
changeset
|
281 (forward-char 1)) |
61110 | 282 nil) |
283 (forward-line 1) | |
284 t))) | |
285 | |
286 (defun longlines-set-breakpoint () | |
287 "Place point where we should break the current line, and return t. | |
288 If the line should not be broken, return nil; point remains on the | |
289 line." | |
290 (move-to-column fill-column) | |
291 (if (and (re-search-forward "[^ ]" (line-end-position) 1) | |
292 (> (current-column) fill-column)) | |
293 ;; This line is too long. Can we break it? | |
294 (or (longlines-find-break-backward) | |
295 (progn (move-to-column fill-column) | |
296 (longlines-find-break-forward))))) | |
297 | |
298 (defun longlines-find-break-backward () | |
299 "Move point backward to the first available breakpoint and return t. | |
300 If no breakpoint is found, return nil." | |
301 (and (search-backward " " (line-beginning-position) 1) | |
302 (save-excursion | |
303 (skip-chars-backward " " (line-beginning-position)) | |
304 (null (bolp))) | |
305 (progn (forward-char 1) | |
306 (if (and fill-nobreak-predicate | |
307 (run-hook-with-args-until-success | |
308 'fill-nobreak-predicate)) | |
309 (progn (skip-chars-backward " " (line-beginning-position)) | |
310 (longlines-find-break-backward)) | |
311 t)))) | |
312 | |
313 (defun longlines-find-break-forward () | |
314 "Move point forward to the first available breakpoint and return t. | |
315 If no break point is found, return nil." | |
316 (and (search-forward " " (line-end-position) 1) | |
317 (progn (skip-chars-forward " " (line-end-position)) | |
318 (null (eolp))) | |
319 (if (and fill-nobreak-predicate | |
320 (run-hook-with-args-until-success | |
321 'fill-nobreak-predicate)) | |
322 (longlines-find-break-forward) | |
323 t))) | |
324 | |
325 (defun longlines-merge-lines-p () | |
326 "Return t if part of the next line can fit onto the current line. | |
327 Otherwise, return nil. Text cannot be moved across hard newlines." | |
328 (save-excursion | |
329 (end-of-line) | |
330 (and (null (eobp)) | |
331 (null (get-text-property (point) 'hard)) | |
332 (let ((space (- fill-column (current-column)))) | |
333 (forward-line 1) | |
334 (if (eq (char-after) ? ) | |
335 t ; We can always merge some spaces | |
336 (<= (if (search-forward " " (line-end-position) 1) | |
337 (current-column) | |
338 (1+ (current-column))) | |
339 space)))))) | |
340 | |
66995
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
341 (defun longlines-decode-region (&optional beg end) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
342 "Turn all newlines between BEG and END into hard newlines. |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
343 If BEG and END are nil, the point and mark are used." |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
344 (if (null beg) (setq beg (point))) |
e10f2e7919f0
Add hacks for citation in mail-mode and message-mode.
Chong Yidong <cyd@stupidchicken.com>
parents:
66465
diff
changeset
|
345 (if (null end) (setq end (mark t))) |
61110 | 346 (save-excursion |
67673
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
347 (let ((reg-max (max beg end))) |
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
348 (goto-char (min beg end)) |
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
349 (while (search-forward "\n" reg-max t) |
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
350 (set-hard-newline-properties |
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
351 (match-beginning 0) (match-end 0)))))) |
61110 | 352 |
67031
9dbc51935e01
(longlines-mode): Add a message-setup-hook.
Chong Yidong <cyd@stupidchicken.com>
parents:
67024
diff
changeset
|
353 (defun longlines-decode-buffer () |
9dbc51935e01
(longlines-mode): Add a message-setup-hook.
Chong Yidong <cyd@stupidchicken.com>
parents:
67024
diff
changeset
|
354 "Turn all newlines in the buffer into hard newlines." |
9dbc51935e01
(longlines-mode): Add a message-setup-hook.
Chong Yidong <cyd@stupidchicken.com>
parents:
67024
diff
changeset
|
355 (longlines-decode-region (point-min) (point-max))) |
9dbc51935e01
(longlines-mode): Add a message-setup-hook.
Chong Yidong <cyd@stupidchicken.com>
parents:
67024
diff
changeset
|
356 |
61110 | 357 (defun longlines-encode-region (beg end &optional buffer) |
358 "Replace each soft newline between BEG and END with exactly one space. | |
359 Hard newlines are left intact. The optional argument BUFFER exists for | |
360 compatibility with `format-alist', and is ignored." | |
361 (save-excursion | |
67673
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
362 (let ((reg-max (max beg end)) |
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
363 (mod (buffer-modified-p))) |
61110 | 364 (goto-char (min beg end)) |
67673
947510e65020
* longlines.el (longlines-mode): Wrap while widened.
Chong Yidong <cyd@stupidchicken.com>
parents:
67213
diff
changeset
|
365 (while (search-forward "\n" reg-max t) |
61110 | 366 (unless (get-text-property (match-beginning 0) 'hard) |
367 (replace-match " "))) | |
368 (set-buffer-modified-p mod) | |
369 end))) | |
370 | |
371 (defun longlines-encode-string (string) | |
372 "Return a copy of STRING with each soft newline replaced by a space. | |
373 Hard newlines are left intact." | |
374 (let* ((str (copy-sequence string)) | |
375 (pos (string-match "\n" str))) | |
376 (while pos | |
377 (if (null (get-text-property pos 'hard str)) | |
378 (aset str pos ? )) | |
379 (setq pos (string-match "\n" str (1+ pos)))) | |
380 str)) | |
381 | |
382 ;; Auto wrap | |
383 | |
384 (defun longlines-auto-wrap (&optional arg) | |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
385 "Toggle automatic line wrapping. |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
386 With optional argument ARG, turn on line wrapping if and only if ARG is positive. |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
387 If automatic line wrapping is turned on, wrap the entire buffer." |
61110 | 388 (interactive "P") |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
389 (setq arg (if arg |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
390 (> (prefix-numeric-value arg) 0) |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
391 (not longlines-auto-wrap))) |
61110 | 392 (if arg |
78088
4545583b711c
(longlines-wrap-region): Avoid marking buffer as modified.
Chong Yidong <cyd@stupidchicken.com>
parents:
77871
diff
changeset
|
393 (progn |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
394 (setq longlines-auto-wrap t) |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
395 (longlines-wrap-region (point-min) (point-max)) |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
396 (message "Auto wrap enabled.")) |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
397 (setq longlines-auto-wrap nil) |
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
398 (message "Auto wrap disabled."))) |
61110 | 399 |
400 (defun longlines-after-change-function (beg end len) | |
401 "Update `longlines-wrap-beg' and `longlines-wrap-end'. | |
402 This is called by `after-change-functions' to keep track of the region | |
403 that has changed." | |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
404 (when (and longlines-auto-wrap (not undo-in-progress)) |
61110 | 405 (setq longlines-wrap-beg |
406 (if longlines-wrap-beg (min longlines-wrap-beg beg) beg)) | |
407 (setq longlines-wrap-end | |
408 (if longlines-wrap-end (max longlines-wrap-end end) end)))) | |
409 | |
410 (defun longlines-post-command-function () | |
411 "Perform line wrapping on the parts of the buffer that have changed. | |
412 This is called by `post-command-hook' after each command." | |
77871
2b390b4a6ba8
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
413 (when (and longlines-auto-wrap longlines-wrap-beg) |
71873 | 414 (if (or (eq this-command 'yank) |
415 (eq this-command 'yank-pop)) | |
416 (longlines-decode-region (point) (mark t))) | |
417 (if longlines-showing | |
418 (longlines-show-region longlines-wrap-beg longlines-wrap-end)) | |
61110 | 419 (unless (or (eq this-command 'fill-paragraph) |
420 (eq this-command 'fill-region)) | |
421 (longlines-wrap-region longlines-wrap-beg longlines-wrap-end)) | |
422 (setq longlines-wrap-beg nil) | |
423 (setq longlines-wrap-end nil))) | |
424 | |
425 (defun longlines-window-change-function () | |
426 "Re-wrap the buffer if the window width has changed. | |
73330
400487787181
* dnd.el (dnd-handle-one-url): Fix typo in doc-string.
Jan Djärv <jan.h.d@swipnet.se>
parents:
72225
diff
changeset
|
427 This is called by `window-configuration-change-hook'." |
79120
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
428 (let ((dw (if (and (integerp longlines-wrap-follows-window-size) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
429 (>= longlines-wrap-follows-window-size 0) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
430 (< longlines-wrap-follows-window-size (window-width))) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
431 longlines-wrap-follows-window-size |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
432 2))) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
433 (when (/= fill-column (- (window-width) dw)) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
434 (setq fill-column (- (window-width) dw)) |
3516a7d8862b
(longlines-wrap-follows-window-size): Integer value
Chong Yidong <cyd@stupidchicken.com>
parents:
78447
diff
changeset
|
435 (longlines-wrap-region (point-min) (point-max))))) |
61110 | 436 |
66088
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
437 ;; Isearch |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
438 |
67701 | 439 (defun longlines-search-function () |
66088
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
440 (cond |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
441 (isearch-word |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
442 (if isearch-forward 'word-search-forward 'word-search-backward)) |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
443 (isearch-regexp |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
444 (if isearch-forward 're-search-forward 're-search-backward)) |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
445 (t |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
446 (if isearch-forward |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
447 'longlines-search-forward |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
448 'longlines-search-backward)))) |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
449 |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
450 (defun longlines-search-forward (string &optional bound noerror count) |
66132
3fe20f1edf7b
* longlines.el (longlines-search-forward)
Chong Yidong <cyd@stupidchicken.com>
parents:
66088
diff
changeset
|
451 (let ((search-spaces-regexp "[ \n]+")) |
66088
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
452 (re-search-forward (regexp-quote string) bound noerror count))) |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
453 |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
454 (defun longlines-search-backward (string &optional bound noerror count) |
66132
3fe20f1edf7b
* longlines.el (longlines-search-forward)
Chong Yidong <cyd@stupidchicken.com>
parents:
66088
diff
changeset
|
455 (let ((search-spaces-regexp "[ \n]+")) |
66088
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
456 (re-search-backward (regexp-quote string) bound noerror count))) |
b63142efae15
* longlines.el (longlinges-search-function)
Chong Yidong <cyd@stupidchicken.com>
parents:
65312
diff
changeset
|
457 |
61110 | 458 ;; Loading and saving |
459 | |
67021
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
460 (defun longlines-before-revert-hook () |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
461 (add-hook 'after-revert-hook 'longlines-after-revert-hook nil t) |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
462 (longlines-mode 0)) |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
463 |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
464 (defun longlines-after-revert-hook () |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
465 (remove-hook 'after-revert-hook 'longlines-after-revert-hook t) |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
466 (longlines-mode 1)) |
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
467 |
61110 | 468 (add-to-list |
469 'format-alist | |
67024 | 470 (list 'longlines "Automatically wrap long lines." nil nil |
67021
e220d76071f7
* longlines.el (longlines-before-revert-hook)
Chong Yidong <cyd@stupidchicken.com>
parents:
66996
diff
changeset
|
471 'longlines-encode-region t nil)) |
61110 | 472 |
473 (provide 'longlines) | |
474 | |
61125
93886f61ae3e
Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents:
61110
diff
changeset
|
475 ;; arch-tag: 3489d225-5506-47b9-8659-d8807b77c624 |
61110 | 476 ;;; longlines.el ends here |