[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fill breaks verbatim macros not followed with spaces
From: |
Arash Esbati |
Subject: |
Re: fill breaks verbatim macros not followed with spaces |
Date: |
Tue, 05 Jul 2022 11:31:26 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 |
Hi Keita,
Ikumi Keita <ikumi@ikumi.que.jp> writes:
>>>>>> Arash Esbati <arash@gnu.org> writes:
>>
>> ltxdoc.el adds '|' to `LaTeX-shortvrb-chars' but fontification of \verb
>> macro and verbatim-environment doesn't work with docTeX. I think your
>> proposal doesn't work there for the same reason. Maybe we can try to
>> address this issue as well.
>
> I have an impression that it would be a tough task. One possible
> approach is to make % at BOL lose comment syntax by syntax
> propertization, but I'm not sure how much adjustment would be needed to
> make it consistent with all other components of AUCTeX.
I agree, this is sort of complicated. We don't have to fix it right
away, we can put it on the ToDo list.
>> And while we're at it, I think there is also a bug in docTeX-mode which
>> indents verbatim environments like this:
>
>> % \begin{verbatim}
>> % foobar
>> % \end{verbatim}
>
>> Note the spaces inserted, most notably before the content which means
>> that it will be inserted in the final product. I will see if adding it
>> to `docTeX-indent-inner-fixed' fixes the issue.
>
> OK.
This isn't as easy as I thought either. Adding verbatim to
`docTeX-indent-inner-fixed' is only half of the fun. We have to change
`LaTeX-indent-line' to calculate `fill-prefix' correctly as well. The
following change should do the trick:
--8<---------------cut here---------------start------------->8---
diff --git a/latex.el b/latex.el
index ac4b0c54..09f557d5 100644
--- a/latex.el
+++ b/latex.el
@@ -3909,7 +3909,10 @@ value."
4 t)
(,(concat (regexp-quote TeX-esc)
"\\(begin\\|end\\)[ \t]*{\\(macro\\|environment\\)\\*?}")
- 0 nil))
+ 0 nil)
+ (,(concat (regexp-quote TeX-esc)
+ "\\(begin\\|end\\)[ \t]*{verbatim\\*?}")
+ 0 t))
"List of items which should have a fixed inner indentation.
The items consist of three parts. The first is a regular
expression which should match the respective string. The second
@@ -4038,7 +4041,19 @@ Lines starting with an item is given an extra
indentation of
(beginning-of-line)
(looking-at
(concat "\\([ \t]*" TeX-comment-start-regexp "+\\)+"))
- (concat (match-string 0) (TeX-comment-padding-string))))))
+ ;; We don't want to insert a '% ' in a verbatim
+ ;; environment when in `doctex-mode', hence we set
+ ;; `comment-padding' to an empty string in such a
+ ;; case before running `TeX-comment-padding-string'
+ ;; and set a correct `fill-prefix':
+ (concat (match-string 0)
+ (if (and (eq major-mode 'doctex-mode)
+ (TeX-in-line-comment)
+ (member (LaTeX-current-environment)
+ (LaTeX-verbatim-environments)))
+ (let ((comment-padding ""))
+ (TeX-comment-padding-string))
+ (TeX-comment-padding-string)))))))
(save-excursion
(cond ((and fill-prefix
(TeX-in-line-comment)
@@ -4056,16 +4071,16 @@ Lines starting with an item is given an extra
indentation of
(let ((inner-indent (LaTeX-indent-calculate 'inner))
(outer-indent (LaTeX-indent-calculate 'outer)))
(when (/= (LaTeX-current-indentation 'inner) inner-indent)
- (LaTeX-indent-inner-do inner-indent))
+ (LaTeX-indent-inner-do inner-indent))
(when (/= (LaTeX-current-indentation 'outer) outer-indent)
- (LaTeX-indent-outer-do outer-indent))))
+ (LaTeX-indent-outer-do outer-indent))))
(t
;; The default is to adapt whitespace before any
;; non-whitespace character, i.e. to do outer
;; indentation.
(let ((outer-indent (LaTeX-indent-calculate 'outer)))
(when (/= (LaTeX-current-indentation 'outer) outer-indent)
- (LaTeX-indent-outer-do outer-indent))))))
+ (LaTeX-indent-outer-do outer-indent))))))
(when (< (current-column) (save-excursion
(LaTeX-back-to-indentation) (current-column)))
(LaTeX-back-to-indentation))))
--8<---------------cut here---------------end--------------->8---
The only thing remaining is how to suppress the actual indenting in this
part of the `LaTeX-indent-line':
--8<---------------cut here---------------start------------->8---
(save-excursion
(cond ((and fill-prefix
(TeX-in-line-comment)
(eq major-mode 'doctex-mode))
;; If point is in a line comment in `doctex-mode' we only
;; consider the inner indentation.
(let ((inner-indent (LaTeX-indent-calculate 'inner)))
(when (/= (LaTeX-current-indentation 'inner) inner-indent)
(LaTeX-indent-inner-do inner-indent))))
--8<---------------cut here---------------end--------------->8---
Best, Arash