[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX] A bug to add a pair of braces and more?
From: |
Ralf Angeli |
Subject: |
Re: [AUCTeX] A bug to add a pair of braces and more? |
Date: |
Wed, 01 Nov 2006 17:08:09 +0100 |
* Adam Johnson (2006-11-01) writes:
> When I first select a region like "abc" forward from 'a' to 'c', and then
> use C-c C-{, a pair of {} was added around "abc" so it becomes "{abc}". If
> I select the same region backwards from 'c' to 'a', the same operation
> produces something like "}abc{", which, in general, is meaningless.
This has been fixed in CVS for quite some time.
> Just a thought, can you please produce any operation to delete a pair of
> braces, that is to change "{blabla}" to "blabla"? In general, an extra pair
> of "{}" will not affect anything, but I'd like to keep my document as neat
> as possible. (that is, without extra things like this in the document.)
How about the following function?
(defun TeX-remove-braces ()
"Remove a pair of braces.
Braces are only removed if point is between a matching pair of
them. The function does nothing if this is not the case."
(interactive)
(let ((opening-brace (TeX-find-opening-brace))
(closing-brace (TeX-find-closing-brace)))
(when (and opening-brace closing-brace)
(delete-region (1- closing-brace) closing-brace)
(delete-region opening-brace (1+ opening-brace)))))
I should probably write a function which returns both the opening and
the closing brace in one go.
And here is something if you want to remove a whole macro:
(defun TeX-remove-macro ()
"Remove a single-argument TeX macro leaving its argument untouched."
(interactive)
(let ((macro-start (TeX-find-macro-start))
(macro-end (TeX-find-macro-end))
opening-brace)
(when (and macro-start macro-end)
(save-excursion
(goto-char (1- macro-end))
(setq opening-brace (TeX-find-opening-brace)))
(delete-region (1- macro-end) macro-end)
(delete-region macro-start (1+ opening-brace)))))
--
Ralf