comparison 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
comparison
equal deleted inserted replaced
214:c5d88c05e1e9 215:1f0dabaa0855
45 marked hard are called \"soft\", and are always internal to 45 marked hard are called \"soft\", and are always internal to
46 paragraphs. The fill functions always insert soft newlines. 46 paragraphs. The fill functions always insert soft newlines.
47 47
48 Each buffer has its own value of this variable.") 48 Each buffer has its own value of this variable.")
49 (make-variable-buffer-local 'use-hard-newlines) 49 (make-variable-buffer-local 'use-hard-newlines)
50
51 (defun use-hard-newlines (&optional arg insert)
52 "Minor mode to distinguish hard and soft newlines.
53 When active, the functions `newline' and `open-line' add the
54 text-property `hard' to newlines that they insert, and a line is
55 only considered as a candidate to match `paragraph-start' or
56 `paragraph-separate' if it follows a hard newline.
57
58 Prefix argument says to turn mode on if positive, off if negative.
59 When the mode is turned on, if there are newlines in the buffer but no hard
60 newlines, ask the user whether to mark as hard any newlines preceeding a
61 `paragraph-start' line. From a program, second arg INSERT specifies whether
62 to do this; it can be `never' to change nothing, t or `always' to force
63 marking, `guess' to try to do the right thing with no questions, nil
64 or anything else to ask the user.
65
66 Newlines not marked hard are called \"soft\", and are always internal
67 to paragraphs. The fill functions insert and delete only soft newlines."
68 (interactive (list current-prefix-arg nil))
69 (if (or (<= (prefix-numeric-value arg) 0)
70 (and use-hard-newlines (null arg)))
71 ;; Turn mode off
72 (setq use-hard-newlines nil)
73 ;; Turn mode on
74 ;; Intuit hard newlines --
75 ;; mark as hard any newlines preceding a paragraph-start line.
76 (if (or (eq insert t) (eq insert 'always)
77 (and (not (eq 'never insert))
78 (not use-hard-newlines)
79 (not (text-property-any (point-min) (point-max) 'hard t))
80 (save-excursion
81 (goto-char (point-min))
82 (search-forward "\n" nil t))
83 (or (eq insert 'guess)
84 (y-or-n-p "Make newlines between paragraphs hard? "))))
85 (save-excursion
86 (goto-char (point-min))
87 (while (search-forward "\n" nil t)
88 (let ((pos (point)))
89 (move-to-left-margin)
90 (if (looking-at paragraph-start)
91 (progn
92 (set-hard-newline-properties (1- pos) pos)
93 ;; If paragraph-separate, newline after it is hard too.
94 (if (looking-at paragraph-separate)
95 (progn
96 (end-of-line)
97 (if (not (eobp))
98 (set-hard-newline-properties
99 (point) (1+ (point))))))))))))
100 (setq use-hard-newlines t)))
50 101
51 ;; XEmacs - use purecopy 102 ;; XEmacs - use purecopy
52 (defconst paragraph-start (purecopy "[ \t\n\f]") "\ 103 (defconst paragraph-start (purecopy "[ \t\n\f]") "\
53 *Regexp for beginning of a line that starts OR separates paragraphs. 104 *Regexp for beginning of a line that starts OR separates paragraphs.
54 This regexp should match lines that separate paragraphs 105 This regexp should match lines that separate paragraphs