[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] problem with LaTeX-{current,modify}-environment
From: |
Jaap Eldering |
Subject: |
Re: [AUCTeX] problem with LaTeX-{current,modify}-environment |
Date: |
Thu, 19 Jun 2014 11:06:19 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
On 17/06/14 21:53, Mosè Giordano wrote:
> Hi Jaap,
>
> 2014-06-17 16:45 GMT+02:00 Jaap Eldering <address@hidden>:
>> Hi all,
>>
>> I'm not sure this should be considered a bug, but
>> LaTeX-current-environment and LaTeX-modify-environment seem to behave in
>> slightly non-compatible ways. I'm using the code here[1] to toggle
>> between (un)starred versions of environments. This works as expected
>> when the point is inside the \begin{...} \end{...} pairs of the
>> environment, but when the point is on one of the begin/end macros, it
>> reads the environment name from the next outer environment, but modifies
>> the inner one.
>
> I can reproduce this on the \begin macro but not on the \end one.
Indeed, I cannot reproduce it with the old code either, probably I was
not carefully checking.
> Here is an improved version of the `LaTeX-star-environment-dwim' which
> cater for the point-on-begin-macro case.
Thanks, works (almost) as advertised: only when the cursor is on the
backslash of \begin or on the final '}' of \end{...}, it still modifies
the outer environment.
I've tried to fix the first problem by adding a hacky
(or (looking-at "\\begin")
clause, but my lack of elisp knowledge seems to let me down in getting
that working.
Best,
Jaap
> --8<---------------cut here---------------start------------->8---
> (defun LaTeX-star-environment-dwim ()
> "Convert between the starred and the not starred version of the
> current environment."
> (interactive)
> (let ((current-environment
> ;; Check whether we are on the \begin macro.
> (if (equal (TeX-current-macro) "begin")
> (save-excursion
> (skip-chars-forward "^\}")
> (re-search-backward "{\\([a-zA-Z*]*\\)" nil t)
> (match-string 1))
> (LaTeX-current-environment))))
> ;; If the current environment is starred.
> (if (string-match "\*$" current-environment)
> ;; Remove the star from the current environment.
> (LaTeX-modify-environment (substring current-environment 0 -1))
> ;; Else add a star to the current environment.
> (LaTeX-modify-environment (concat current-environment "*")))))
> --8<---------------cut here---------------end--------------->8---
>
> Bye,
> Mosè
>