diff options
| author | Richard M. Stallman | 1995-01-13 08:44:43 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-01-13 08:44:43 +0000 |
| commit | a37669ece7d909bd2830c4b69bd5c53ca8d7270b (patch) | |
| tree | fa7093ea66d80c2571253f29b0beba531749b2ae | |
| parent | a098333daefdaa5cb1a0ca8f225de5ffc40e6a89 (diff) | |
| download | emacs-a37669ece7d909bd2830c4b69bd5c53ca8d7270b.tar.gz emacs-a37669ece7d909bd2830c4b69bd5c53ca8d7270b.zip | |
(forward-paragraph): Notice use-hard-newlines value.
(looking-at-hard): New function.
(paragraph-start, paragraph-separate): Doc fix.
| -rw-r--r-- | lisp/textmodes/paragraphs.el | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index 2a08bb21966..c85b15249f3 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el | |||
| @@ -33,12 +33,19 @@ | |||
| 33 | This regexp should match lines that separate paragraphs | 33 | This regexp should match lines that separate paragraphs |
| 34 | and should also match lines that start a paragraph | 34 | and should also match lines that start a paragraph |
| 35 | \(and are part of that paragraph). | 35 | \(and are part of that paragraph). |
| 36 | |||
| 36 | The variable `paragraph-separate' specifies how to distinguish | 37 | The variable `paragraph-separate' specifies how to distinguish |
| 37 | lines that start paragraphs from lines that separate them.") | 38 | lines that start paragraphs from lines that separate them. |
| 39 | |||
| 40 | If the variable `use-hard-newlines' is nonnil, then only lines following a | ||
| 41 | hard newline are considered to match.") | ||
| 38 | 42 | ||
| 39 | (defconst paragraph-separate "^[ \t\f]*$" "\ | 43 | (defconst paragraph-separate "^[ \t\f]*$" "\ |
| 40 | *Regexp for beginning of a line that separates paragraphs. | 44 | *Regexp for beginning of a line that separates paragraphs. |
| 41 | If you change this, you may have to change paragraph-start also.") | 45 | If you change this, you may have to change paragraph-start also. |
| 46 | |||
| 47 | If the variable `use-hard-newlines' is nonnil, then only lines following a | ||
| 48 | hard newline are considered to match.") | ||
| 42 | 49 | ||
| 43 | (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\ | 50 | (defconst sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") "\ |
| 44 | *Regexp describing the end of a sentence. | 51 | *Regexp describing the end of a sentence. |
| @@ -55,6 +62,12 @@ unless it's inside some sort of quotes or parenthesis.") | |||
| 55 | Non-nil means the paragraph commands are not affected by `fill-prefix'. | 62 | Non-nil means the paragraph commands are not affected by `fill-prefix'. |
| 56 | This is desirable in modes where blank lines are the paragraph delimiters.") | 63 | This is desirable in modes where blank lines are the paragraph delimiters.") |
| 57 | 64 | ||
| 65 | (defsubst looking-at-hard (re) | ||
| 66 | ;; Just for convenience in writing the function below. | ||
| 67 | (and (or (null use-hard-newlines) | ||
| 68 | (bobp) | ||
| 69 | (get-text-property (1- (point)) 'hard)) | ||
| 70 | (looking-at re))) | ||
| 58 | 71 | ||
| 59 | (defun forward-paragraph (&optional arg) | 72 | (defun forward-paragraph (&optional arg) |
| 60 | "Move forward to end of paragraph. | 73 | "Move forward to end of paragraph. |
| @@ -76,12 +89,14 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 76 | fill-prefix-regexp "[ \t]*$") | 89 | fill-prefix-regexp "[ \t]*$") |
| 77 | paragraph-separate))) | 90 | paragraph-separate))) |
| 78 | (while (and (< arg 0) (not (bobp))) | 91 | (while (and (< arg 0) (not (bobp))) |
| 79 | (if (and (not (looking-at paragraph-separate)) | 92 | (if (and (not (looking-at-hard paragraph-separate)) |
| 80 | (re-search-backward "^\n" (max (1- (point)) (point-min)) t)) | 93 | (re-search-backward "^\n" (max (1- (point)) (point-min)) t) |
| 94 | (looking-at-hard paragraph-separate)) | ||
| 81 | nil | 95 | nil |
| 82 | ;; Move back over paragraph-separating lines. | 96 | ;; Move back over paragraph-separating lines. |
| 83 | (forward-char -1) (beginning-of-line) | 97 | (forward-char -1) (beginning-of-line) |
| 84 | (while (and (not (bobp)) (looking-at paragraph-separate)) | 98 | (while (and (not (bobp)) |
| 99 | (looking-at-hard paragraph-separate)) | ||
| 85 | (forward-line -1)) | 100 | (forward-line -1)) |
| 86 | (if (bobp) | 101 | (if (bobp) |
| 87 | nil | 102 | nil |
| @@ -93,17 +108,23 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 93 | (progn | 108 | (progn |
| 94 | (while (progn (beginning-of-line) | 109 | (while (progn (beginning-of-line) |
| 95 | (and (not (bobp)) | 110 | (and (not (bobp)) |
| 96 | (not (looking-at paragraph-separate)) | 111 | (not (looking-at-hard |
| 112 | paragraph-separate)) | ||
| 97 | (looking-at fill-prefix-regexp))) | 113 | (looking-at fill-prefix-regexp))) |
| 98 | (forward-line -1)) | 114 | (forward-line -1)) |
| 99 | (not (bobp))) | 115 | (not (bobp))) |
| 100 | (re-search-backward paragraph-start nil t)) | 116 | (while (and (re-search-backward paragraph-start nil 1) |
| 117 | use-hard-newlines | ||
| 118 | (not (bobp)) | ||
| 119 | (null (get-text-property (1- (point)) 'hard))) | ||
| 120 | (if (not (bobp)) (backward-char 1))) | ||
| 121 | (> (point) (point-min))) | ||
| 101 | ;; Found one. | 122 | ;; Found one. |
| 102 | (progn | 123 | (progn |
| 103 | ;; Move forward over paragraph separators. | 124 | ;; Move forward over paragraph separators. |
| 104 | ;; We know this cannot reach the place we started | 125 | ;; We know this cannot reach the place we started |
| 105 | ;; because we know we moved back over a non-separator. | 126 | ;; because we know we moved back over a non-separator. |
| 106 | (while (and (not (eobp)) (looking-at paragraph-separate)) | 127 | (while (and (not (eobp)) (looking-at-hard paragraph-separate)) |
| 107 | (forward-line 1)) | 128 | (forward-line 1)) |
| 108 | (if (eq (char-after (- (point) 2)) ?\n) | 129 | (if (eq (char-after (- (point) 2)) ?\n) |
| 109 | (forward-line -1))) | 130 | (forward-line -1))) |
| @@ -113,17 +134,21 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 113 | (while (and (> arg 0) (not (eobp))) | 134 | (while (and (> arg 0) (not (eobp))) |
| 114 | (beginning-of-line) | 135 | (beginning-of-line) |
| 115 | (while (prog1 (and (not (eobp)) | 136 | (while (prog1 (and (not (eobp)) |
| 116 | (looking-at paragraph-separate)) | 137 | (looking-at-hard paragraph-separate)) |
| 117 | (forward-line 1))) | 138 | (forward-line 1))) |
| 118 | (if fill-prefix-regexp | 139 | (if fill-prefix-regexp |
| 119 | ;; There is a fill prefix; it overrides paragraph-start. | 140 | ;; There is a fill prefix; it overrides paragraph-start. |
| 120 | (while (and (not (eobp)) | 141 | (while (and (not (eobp)) |
| 121 | (not (looking-at paragraph-separate)) | 142 | (not (looking-at-hard paragraph-separate)) |
| 122 | (looking-at fill-prefix-regexp)) | 143 | (looking-at fill-prefix-regexp)) |
| 123 | (forward-line 1)) | 144 | (forward-line 1)) |
| 124 | (if (re-search-forward paragraph-start nil t) | 145 | (while (and (not (eobp)) |
| 125 | (goto-char (match-beginning 0)) | 146 | (re-search-forward paragraph-start nil 1) |
| 126 | (goto-char (point-max)))) | 147 | use-hard-newlines |
| 148 | (null (get-text-property (1- (match-beginning 0)) 'hard))) | ||
| 149 | (forward-char 1)) | ||
| 150 | (if (< (point) (point-max)) | ||
| 151 | (goto-char (match-beginning 0)))) | ||
| 127 | (setq arg (1- arg))))) | 152 | (setq arg (1- arg))))) |
| 128 | 153 | ||
| 129 | (defun backward-paragraph (&optional arg) | 154 | (defun backward-paragraph (&optional arg) |