]> gitweb.michael.orlitzky.com - emacs.d.git/blob - latex-query-replace-regexp-math.el
mode-hooks.el: add dns-mode hooks
[emacs.d.git] / latex-query-replace-regexp-math.el
1 ;; This is a math-mode find and replace. It relies on the AUCTeX
2 ;; package for the "texmathp" function.
3 ;;
4 ;; Originally from http://stackoverflow.com/questions/19845598,
5 ;; and modified to mention AUCTeX if it is missing.
6
7 (fset 'latex-query-replace-regexp-math
8 `(lambda (regexp to-string &optional delimited start end backward)
9 "Like `query-replace-regexp' but only searches within math environments."
10 ,(interactive-form 'query-replace-regexp)
11
12 (if (fboundp 'texmathp)
13 (let ((replace-re-search-function
14 (lambda (regexp bound noerror)
15 (catch :found
16 (while (let ((ret (re-search-forward regexp bound noerror)))
17 (when (save-match-data (texmathp)) (throw :found ret))
18 ret))))))
19 (query-replace-regexp regexp to-string delimited start end backward))
20 (error "AUCTeX and latex-mode are required for this function.")
21 )))