diff --git a/latex.el b/latex.el index 05238344..97bada66 100644 --- a/latex.el +++ b/latex.el @@ -4019,12 +4019,24 @@ performed in that case." (save-restriction (goto-char from) (while (< (point) end-marker) - (if (re-search-forward + (if (or + ;; Code comments. + (let ((p (point))) + (when (TeX-search-forward-comment-start end-marker) + (goto-char (match-beginning 0)) + ;; Pretend as if there were no match to tell later + ;; code that there is a code comment. + (set-match-data nil) + ;; See if there is at least one non-whitespace + ;; character before the comment starts. + (or (save-excursion + (skip-chars-backward " \t" (line-beginning-position)) + (not (bolp))) + (progn + (goto-char p) + nil)))) + (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 +4050,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 +4064,7 @@ 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 (not (match-beginning 0)) ; code comment (LaTeX-fill-region-as-para-do from (point) justify-flag) (LaTeX-fill-region-as-para-do from (line-beginning-position 0) justify-flag)