-
Notifications
You must be signed in to change notification settings - Fork 43
Home
Welcome to the iedit wiki!
I have a piece of code combining cscope, gtags, occur, iedit to rename symbol accoss multiple files. It is quite handy.
(require 'xcscope)
(defun vr-occur-from-cscope ()
"Start occur form cscope buffer."
(interactive)
(with-current-buffer cscope-output-buffer-name
(let (files
bufs
(symbol (cadr cscope-previous-user-search)))
(save-excursion
(if (>= emacs-major-version 27)
(while (setq match (text-property-search-forward 'cscope-file nil nil))
(add-to-list 'files (prop-match-value match)))
(let ((pos (point))
file)
(while (and pos (< pos (point-max)))
(setq file (get-text-property pos 'cscope-file))
(when file (add-to-list 'files file))
(setq pos (next-single-property-change pos 'cscope-file))))))
(or files (error "No file matched"))
(dolist (file files bufs)
(push (find-file-noselect file) bufs))
(quit-window)
(occur-1 symbol nil bufs "*refactor*")
(select-window (get-buffer-window "*refactor*"))
(occur-edit-mode)
(occur-next)
(iedit-mode)
)))
(define-key cscope-list-entry-keymap ";" 'vr-occur-from-cscope)
(defun vr-cscope-sentinel-advice (process event)
"docstring"
(vr-occur-from-cscope)
(advice-remove 'cscope-process-sentinel #'vr-cscope-sentinel-advice))
(defun vr-rename-refactor (&optional arg)
"Rename the symbol at the point."
(interactive "P")
(let ((symbol
(if (and mark-active
(not (equal (mark) (point))))
(buffer-substring-no-properties
(mark) (point))
(thing-at-point 'symbol))))
(advice-add 'cscope-process-sentinel :after #'vr-cscope-sentinel-advice)
(cscope-find-this-symbol symbol)
))
(define-key global-map (kbd "C-c C-;") 'vr-rename-refactor)
gyst commented (This is a problem of Emacs 25.1 ~ 26.1. It is fixed in Emacs 26.2.)
Update: this workaround is nice for me, perhaps useful for somebody else. In my .emacs:
(add-hook ‘iedit-mode-hook (lambda () (diff-hl-mode -1)))
(add-hook ‘iedit-mode-end-hook (lambda () (diff-hl-mode +1)))
TLINDEN commented on Nov 9, 2016
As far as I understand the docs and source, there’s no such feature yet, I wrote the following work-around:
;; Keep buffer-undo-list as is while iedit is active, that is, as long
;; as I am inside iedit I can undo/redo current occurences. However,
;; if I leave iedit and issue the undo command, ALL changes made with
;; iedit are undone, whereas the default behaviour would be to go
;; through every change made iside iedit, which I hate.
;; iedit doesn’t provide a customizable flag to configure it’s undo
;; behavior, so, I modify it myself using defadvice.
(setq my-buffer-undo-list nil)
(advice-add ‘iedit-mode :before ‘(lambda (&rest args) ;; save current
(setq my-buffer-undo-list buffer-undo-list)))
(advice-add ‘iedit-mode :after ‘(lambda (&rest args) ;; restore previously saved
(setq buffer-undo-list my-buffer-undo-list)))
Maybe this is of use for others, therefore I’m posting it here.