【发布时间】:2009-06-29 09:04:34
【问题描述】:
我有以下函数可以删除当前光标位置周围的 LaTeX 命令:
(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"))))
除了以下情况,它运行良好,因为它只是匹配下一个关闭}:
\test{a<cursor here>sdf ${bla}+1$}
结果
+1$}
当然,我可以计算左括号和右括号。不过这个问题应该经常出现,不知道有没有更智能的搜索功能,还是我漏掉了一个完全不同的点?
【问题讨论】: