Skip to content

Instantly share code, notes, and snippets.

@tam17aki
Last active December 21, 2015 23:08
Show Gist options
  • Save tam17aki/6379652 to your computer and use it in GitHub Desktop.
Save tam17aki/6379652 to your computer and use it in GitHub Desktop.
(defun iedit-dwim-get-string ()
(cond ((iedit-region-active)
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(buffer-substring-no-properties
(region-beginning) (region-end)))
(t
(current-word))))
(defun iedit-dwim (arg)
"Starts iedit but uses \\[narrow-to-defun] to limit its scope."
(interactive "P")
(if arg
(iedit-mode)
(save-excursion
(save-restriction
(widen)
(cond (iedit-mode
(iedit-done))
(t
(narrow-to-defun)
(if (eq (count-lines (point-min) (point-max)) 1)
(widen))
(iedit-start (iedit-dwim-get-string) (point-min) (point-max))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment