aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1998-10-21 11:50:56 +0000
committerKenichi Handa1998-10-21 11:50:56 +0000
commitce82deede20bb588e44520fb51c4fb25cf39c97c (patch)
treebaf6e1e937d88142f27534919775ffce20d0bf91
parent9ebe6947aeed0d92ae7d3e634d4a384be744db24 (diff)
downloademacs-ce82deede20bb588e44520fb51c4fb25cf39c97c.tar.gz
emacs-ce82deede20bb588e44520fb51c4fb25cf39c97c.zip
(sentence-end-without-period): New variable.
(canonically-space-region): Pay attention to sentence-end-without-period. (fill-find-break-point): The first argument CHARSET deleted. Caller changed. (fill-region-as-paragraph): Pay attention to charset property nospace-between-words and text property nospace-between-words.
-rw-r--r--lisp/textmodes/fill.el87
1 files changed, 58 insertions, 29 deletions
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index e96d20ace1c..a563cb52d72 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -47,6 +47,12 @@ A value of nil means that any change in indentation starts a new paragraph."
47 :type 'boolean 47 :type 'boolean
48 :group 'fill) 48 :group 'fill)
49 49
50(defcustom sentence-end-without-period nil
51 "*Non-nil means a sentence will end without period.
52For example, Thai text ends with double space but without period."
53 :type 'boolean
54 :group 'fill)
55
50(defvar fill-paragraph-function nil 56(defvar fill-paragraph-function nil
51 "Mode-specific function to fill a paragraph, or nil if there is none. 57 "Mode-specific function to fill a paragraph, or nil if there is none.
52If the function returns nil, then `fill-paragraph' does its normal work.") 58If the function returns nil, then `fill-paragraph' does its normal work.")
@@ -136,7 +142,8 @@ number equals or exceeds the local fill-column - right-margin difference."
136(defun canonically-space-region (beg end) 142(defun canonically-space-region (beg end)
137 "Remove extra spaces between words in region. 143 "Remove extra spaces between words in region.
138Leave one space between words, two at end of sentences or after colons 144Leave one space between words, two at end of sentences or after colons
139\(depending on values of `sentence-end-double-space' and `colon-double-space'). 145\(depending on values of `sentence-end-double-space', `colon-double-space',
146and `sentence-end-without-period').
140Remove indentation from each line." 147Remove indentation from each line."
141 (interactive "r") 148 (interactive "r")
142 (save-excursion 149 (save-excursion
@@ -154,7 +161,9 @@ Remove indentation from each line."
154 (save-excursion 161 (save-excursion
155 (skip-chars-backward " ]})\"'") 162 (skip-chars-backward " ]})\"'")
156 (cond ((and sentence-end-double-space 163 (cond ((and sentence-end-double-space
157 (memq (preceding-char) '(?. ?? ?!))) 2) 164 (or (memq (preceding-char) '(?. ?? ?!))
165 (and sentence-end-without-period
166 (= (char-syntax (preceding-char)) ?w)))) 2)
158 ((and colon-double-space 167 ((and colon-double-space
159 (= (preceding-char) ?:)) 2) 168 (= (preceding-char) ?:)) 2)
160 ((char-equal (preceding-char) ?\n) 0) 169 ((char-equal (preceding-char) ?\n) 0)
@@ -252,6 +261,8 @@ act as a paragraph-separator."
252The predicate is called with no arguments, with point at the place 261The predicate is called with no arguments, with point at the place
253to be tested. If it returns t, fill commands do not break the line there.") 262to be tested. If it returns t, fill commands do not break the line there.")
254 263
264;; Put `fill-find-break-point-function' property to charsets which
265;; require special functions to find line breaking point.
255(let ((alist '((katakana-jisx0201 . kinsoku) 266(let ((alist '((katakana-jisx0201 . kinsoku)
256 (chinese-gb2312 . kinsoku) 267 (chinese-gb2312 . kinsoku)
257 (japanese-jisx0208 . kinsoku) 268 (japanese-jisx0208 . kinsoku)
@@ -263,18 +274,28 @@ to be tested. If it returns t, fill commands do not break the line there.")
263 (cdr (car alist))) 274 (cdr (car alist)))
264 (setq alist (cdr alist)))) 275 (setq alist (cdr alist))))
265 276
266(defun fill-find-break-point (charset limit) 277(defun fill-find-break-point (limit)
267 "Move point to a proper line wrapping position of the current line. 278 "Move point to a proper line breaking position of the current line.
268
269CHARSET is a non-ascii character set before or after the current position.
270Don't move back past the buffer position LIMIT. 279Don't move back past the buffer position LIMIT.
271 280
272If CHARSET has the property `fill-find-break-point-function', this 281This function is called when we are going to break the current line
282after or before a non-ascii character. If the charset of the
283character has the property `fill-find-break-point-function', this
273function calls the property value as a function with one arg LINEBEG. 284function calls the property value as a function with one arg LINEBEG.
274If CHARSET has no such property, do nothing." 285If the charset has no such property, do nothing."
275 (let ((func (get-charset-property charset 'fill-find-break-point-function))) 286 (let* ((ch (following-char))
276 (if func 287 (charset (char-charset ch))
277 (funcall func limit)))) 288 func)
289 (if (eq charset 'ascii)
290 (setq ch (preceding-char)
291 charset (char-charset ch)))
292 (if (eq charset 'ascii)
293 nil
294 (if (eq charset 'composition)
295 (setq charset (char-charset (composite-char-component ch 0)))))
296 (setq func (get-charset-property charset 'fill-find-break-point-function))
297 (if (and func (fboundp func))
298 (funcall func limit))))
278 299
279(defun fill-region-as-paragraph (from to &optional justify 300(defun fill-region-as-paragraph (from to &optional justify
280 nosqueeze squeeze-after) 301 nosqueeze squeeze-after)
@@ -398,19 +419,29 @@ space does not end a sentence, so don't break a line there."
398 ;; loses on split abbrevs ("Mr.\nSmith") 419 ;; loses on split abbrevs ("Mr.\nSmith")
399 (while (re-search-forward "[.?!][])}\"']*$" nil t) 420 (while (re-search-forward "[.?!][])}\"']*$" nil t)
400 (or (eobp) (insert-and-inherit ?\ ))) 421 (or (eobp) (insert-and-inherit ?\ )))
401 (goto-char from) 422
402 ;; The character category `|' means that we can break a line 423 (goto-char from)
403 ;; at the character. Since we don't need a space between 424 (if enable-multibyte-characters
404 ;; them, delete all newlines between them ... 425 ;; Delete unnecessay newlines surrounded by words. The
405 (while (re-search-forward "\\c|\n\\|\n\\c|" nil t) 426 ;; character category `|' means that we can break a line
406 (if (bolp) 427 ;; at the character. And, charset property
407 (delete-char -1) 428 ;; `nospace-between-words' tells how to concatenate
408 (if (= (char-before (match-beginning 0)) ?\ ) 429 ;; words. If the value is non-nil, never put spaces
409 ;; ... except when there is end of sentence. The 430 ;; between words, thus delete a newline between them.
410 ;; variable `sentence-end-double-space' is handled 431 ;; If the value is nil, delete a newline only when a
411 ;; properly later. 432 ;; character preceding a newline has text property
412 nil 433 ;; `nospace-between-words'.
413 (delete-region (match-beginning 0) (1+ (match-beginning 0)))))) 434 (while (search-forward "\n" nil t)
435 (let ((prev (char-before (match-beginning 0)))
436 (next (following-char)))
437 (if (and (or (aref (char-category-set next) ?|)
438 (aref (char-category-set prev) ?|))
439 (or (get-charset-property (char-charset prev)
440 'nospace-between-words)
441 (get-text-property (1- (match-beginning 0))
442 'nospace-between-words)))
443 (delete-char -1)))))
444
414 (goto-char from) 445 (goto-char from)
415 (skip-chars-forward " \t") 446 (skip-chars-forward " \t")
416 ;; Then change all newlines to spaces. 447 ;; Then change all newlines to spaces.
@@ -504,11 +535,9 @@ space does not end a sentence, so don't break a line there."
504 ;; before a non-ascii character, we may have to 535 ;; before a non-ascii character, we may have to
505 ;; run a special function for the charset of the 536 ;; run a special function for the charset of the
506 ;; character to find the correct break point. 537 ;; character to find the correct break point.
507 (let ((charset (charset-after (1- (point))))) 538 (if (not (and (eq (charset-after (1- (point))) 'ascii)
508 (if (eq charset 'ascii) 539 (eq (charset-after (point)) 'ascii)))
509 (setq charset (charset-after (point)))) 540 (fill-find-break-point linebeg))))
510 (if (not (eq charset 'ascii))
511 (fill-find-break-point charset linebeg)))))
512 541
513 ;; If the left margin and fill prefix by themselves 542 ;; If the left margin and fill prefix by themselves
514 ;; pass the fill-column, keep at least one word. 543 ;; pass the fill-column, keep at least one word.