diff --git a/latex.el b/latex.el index 05238344..1b4346f6 100644 --- a/latex.el +++ b/latex.el @@ -4004,7 +4004,8 @@ 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)))) + (let ((end-marker (save-excursion (goto-char to) (point-marker))) + has-code-comment) (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 @@ -4019,12 +4020,24 @@ performed in that case." (save-restriction (goto-char from) (while (< (point) end-marker) - (if (re-search-forward + (if (or + ;; Code comments. + (when (setq has-code-comment + (TeX-search-forward-comment-start end-marker)) + (goto-char has-code-comment) + (when + ;; See if there is at least one non-whitespace + ;; character before the comment starts. + (save-excursion + (skip-chars-backward " \t" (line-beginning-position)) + (bolp)) + ;; Not a code comment. Go back to the former + ;; point. + (setq has-code-comment nil) + (goto-char from)) + has-code-comment) + (re-search-forward (concat "\\(" - ;; Code comments. - "\\([^ \r\n%\\]\\|\\\\%\\)\\([ \t]\\|\\\\\\\\\\)*" - TeX-comment-start-regexp - "\\|" ;; Lines ending with `\par'. "\\(\\=\\|[^" TeX-esc "\n]\\)\\(" (regexp-quote (concat TeX-esc TeX-esc)) @@ -4038,7 +4051,7 @@ performed in that case." "\\(\\s-*\\*\\)?" "\\(\\s-*\\[[^]]*\\]\\)?" "\\s-*$\\)") - end-marker t) + end-marker t)) (progn (goto-char (line-end-position)) (delete-horizontal-space) @@ -4052,7 +4065,8 @@ performed in that case." ;; Code comments and lines ending with `\par' are ;; included in filling. Lines ending with `\\' are ;; skipped. - (if (match-string 1) + (if (or has-code-comment + (match-beginning 1)) (LaTeX-fill-region-as-para-do from (point) justify-flag) (LaTeX-fill-region-as-para-do from (line-beginning-position 0) justify-flag)