annotate lisp/longlines.el @ 94794:f108de597672

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