[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] problem with LaTeX-{current,modify}-environment
From: |
Mosè Giordano |
Subject: |
Re: [AUCTeX] problem with LaTeX-{current,modify}-environment |
Date: |
Fri, 20 Jun 2014 16:04:59 +0200 |
2014-06-19 12:06 GMT+02:00 Jaap Eldering <address@hidden>:
> 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.
For your purposes, the `save-excursion' in the "then" branch of the
`if' was more harmful than helpful, just replace it with a `progn':
--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 (or (equal (TeX-current-macro) "begin")
(looking-at "\\begin"))
;; Go to the end of the macro and get the environment name.
(progn
(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è