Skip to content

Instantly share code, notes, and snippets.

@smikes
Created February 16, 2014 11:42
Show Gist options
  • Save smikes/9032917 to your computer and use it in GitHub Desktop.
Save smikes/9032917 to your computer and use it in GitHub Desktop.
Replace all occurrences of regexp in file, preserving location of point
(defun global-replace-regexp (regexp to-string &optional delimited start end)
""
(interactive
(let ((common
(query-replace-read-args
(concat "Replace"
(if current-prefix-arg " word" "")
" regexp"
(if (and transient-mark-mode mark-active) " in region" ""))
t)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(point-min) (point-max))))
(save-excursion
(perform-replace regexp to-string nil t delimited nil nil start end)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment