diff options
author | Richard M. Stallman <rms@gnu.org> | 1996-09-01 03:24:55 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1996-09-01 03:24:55 +0000 |
commit | 8a5df248c759ac27b5b6c12742124d4cd2df82bd (patch) | |
tree | 76acc0163a94a7169dcd411a5a3935c31eaf81b4 /lisp/textmodes | |
parent | 02ea83e56682200b03b9dd126643b6a0953706ec (diff) | |
download | emacs-8a5df248c759ac27b5b6c12742124d4cd2df82bd.tar.gz |
(use-hard-newlines): New minor mode function.
Existing variable gets doc fix.
Diffstat (limited to 'lisp/textmodes')
-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 @@ (defvar use-hard-newlines nil "Non-nil means to distinguish hard and soft newlines. -When this is non-nil, the functions `newline' and `open-line' add the -text-property `hard' to newlines that they insert. Also, a line is -only considered as a candidate to match `paragraph-start' or -`paragraph-separate' if it follows a hard newline. Newlines not -marked hard are called \"soft\", and are always internal to -paragraphs. The fill functions always insert soft newlines. - -Each buffer has its own value of this variable.") +See documentation for the `use-hard-newlines' function.") (make-variable-buffer-local 'use-hard-newlines) +(defun use-hard-newlines (&optional arg insert) + "Minor mode to distinguish hard and soft newlines. +When active, the functions `newline' and `open-line' add the +text-property `hard' to newlines that they insert, and a line is +only considered as a candidate to match `paragraph-start' or +`paragraph-separate' if it follows a hard newline. + +Prefix argument says to turn mode on if positive, off if negative. +When the mode is turned on, if there are newlines in the buffer but no hard +newlines, ask the user whether to mark as hard any newlines preceeding a +`paragraph-start' line. From a program, second arg INSERT specifies whether +to do this; it can be `never' to change nothing, t or `always' to force +marking, `guess' to try to do the right thing with no questions, nil +or anything else to ask the user. + +Newlines not marked hard are called \"soft\", and are always internal +to paragraphs. The fill functions insert and delete only soft newlines." + (interactive (list current-prefix-arg nil)) + (if (or (<= (prefix-numeric-value arg) 0) + (and use-hard-newlines (null arg))) + ;; Turn mode off + (setq use-hard-newlines nil) + ;; Turn mode on + ;; Intuit hard newlines -- + ;; mark as hard any newlines preceding a paragraph-start line. + (if (or (eq insert t) (eq insert 'always) + (and (not (eq 'never insert)) + (not use-hard-newlines) + (not (text-property-any (point-min) (point-max) 'hard t)) + (save-excursion + (goto-char (point-min)) + (search-forward "\n" nil t)) + (or (eq insert 'guess) + (y-or-n-p "Make newlines between paragraphs hard? ")))) + (save-excursion + (goto-char (point-min)) + (while (search-forward "\n" nil t) + (let ((pos (point))) + (move-to-left-margin) + (if (looking-at paragraph-start) + (progn + (set-hard-newline-properties (1- pos) pos) + ;; If paragraph-separate, newline after it is hard too. + (if (looking-at paragraph-separate) + (progn + (end-of-line) + (if (not (eobp)) + (set-hard-newline-properties + (point) (1+ (point)))))))))))) + (setq use-hard-newlines t))) + (defconst paragraph-start "[ \t\n\f]" "\ *Regexp for beginning of a line that starts OR separates paragraphs. This regexp should match lines that separate paragraphs |