(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.
This commit is contained in:
Kenichi Handa 1998-10-21 11:50:56 +00:00
parent 9ebe6947ae
commit ce82deede2

View file

@ -47,6 +47,12 @@ A value of nil means that any change in indentation starts a new paragraph."
:type 'boolean :type 'boolean
:group 'fill) :group 'fill)
(defcustom sentence-end-without-period nil
"*Non-nil means a sentence will end without period.
For example, Thai text ends with double space but without period."
:type 'boolean
:group 'fill)
(defvar fill-paragraph-function nil (defvar fill-paragraph-function nil
"Mode-specific function to fill a paragraph, or nil if there is none. "Mode-specific function to fill a paragraph, or nil if there is none.
If the function returns nil, then `fill-paragraph' does its normal work.") If 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."
(defun canonically-space-region (beg end) (defun canonically-space-region (beg end)
"Remove extra spaces between words in region. "Remove extra spaces between words in region.
Leave one space between words, two at end of sentences or after colons Leave one space between words, two at end of sentences or after colons
\(depending on values of `sentence-end-double-space' and `colon-double-space'). \(depending on values of `sentence-end-double-space', `colon-double-space',
and `sentence-end-without-period').
Remove indentation from each line." Remove indentation from each line."
(interactive "r") (interactive "r")
(save-excursion (save-excursion
@ -154,7 +161,9 @@ Remove indentation from each line."
(save-excursion (save-excursion
(skip-chars-backward " ]})\"'") (skip-chars-backward " ]})\"'")
(cond ((and sentence-end-double-space (cond ((and sentence-end-double-space
(memq (preceding-char) '(?. ?? ?!))) 2) (or (memq (preceding-char) '(?. ?? ?!))
(and sentence-end-without-period
(= (char-syntax (preceding-char)) ?w)))) 2)
((and colon-double-space ((and colon-double-space
(= (preceding-char) ?:)) 2) (= (preceding-char) ?:)) 2)
((char-equal (preceding-char) ?\n) 0) ((char-equal (preceding-char) ?\n) 0)
@ -252,6 +261,8 @@ act as a paragraph-separator."
The predicate is called with no arguments, with point at the place The predicate is called with no arguments, with point at the place
to be tested. If it returns t, fill commands do not break the line there.") to be tested. If it returns t, fill commands do not break the line there.")
;; Put `fill-find-break-point-function' property to charsets which
;; require special functions to find line breaking point.
(let ((alist '((katakana-jisx0201 . kinsoku) (let ((alist '((katakana-jisx0201 . kinsoku)
(chinese-gb2312 . kinsoku) (chinese-gb2312 . kinsoku)
(japanese-jisx0208 . kinsoku) (japanese-jisx0208 . kinsoku)
@ -263,18 +274,28 @@ to be tested. If it returns t, fill commands do not break the line there.")
(cdr (car alist))) (cdr (car alist)))
(setq alist (cdr alist)))) (setq alist (cdr alist))))
(defun fill-find-break-point (charset limit) (defun fill-find-break-point (limit)
"Move point to a proper line wrapping position of the current line. "Move point to a proper line breaking position of the current line.
CHARSET is a non-ascii character set before or after the current position.
Don't move back past the buffer position LIMIT. Don't move back past the buffer position LIMIT.
If CHARSET has the property `fill-find-break-point-function', this This function is called when we are going to break the current line
after or before a non-ascii character. If the charset of the
character has the property `fill-find-break-point-function', this
function calls the property value as a function with one arg LINEBEG. function calls the property value as a function with one arg LINEBEG.
If CHARSET has no such property, do nothing." If the charset has no such property, do nothing."
(let ((func (get-charset-property charset 'fill-find-break-point-function))) (let* ((ch (following-char))
(if func (charset (char-charset ch))
(funcall func limit)))) func)
(if (eq charset 'ascii)
(setq ch (preceding-char)
charset (char-charset ch)))
(if (eq charset 'ascii)
nil
(if (eq charset 'composition)
(setq charset (char-charset (composite-char-component ch 0)))))
(setq func (get-charset-property charset 'fill-find-break-point-function))
(if (and func (fboundp func))
(funcall func limit))))
(defun fill-region-as-paragraph (from to &optional justify (defun fill-region-as-paragraph (from to &optional justify
nosqueeze squeeze-after) nosqueeze squeeze-after)
@ -398,19 +419,29 @@ space does not end a sentence, so don't break a line there."
;; loses on split abbrevs ("Mr.\nSmith") ;; loses on split abbrevs ("Mr.\nSmith")
(while (re-search-forward "[.?!][])}\"']*$" nil t) (while (re-search-forward "[.?!][])}\"']*$" nil t)
(or (eobp) (insert-and-inherit ?\ ))) (or (eobp) (insert-and-inherit ?\ )))
(goto-char from)
;; The character category `|' means that we can break a line (goto-char from)
;; at the character. Since we don't need a space between (if enable-multibyte-characters
;; them, delete all newlines between them ... ;; Delete unnecessay newlines surrounded by words. The
(while (re-search-forward "\\c|\n\\|\n\\c|" nil t) ;; character category `|' means that we can break a line
(if (bolp) ;; at the character. And, charset property
(delete-char -1) ;; `nospace-between-words' tells how to concatenate
(if (= (char-before (match-beginning 0)) ?\ ) ;; words. If the value is non-nil, never put spaces
;; ... except when there is end of sentence. The ;; between words, thus delete a newline between them.
;; variable `sentence-end-double-space' is handled ;; If the value is nil, delete a newline only when a
;; properly later. ;; character preceding a newline has text property
nil ;; `nospace-between-words'.
(delete-region (match-beginning 0) (1+ (match-beginning 0)))))) (while (search-forward "\n" nil t)
(let ((prev (char-before (match-beginning 0)))
(next (following-char)))
(if (and (or (aref (char-category-set next) ?|)
(aref (char-category-set prev) ?|))
(or (get-charset-property (char-charset prev)
'nospace-between-words)
(get-text-property (1- (match-beginning 0))
'nospace-between-words)))
(delete-char -1)))))
(goto-char from) (goto-char from)
(skip-chars-forward " \t") (skip-chars-forward " \t")
;; Then change all newlines to spaces. ;; Then change all newlines to spaces.
@ -504,11 +535,9 @@ space does not end a sentence, so don't break a line there."
;; before a non-ascii character, we may have to ;; before a non-ascii character, we may have to
;; run a special function for the charset of the ;; run a special function for the charset of the
;; character to find the correct break point. ;; character to find the correct break point.
(let ((charset (charset-after (1- (point))))) (if (not (and (eq (charset-after (1- (point))) 'ascii)
(if (eq charset 'ascii) (eq (charset-after (point)) 'ascii)))
(setq charset (charset-after (point)))) (fill-find-break-point linebeg))))
(if (not (eq charset 'ascii))
(fill-find-break-point charset linebeg)))))
;; If the left margin and fill prefix by themselves ;; If the left margin and fill prefix by themselves
;; pass the fill-column, keep at least one word. ;; pass the fill-column, keep at least one word.