diff options
| author | Stefan Monnier | 2001-10-30 06:46:49 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2001-10-30 06:46:49 +0000 |
| commit | 629261c740735801d073f4251f76f4ddae612771 (patch) | |
| tree | b892460a1b8aacb218297133d7965340d57d941a | |
| parent | 9e59bf581e014fe12dca0514b9ad26dab56f8361 (diff) | |
| download | emacs-629261c740735801d073f4251f76f4ddae612771.tar.gz emacs-629261c740735801d073f4251f76f4ddae612771.zip | |
(sentence-end-double-space, sentence-end-without-period): Move from fill.el.
(forward-paragraph): Use `parstart' and `parsep' for temp variables
rather than rebinding `paragraph-start' and `paragraph-separate'.
| -rw-r--r-- | lisp/textmodes/paragraphs.el | 108 |
1 files changed, 66 insertions, 42 deletions
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el index 609922e456e..8b9ca150ea9 100644 --- a/lisp/textmodes/paragraphs.el +++ b/lisp/textmodes/paragraphs.el | |||
| @@ -114,7 +114,32 @@ text indented by a margin setting." | |||
| 114 | :group 'paragraphs | 114 | :group 'paragraphs |
| 115 | :type 'regexp) | 115 | :type 'regexp) |
| 116 | 116 | ||
| 117 | (defcustom sentence-end (purecopy "[.?!][]\"')}]*\\($\\| $\\|\t\\| \\)[ \t\n]*") | 117 | (defcustom sentence-end-double-space t |
| 118 | "*Non-nil means a single space does not end a sentence. | ||
| 119 | This is relevant for filling. See also `sentence-end-without-period' | ||
| 120 | and `colon-double-space'. | ||
| 121 | |||
| 122 | If you change this, you should also change `sentence-end'. See Info | ||
| 123 | node `Sentences'." | ||
| 124 | :type 'boolean | ||
| 125 | :group 'fill) | ||
| 126 | |||
| 127 | (defcustom sentence-end-without-period nil | ||
| 128 | "*Non-nil means a sentence will end without a period. | ||
| 129 | For example, a sentence in Thai text ends with double space but | ||
| 130 | without a period." | ||
| 131 | :type 'boolean | ||
| 132 | :group 'fill) | ||
| 133 | |||
| 134 | (defcustom sentence-end | ||
| 135 | (purecopy | ||
| 136 | ;; This is a bit stupid since it's not auto-updated when the | ||
| 137 | ;; other variables are changes, but it's still useful info. | ||
| 138 | (concat (if sentence-end-without-period "\\w \\|") | ||
| 139 | "[.?!][]\"')}]*" | ||
| 140 | (if sentence-end-double-space | ||
| 141 | "\\($\\| $\\|\t\\| \\)" "\\($\\|[\t ]\\)") | ||
| 142 | "[ \t\n]*")) | ||
| 118 | "*Regexp describing the end of a sentence. | 143 | "*Regexp describing the end of a sentence. |
| 119 | The value includes the whitespace following the sentence. | 144 | The value includes the whitespace following the sentence. |
| 120 | All paragraph boundaries also end sentences, regardless. | 145 | All paragraph boundaries also end sentences, regardless. |
| @@ -161,33 +186,33 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 161 | ;; starting at the left-margin. This allows paragraph commands to | 186 | ;; starting at the left-margin. This allows paragraph commands to |
| 162 | ;; work normally with indented text. | 187 | ;; work normally with indented text. |
| 163 | ;; This hack will not find problem cases like "whatever\\|^something". | 188 | ;; This hack will not find problem cases like "whatever\\|^something". |
| 164 | (paragraph-start (if (and (not (equal "" paragraph-start)) | 189 | (parstart (if (and (not (equal "" paragraph-start)) |
| 165 | (equal ?^ (aref paragraph-start 0))) | 190 | (equal ?^ (aref paragraph-start 0))) |
| 166 | (substring paragraph-start 1) | 191 | (substring paragraph-start 1) |
| 167 | paragraph-start)) | 192 | paragraph-start)) |
| 168 | (paragraph-separate (if (and (not (equal "" paragraph-separate)) | 193 | (parsep (if (and (not (equal "" paragraph-separate)) |
| 169 | (equal ?^ (aref paragraph-separate 0))) | 194 | (equal ?^ (aref paragraph-separate 0))) |
| 170 | (substring paragraph-separate 1) | 195 | (substring paragraph-separate 1) |
| 171 | paragraph-separate)) | 196 | paragraph-separate)) |
| 172 | (paragraph-separate | 197 | (parsep |
| 173 | (if fill-prefix-regexp | 198 | (if fill-prefix-regexp |
| 174 | (concat paragraph-separate "\\|" | 199 | (concat parsep "\\|" |
| 175 | fill-prefix-regexp "[ \t]*$") | 200 | fill-prefix-regexp "[ \t]*$") |
| 176 | paragraph-separate)) | 201 | parsep)) |
| 177 | ;; This is used for searching. | 202 | ;; This is used for searching. |
| 178 | (sp-paragraph-start (concat "^[ \t]*\\(" paragraph-start "\\)")) | 203 | (sp-parstart (concat "^[ \t]*\\(?:" parstart "\\|" parsep "\\)")) |
| 179 | start found-start) | 204 | start found-start) |
| 180 | (while (and (< arg 0) (not (bobp))) | 205 | (while (and (< arg 0) (not (bobp))) |
| 181 | (if (and (not (looking-at paragraph-separate)) | 206 | (if (and (not (looking-at parsep)) |
| 182 | (re-search-backward "^\n" (max (1- (point)) (point-min)) t) | 207 | (re-search-backward "^\n" (max (1- (point)) (point-min)) t) |
| 183 | (looking-at paragraph-separate)) | 208 | (looking-at parsep)) |
| 184 | nil | 209 | nil |
| 185 | (setq start (point)) | 210 | (setq start (point)) |
| 186 | ;; Move back over paragraph-separating lines. | 211 | ;; Move back over paragraph-separating lines. |
| 187 | (forward-char -1) (beginning-of-line) | 212 | (forward-char -1) (beginning-of-line) |
| 188 | (while (and (not (bobp)) | 213 | (while (and (not (bobp)) |
| 189 | (progn (move-to-left-margin) | 214 | (progn (move-to-left-margin) |
| 190 | (looking-at paragraph-separate))) | 215 | (looking-at parsep))) |
| 191 | (forward-line -1)) | 216 | (forward-line -1)) |
| 192 | (if (bobp) | 217 | (if (bobp) |
| 193 | nil | 218 | nil |
| @@ -195,38 +220,36 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 195 | (end-of-line) | 220 | (end-of-line) |
| 196 | ;; Search back for line that starts or separates paragraphs. | 221 | ;; Search back for line that starts or separates paragraphs. |
| 197 | (if (if fill-prefix-regexp | 222 | (if (if fill-prefix-regexp |
| 198 | ;; There is a fill prefix; it overrides paragraph-start. | 223 | ;; There is a fill prefix; it overrides parstart. |
| 199 | (let (multiple-lines) | 224 | (let (multiple-lines) |
| 200 | (while (and (progn (beginning-of-line) (not (bobp))) | 225 | (while (and (progn (beginning-of-line) (not (bobp))) |
| 201 | (progn (move-to-left-margin) | 226 | (progn (move-to-left-margin) |
| 202 | (not (looking-at paragraph-separate))) | 227 | (not (looking-at parsep))) |
| 203 | (looking-at fill-prefix-regexp)) | 228 | (looking-at fill-prefix-regexp)) |
| 204 | (unless (= (point) start) | 229 | (unless (= (point) start) |
| 205 | (setq multiple-lines t)) | 230 | (setq multiple-lines t)) |
| 206 | (forward-line -1)) | 231 | (forward-line -1)) |
| 207 | (move-to-left-margin) | 232 | (move-to-left-margin) |
| 208 | ;;; This deleted code caused a long hanging-indent line | 233 | ;; This deleted code caused a long hanging-indent line |
| 209 | ;;; not to be filled together with the following lines. | 234 | ;; not to be filled together with the following lines. |
| 210 | ;;; ;; Don't move back over a line before the paragraph | 235 | ;; ;; Don't move back over a line before the paragraph |
| 211 | ;;; ;; which doesn't start with fill-prefix | 236 | ;; ;; which doesn't start with fill-prefix |
| 212 | ;;; ;; unless that is the only line we've moved over. | 237 | ;; ;; unless that is the only line we've moved over. |
| 213 | ;;; (and (not (looking-at fill-prefix-regexp)) | 238 | ;; (and (not (looking-at fill-prefix-regexp)) |
| 214 | ;;; multiple-lines | 239 | ;; multiple-lines |
| 215 | ;;; (forward-line 1)) | 240 | ;; (forward-line 1)) |
| 216 | (not (bobp))) | 241 | (not (bobp))) |
| 217 | (while (and (re-search-backward sp-paragraph-start nil 1) | 242 | (while (and (re-search-backward sp-parstart nil 1) |
| 218 | (setq found-start t) | 243 | (setq found-start t) |
| 219 | ;; Found a candidate, but need to check if it is a | 244 | ;; Found a candidate, but need to check if it is a |
| 220 | ;; REAL paragraph-start. | 245 | ;; REAL parstart. |
| 221 | (progn (setq start (point)) | 246 | (progn (setq start (point)) |
| 222 | (move-to-left-margin) | 247 | (move-to-left-margin) |
| 223 | (not (looking-at paragraph-separate))) | 248 | (not (looking-at parsep))) |
| 224 | (not (and (looking-at paragraph-start) | 249 | (not (and (looking-at parstart) |
| 225 | (not | 250 | (or (not use-hard-newlines) |
| 226 | (and use-hard-newlines | 251 | (get-text-property (1- start) 'hard) |
| 227 | (not (bobp)) | 252 | (bobp))))) |
| 228 | (not (get-text-property (1- start) | ||
| 229 | 'hard))))))) | ||
| 230 | (setq found-start nil) | 253 | (setq found-start nil) |
| 231 | (goto-char start)) | 254 | (goto-char start)) |
| 232 | found-start) | 255 | found-start) |
| @@ -237,7 +260,7 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 237 | ;; because we know we moved back over a non-separator. | 260 | ;; because we know we moved back over a non-separator. |
| 238 | (while (and (not (eobp)) | 261 | (while (and (not (eobp)) |
| 239 | (progn (move-to-left-margin) | 262 | (progn (move-to-left-margin) |
| 240 | (looking-at paragraph-separate))) | 263 | (looking-at parsep))) |
| 241 | (forward-line 1)) | 264 | (forward-line 1)) |
| 242 | ;; If line before paragraph is just margin, back up to there. | 265 | ;; If line before paragraph is just margin, back up to there. |
| 243 | (end-of-line 0) | 266 | (end-of-line 0) |
| @@ -249,26 +272,27 @@ to which the end of the previous line belongs, or the end of the buffer." | |||
| 249 | ;; No starter or separator line => use buffer beg. | 272 | ;; No starter or separator line => use buffer beg. |
| 250 | (goto-char (point-min))))) | 273 | (goto-char (point-min))))) |
| 251 | (setq arg (1+ arg))) | 274 | (setq arg (1+ arg))) |
| 275 | |||
| 252 | (while (and (> arg 0) (not (eobp))) | 276 | (while (and (> arg 0) (not (eobp))) |
| 253 | ;; Move forward over separator lines, and one more line. | 277 | ;; Move forward over separator lines, and one more line. |
| 254 | (while (prog1 (and (not (eobp)) | 278 | (while (prog1 (and (not (eobp)) |
| 255 | (progn (move-to-left-margin) (not (eobp))) | 279 | (progn (move-to-left-margin) (not (eobp))) |
| 256 | (looking-at paragraph-separate)) | 280 | (looking-at parsep)) |
| 257 | (forward-line 1))) | 281 | (forward-line 1))) |
| 258 | (if fill-prefix-regexp | 282 | (if fill-prefix-regexp |
| 259 | ;; There is a fill prefix; it overrides paragraph-start. | 283 | ;; There is a fill prefix; it overrides parstart. |
| 260 | (while (and (not (eobp)) | 284 | (while (and (not (eobp)) |
| 261 | (progn (move-to-left-margin) (not (eobp))) | 285 | (progn (move-to-left-margin) (not (eobp))) |
| 262 | (not (looking-at paragraph-separate)) | 286 | (not (looking-at parsep)) |
| 263 | (looking-at fill-prefix-regexp)) | 287 | (looking-at fill-prefix-regexp)) |
| 264 | (forward-line 1)) | 288 | (forward-line 1)) |
| 265 | (while (and (re-search-forward sp-paragraph-start nil 1) | 289 | (while (and (re-search-forward sp-parstart nil 1) |
| 266 | (progn (setq start (match-beginning 0)) | 290 | (progn (setq start (match-beginning 0)) |
| 267 | (goto-char start) | 291 | (goto-char start) |
| 268 | (not (eobp))) | 292 | (not (eobp))) |
| 269 | (progn (move-to-left-margin) | 293 | (progn (move-to-left-margin) |
| 270 | (not (looking-at paragraph-separate))) | 294 | (not (looking-at parsep))) |
| 271 | (or (not (looking-at paragraph-start)) | 295 | (or (not (looking-at parstart)) |
| 272 | (and use-hard-newlines | 296 | (and use-hard-newlines |
| 273 | (not (get-text-property (1- start) 'hard))))) | 297 | (not (get-text-property (1- start) 'hard))))) |
| 274 | (forward-char 1)) | 298 | (forward-char 1)) |