From 042fac64b6d145441dfd0879e44cb56ceefba482 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 18 Dec 2016 00:54:32 -0500 Subject: [PATCH] Add the latex-query-replace-regexp-math library. --- .emacs | 16 +++++++++++++++- latex-query-replace-regexp-math.el | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 latex-query-replace-regexp-math.el diff --git a/.emacs b/.emacs index b990474..5e9a7a0 100644 --- a/.emacs +++ b/.emacs @@ -76,6 +76,7 @@ (global-set-key "\C-cd" 'diff-buffer-against-file) (load-library "fix-nonstandard-chars") +(load-library "latex-query-replace-regexp-math") ;; Enable dired-find-alternate-file without having to stop @@ -88,4 +89,17 @@ ;; Show trailing whitespace, without having to drop into ;; whitespace-mode. -(custom-set-variables '(show-trailing-whitespace t)) +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(auth-source-save-behavior nil) + '(show-trailing-whitespace t)) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) + 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.") + ))) -- 2.44.2