Mercurial > hg > xemacs-beta
diff lisp/paragraphs.el @ 215:1f0dabaa0855 r20-4b6
Import from CVS: tag r20-4b6
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:07:35 +0200 |
parents | 78478c60bfcd |
children | a4f53d9b3154 |
line wrap: on
line diff
--- a/lisp/paragraphs.el Mon Aug 13 10:06:48 2007 +0200 +++ b/lisp/paragraphs.el Mon Aug 13 10:07:35 2007 +0200 @@ -48,6 +48,57 @@ Each buffer has its own value of this variable.") (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))) + ;; XEmacs - use purecopy (defconst paragraph-start (purecopy "[ \t\n\f]") "\ *Regexp for beginning of a line that starts OR separates paragraphs.