Skip to content

Instantly share code, notes, and snippets.

@myuhe
Created February 9, 2010 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myuhe/299199 to your computer and use it in GitHub Desktop.
Save myuhe/299199 to your computer and use it in GitHub Desktop.
(defun iedit-mode ()
"Toggle iedit mode.
If iedit mode is off, turn iedit mode on using active region as
input, off otherwise.
In iedit mode, all the occurrences of the input region are
highlighted. If one occurrence is modified, the change are
propagated to all other occurrences simultaneously.
If the region is not active, the `current-word' is used as
input. All the occurrences of the `current-word' are highlighted.
You can also switch to iedit mode from isearch mode directly.
All occurrences of isearch-string are highlighted.
Commands:
\\{iedit-mode-map}"
;;(interactive "r")
(interactive)
(if iedit-mode
(iedit-done)
(let ((occurrence nil))
(cond
((and mark-active (not (equal (region-beginning) (region-end))))
(setq occurrence (buffer-substring (region-beginning) (region-end))))
((and isearch-mode (not (string= isearch-string "")))
(setq occurrence isearch-string)
(isearch-exit))
((and iedit-symbol-at-point (current-word t))
(setq occurrence (current-word)))
(t (error "No region selected, cannot enable iedit mode.")))
(deactivate-mark)
(iedit-start occurrence))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment