--- latex.el.org 2005-02-11 07:05:54.000000000 +0900 +++ latex.el 2005-02-27 19:54:29.157277392 +0900 @@ -2243,6 +2243,21 @@ :group 'LaTeX :type 'boolean) +(defcustom LaTeX-nospace-between-char-regexp + (if (featurep 'xemacs) + (if (and (boundp 'word-across-newline) word-across-newline) + word-across-newline + ;; NOTE: Ensure not to have a value of nil for such a rare case that + ;; somebody removes the mule test in `LaTeX-fill-delete-newlines' so that + ;; it could match only "\n" and this could lead to problem. XEmacs does + ;; not have a category `\c|' and `\ct' means `Chinese Taiwan' in XEmacs. + "\\(\\cj\\|\\cc\\|\\ct\\)") + "\\c|") + "Regexp matching a character where no interword space is necessary. +Words formed by such characters can be broken across newlines." + :group 'LaTeX + :type 'regexp) + (defun LaTeX-fill-region-as-paragraph (from to &optional justify-flag) "Fill region as one paragraph. Break lines to fit `fill-column', but leave all lines ending with @@ -2423,30 +2438,7 @@ ;; FROM, and point, are now before the text to fill, ;; but after any fill prefix on the first line. - ;; COMPATIBILITY for Emacs <= 21.1 - (if (fboundp 'fill-delete-newlines) - (fill-delete-newlines from to justify nosqueeze squeeze-after) - ;; Make sure sentences ending at end of line get an extra space. - (if (or (not (boundp 'sentence-end-double-space)) - sentence-end-double-space) - (progn - (goto-char from) - (while (re-search-forward "[.?!][]})\"']*$" to t) - (insert ? )))) - ;; Then change all newlines to spaces. - (let ((point-max (progn - (goto-char to) - (skip-chars-backward "\n") - (point)))) - (subst-char-in-region from point-max ?\n ?\ )) - (goto-char from) - (skip-chars-forward " \t") - ;; Remove extra spaces between words. - (unless (and nosqueeze (not (eq justify 'full))) - (canonically-space-region (or squeeze-after (point)) to) - ;; Remove trailing whitespace. - (goto-char (line-end-position)) - (delete-char (- (skip-chars-backward " \t"))))) + (LaTeX-fill-delete-newlines from to justify nosqueeze squeeze-after) ;; This is the actual FILLING LOOP. (goto-char from) @@ -2540,12 +2532,61 @@ ;; Return the fill-prefix we used fill-prefix))) +(defun LaTeX-fill-delete-newlines (from to justify nosqueeze squeeze-after) + ;; COMPATIBILITY for Emacs < 22.1 and XEmacs + (if (fboundp 'fill-delete-newlines) + (fill-delete-newlines from to justify nosqueeze squeeze-after) + (if (featurep 'xemacs) + (when (featurep 'mule) + (goto-char from) + (let ((unwished-newline (concat LaTeX-nospace-between-char-regexp "\n" + LaTeX-nospace-between-char-regexp))) + (while (re-search-forward unwished-newline to t) + (skip-chars-backward "^\n") + (delete-char -1)))) + ;; This else-sentence was copied from the function `fill-delete-newlines' + ;; in `fill.el' (CVS Emacs, 2005-02-17) and adapted accordingly. + (while (search-forward "\n" to t) + (let ((prev (char-before (match-beginning 0))) + (next (following-char))) + (when (or (aref (char-category-set next) ?|) + (aref (char-category-set prev) ?|)) + (delete-char -1))))) + + ;; Make sure sentences ending at end of line get an extra space. + (if (or (not (boundp 'sentence-end-double-space)) + sentence-end-double-space) + (progn + (goto-char from) + (while (re-search-forward "[.?!][]})\"']*$" to t) + (insert ? )))) + ;; Then change all newlines to spaces. + (let ((point-max (progn + (goto-char to) + (skip-chars-backward "\n") + (point)))) + (subst-char-in-region from point-max ?\n ?\ )) + (goto-char from) + (skip-chars-forward " \t") + ;; Remove extra spaces between words. + (unless (and nosqueeze (not (eq justify 'full))) + (canonically-space-region (or squeeze-after (point)) to) + ;; Remove trailing whitespace. + (goto-char (line-end-position)) + (delete-char (- (skip-chars-backward " \t")))))) + (defun LaTeX-fill-move-to-break-point (linebeg) "Move to the position where the line should be broken." - ;; COMPATIBILITY for Emacs <= 21.3 and XEmacs + ;; COMPATIBILITY for Emacs < 22.1 and XEmacs (if (fboundp 'fill-move-to-break-point) (fill-move-to-break-point linebeg) - (skip-chars-backward "^ \n") + ;; Cancel `forward-char' which is called just before + ;; `LaTeX-fill-move-to-break-point' if the char before point matches + ;; `LaTeX-nospace-between-char-regexp'. + (if (and (featurep 'mule) + (TeX-looking-at-backward LaTeX-nospace-between-char-regexp)) + (backward-char 1) + (skip-chars-backward "^ \n")) ;; Prevent infinite loops: If we cannot find a place to break ;; while searching backward, search forward again. (cond ((bolp) @@ -2554,7 +2595,22 @@ (concat "^[ \t]+\\|^[ \t]*" TeX-comment-start-regexp "+[ \t]*") (1- (line-beginning-position))) (goto-char (match-end 0)) - (skip-chars-forward "^ \n" (point-max))))) + (skip-chars-forward "^ \n" (point-max)))) + ;; This code was copied from the function `fill-move-to-break-point' + ;; in `fill.el' (CVS Emacs, 2005-02-22) and adapted accordingly. + (when (and (< linebeg (point)) + ;; If we are going to break the line after or + ;; before a non-ascii character, we may have to + ;; run a special function for the charset of the + ;; character to find the correct break point. + enable-multibyte-characters + (not (and (eq (charset-after (1- (point))) 'ascii) + (eq (charset-after (point)) 'ascii)))) + ;; Make sure we take SOMETHING after the fill prefix if any. + (if (fboundp 'fill-find-break-point) + (fill-find-break-point linebeg) + (when (fboundp 'kinsoku-process) ;XEmacs + (kinsoku-process))))) ;; Cater for \verb|...| (and similar) contructs which should not be ;; broken. (FIXME: Make it work with shortvrb.sty (also loaded by ;; doc.sty) where |...| is allowed. Arbitrary delimiters may be