diff options
| author | Richard M. Stallman | 1996-09-01 03:24:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-01 03:24:55 +0000 |
| commit | 965eb84afdfe12fb2d037b5019d0308b06df1653 (patch) | |
| tree | 312daa7f08e0c4df9a1a00daf9809e8df5dce00c | |
| parent | 55741b46813a1dd2199313e45db8e99acbd08a42 (diff) | |
| download | emacs-965eb84afdfe12fb2d037b5019d0308b06df1653.tar.gz emacs-965eb84afdfe12fb2d037b5019d0308b06df1653.zip | |
(use-hard-newlines): New minor mode function.
Existing variable gets doc fix.
| -rw-r--r-- | lisp/textmodes/paragraphs.el | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index 187bc9bf783..683845ac398 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el | |||
| @@ -31,16 +31,60 @@ | |||
| 31 | 31 | ||
| 32 | (defvar use-hard-newlines nil | 32 | (defvar use-hard-newlines nil |
| 33 | "Non-nil means to distinguish hard and soft newlines. | 33 | "Non-nil means to distinguish hard and soft newlines. |
| 34 | When this is non-nil, the functions `newline' and `open-line' add the | 34 | See documentation for the `use-hard-newlines' function.") |
| 35 | text-property `hard' to newlines that they insert. Also, a line is | ||
| 36 | only considered as a candidate to match `paragraph-start' or | ||
| 37 | `paragraph-separate' if it follows a hard newline. Newlines not | ||
| 38 | marked hard are called \"soft\", and are always internal to | ||
| 39 | paragraphs. The fill functions always insert soft newlines. | ||
| 40 | |||
| 41 | Each buffer has its own value of this variable.") | ||
| 42 | (make-variable-buffer-local 'use-hard-newlines) | 35 | (make-variable-buffer-local 'use-hard-newlines) |
| 43 | 36 | ||
| 37 | (defun use-hard-newlines (&optional arg insert) | ||
| 38 | "Minor mode to distinguish hard and soft newlines. | ||
| 39 | When active, the functions `newline' and `open-line' add the | ||
| 40 | text-property `hard' to newlines that they insert, and a line is | ||
| 41 | only considered as a candidate to match `paragraph-start' or | ||
| 42 | `paragraph-separate' if it follows a hard newline. | ||
| 43 | |||
| 44 | Prefix argument says to turn mode on if positive, off if negative. | ||
| 45 | When the mode is turned on, if there are newlines in the buffer but no hard | ||
| 46 | newlines, ask the user whether to mark as hard any newlines preceeding a | ||
| 47 | `paragraph-start' line. From a program, second arg INSERT specifies whether | ||
| 48 | to do this; it can be `never' to change nothing, t or `always' to force | ||
| 49 | marking, `guess' to try to do the right thing with no questions, nil | ||
| 50 | or anything else to ask the user. | ||
| 51 | |||
| 52 | Newlines not marked hard are called \"soft\", and are always internal | ||
| 53 | to paragraphs. The fill functions insert and delete only soft newlines." | ||
| 54 | (interactive (list current-prefix-arg nil)) | ||
| 55 | (if (or (<= (prefix-numeric-value arg) 0) | ||
| 56 | (and use-hard-newlines (null arg))) | ||
| 57 | ;; Turn mode off | ||
| 58 | (setq use-hard-newlines nil) | ||
| 59 | ;; Turn mode on | ||
| 60 | ;; Intuit hard newlines -- | ||
| 61 | ;; mark as hard any newlines preceding a paragraph-start line. | ||
| 62 | (if (or (eq insert t) (eq insert 'always) | ||
| 63 | (and (not (eq 'never insert)) | ||
| 64 | (not use-hard-newlines) | ||
| 65 | (not (text-property-any (point-min) (point-max) 'hard t)) | ||
| 66 | (save-excursion | ||
| 67 | (goto-char (point-min)) | ||
| 68 | (search-forward "\n" nil t)) | ||
| 69 | (or (eq insert 'guess) | ||
| 70 | (y-or-n-p "Make newlines between paragraphs hard? ")))) | ||
| 71 | (save-excursion | ||
| 72 | (goto-char (point-min)) | ||
| 73 | (while (search-forward "\n" nil t) | ||
| 74 | (let ((pos (point))) | ||
| 75 | (move-to-left-margin) | ||
| 76 | (if (looking-at paragraph-start) | ||
| 77 | (progn | ||
| 78 | (set-hard-newline-properties (1- pos) pos) | ||
| 79 | ;; If paragraph-separate, newline after it is hard too. | ||
| 80 | (if (looking-at paragraph-separate) | ||
| 81 | (progn | ||
| 82 | (end-of-line) | ||
| 83 | (if (not (eobp)) | ||
| 84 | (set-hard-newline-properties | ||
| 85 | (point) (1+ (point)))))))))))) | ||
| 86 | (setq use-hard-newlines t))) | ||
| 87 | |||
| 44 | (defconst paragraph-start "[ \t\n\f]" "\ | 88 | (defconst paragraph-start "[ \t\n\f]" "\ |
| 45 | *Regexp for beginning of a line that starts OR separates paragraphs. | 89 | *Regexp for beginning of a line that starts OR separates paragraphs. |
| 46 | This regexp should match lines that separate paragraphs | 90 | This regexp should match lines that separate paragraphs |