[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#48937: 13.0.12; Paragraph filling with line that ends in % followed

From: Tassilo Horn
Subject: bug#48937: 13.0.12; Paragraph filling with line that ends in % followed by comment
Date: Wed, 09 Jun 2021 21:05:43 +0200
User-agent: mu4e 1.5.13; emacs 28.0.50

Gustavo Barros <gusbrs.2016@gmail.com> writes:

Hi Gustavo,

> When a paragraph containing a line whose text ends with a "legit" `\%'
> and is followed by a comment, paragraph filling joins the following
> paragraph content into the comment, when it shouldn't.

Indeed, that's a corner case nobody has bothered to handle yet.  I've
pushed a fix to master.  Please give it a try.

If you don't have a git checkout handy, you can also `eval-defun' the
function below containing the fix.


--8<---------------cut here---------------start------------->8---
(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
\\\\ \(plus its optional argument) alone.  Lines with code
comments and lines ending with `\\par' are included in filling but
act as boundaries.  Prefix arg means justify too.  From program,
pass args FROM, TO and JUSTIFY-FLAG.

You can disable filling inside a specific environment by adding
it to `LaTeX-indent-environment-list', only indentation is
performed in that case."
  (interactive "*r\nP")
  (let ((end-marker (save-excursion (goto-char to) (point-marker))))
    (if (or (assoc (LaTeX-current-environment) LaTeX-indent-environment-list)
            (member (TeX-current-macro) LaTeX-fill-excluded-macros)
            ;; This could be generalized, if there are more cases where
            ;; a special string at the start of a region to fill should
            ;; inhibit filling.
            (progn (save-excursion (goto-char from)
                                   (looking-at (concat TeX-comment-start-regexp
                                                       "+[ \t]*"
                                                       "Local Variables:")))))
        ;; Filling disabled, only do indentation.
        (indent-region from to nil)
        (goto-char from)
        (while (< (point) end-marker)
          (if (re-search-forward
               (concat "\\("
                       ;; Code comments.
                       "\\([^ \r\n%\\]\\|\\\\%\\)\\([ \t]\\|\\\\\\\\\\)*"
                       "[^\r\n\\]" TeX-comment-start-regexp
                       ;; Lines ending with `\par'.
                       "\\(\\=\\|[^" TeX-esc "\n]\\)\\("
                       (regexp-quote (concat TeX-esc TeX-esc))
                       (regexp-quote TeX-esc) "par[ \t]*"
                       "\\({[ \t]*}\\)?[ \t]*$"
                       ;; Lines ending with `\\'.
                       (regexp-quote TeX-esc)
                       (regexp-quote TeX-esc)
               end-marker t)
                (goto-char (line-end-position))
                ;; I doubt very much if we want justify -
                ;; this is a line with \\
                ;; if you think otherwise - uncomment the next line
                ;; (and justify-flag (justify-current-line))
                ;; keep our position in a buffer
                  ;; Code comments and lines ending with `\par' are
                  ;; included in filling.  Lines ending with `\\' are
                  ;; skipped.
                  (if (match-string 1)
                      (LaTeX-fill-region-as-para-do from (point) justify-flag)
                     from (line-beginning-position 0) justify-flag)
                    ;; At least indent the line ending with `\\'.
                (setq from (point)))
            ;; ELSE part follows - loop termination relies on a fact
            ;; that (LaTeX-fill-region-as-para-do) moves point past
            ;; the filled region
            (LaTeX-fill-region-as-para-do from end-marker justify-flag)))))))
--8<---------------cut here---------------end--------------->8---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]