I have the following function that removes the LaTeX command surrounding the current cursor position:
(defun remove-tex-cmd () (interactive) (save-excursion (let (cur-point beg-point end-point) (setq cur-point (point)) (catch 'notexcmd (if (not (re-search-backward "\\.*?{" nil t)) ; now the point is at the { (throw 'notexcmd nil)) (search-backward "\\" nil t) (setq beg-point (point)) (re-search-forward "}") (setq end-point (point)) (if (> end-point cur-point) (kill-region beg-point end-point)) (throw 'notexcmd nil))) (if 'notexcmd (message "no tex command at point"))))
It works well, except in the following situation, because it just matches the following closure } :
\test{a<cursor here>sdf ${bla}+1$}
leads to
+1$}
I could, of course, count the opening and closing brackets. However, since this problem often arises, I wonder if there is an even more intelligent search function, or am I missing a completely different point?
source share