X-Git-Url: http://gitweb.michael.orlitzky.com/?p=emacs.d.git;a=blobdiff_plain;f=latex-query-replace-regexp-math.el;fp=latex-query-replace-regexp-math.el;h=2c486ec6c21b140f3e4fe524d7cf893bff8ebe13;hp=0000000000000000000000000000000000000000;hb=042fac64b6d145441dfd0879e44cb56ceefba482;hpb=e047f0ab8c506207665c71666b6dcb75fc5d683d diff --git a/latex-query-replace-regexp-math.el b/latex-query-replace-regexp-math.el new file mode 100644 index 0000000..2c486ec --- /dev/null +++ b/latex-query-replace-regexp-math.el @@ -0,0 +1,21 @@ +;; This is a math-mode find and replace. It relies on the AUCTeX +;; package for the "texmathp" function. +;; +;; Originally from http://stackoverflow.com/questions/19845598, +;; and modified to mention AUCTeX if it is missing. + +(fset 'latex-query-replace-regexp-math + `(lambda (regexp to-string &optional delimited start end backward) + "Like `query-replace-regexp' but only searches within math environments." + ,(interactive-form 'query-replace-regexp) + + (if (fboundp 'texmathp) + (let ((replace-re-search-function + (lambda (regexp bound noerror) + (catch :found + (while (let ((ret (re-search-forward regexp bound noerror))) + (when (save-match-data (texmathp)) (throw :found ret)) + ret)))))) + (query-replace-regexp regexp to-string delimited start end backward)) + (error "AUCTeX and latex-mode are required for this function.") + )))