- emacs lisp, write command to rename xp1 xp2 to xbeg xend. the command should fix current defun
(defun xah-rename-elisp-var ()
"Rename variables xp1 xp2 to xbeg xend, in current defun.
if var name xbeg already exist, it's renamed to xbeg888.
if var name xend already exist, it's renamed to xend888.
Created: 2024-08-30
Version: 2024-08-30"
(interactive)
(let ((case-fold-search nil)
(xbeg-new "xbeg888")
(xend-new "xend888"))
(save-restriction
(narrow-to-defun)
(progn
(goto-char (point-min))
(while (re-search-forward "\\_<xbeg\\_>" nil t)
(replace-match xbeg-new t t))
(goto-char (point-min))
(while (re-search-forward "\\_<xp1\\_>" nil t)
(replace-match "xbeg" t t)))
(progn
(goto-char (point-min))
(while (re-search-forward "\\_<xend\\_>" nil t)
(replace-match xend-new t t))
(goto-char (point-min))
(while (re-search-forward "\\_<xp2\\_>" nil t)
(replace-match "xend" t t))))))