Hi Arash, thanks for your comment. >>>>> Arash Esbati writes: > Thank you for looking into this. The way I understand this regexp: > "\\([^ \r\n%\\]\\|\\\\%\\)\\([ \t]\\|\\\\\\\\\\)*" > ^^^^^^^ > is there to exclude the control symbol \%, i.e., being parsed as comment > start. I think so, too. Tassilo added it to fix bug#48937 this June. > Would it help if we generlize the control symbol idea by saying: > "\\([^ \r\n%\\]\\|\\\\[^a-zA-Z0-9\\]\\)\\([ \t]\\|\\\\\\\\\\)*" > ^^^^^^^^^^^^^^ I'm afraid that it doesn't match a line \\% This is a code comment. , either. Try typing M-q on the following paragraph in latex mode buffer: ---------------------------------------------------------------------- Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt et, \\% This is a code comment. mattis eget, convallis nec, purus. ---------------------------------------------------------------------- >> Maybe we should give up regexp-based approach to find out code comments >> accurately. > Are you thinking about `syntax-ppss'? No, other parts of latex.el ideintify code comments by a different logic like: ;; A line with some code, followed by a comment? ((and (setq code-comment-start (save-excursion (beginning-of-line) (TeX-search-forward-comment-start (line-end-position)))) (> (point) code-comment-start) (not (TeX-in-commented-line)) (save-excursion (goto-char code-comment-start) ;; See if there is at least one non-whitespace character ;; before the comment starts. (re-search-backward "[^ \t\n]" (line-beginning-position) t))) So it would be better to follow this logic than to rely on regexp. In addition, regexp-based approach is easily fooled by percent sign in \verb, while `TeX-search-forward-comment-start' (which in turn calls `LaTeX-search-forward-comment-start') takes care of such cases. I ended up with the attached tentative patch. I hope this doesn't slow down the filling loop significantly. What do you think about it? Regards, Ikumi Keita