19

I now use helm-ag to find all instances of the function name (searches in all files, incl. subdirs, not just in open buffers), and then I use C-c C-e to enter a buffer that lists all the matches and there I change the function name. When I am done I press C-c C-c (helm-ag--edit-commit) to store the changes to all the opened files. This might sound confusing ...


8

Install plur and run the command plur-query-replace and input {foo,bar} and its replacement {bar,foo} Hit y to replace the occurrences as desired. There are also non-interactive, and isearch-like, variants of this command.


7

Since you didn't specify the language, it's hard to give better answers than “Search and Replace”. Using wgrep If you just want to (interactively) replace all instances of a symbol with another, wgrep is your best bet. It let's you interactively edit the grep results buffer. Do M-x package-install RET wgrep. Run M-x rgrep. It will ask you a few easy ...


7

Here is a small command that will do this: (defun query-swap-strings (from-string to-string &optional delimited start end) "Swap occurrences of FROM-STRING and TO-STRING." (interactive (let ((common (query-replace-read-args (concat "Query swap" (if current-prefix-arg (if (eq current-...


5

You can give multifiles a try. From its README: Bind a key to mf/mirror-region-in-multifile, let's say C-!. Now mark a part of the buffer and press it. A new multifile buffer pops up. Mark some other part of another file, and press C-! again. This is added to the multifile. You can now edit the multifile buffer, and watch the original files change. ...


5

You can use counsel-rg followed by C-c C-o to get a list of all candidates in a buffer. Press w to edit them with wgrep. I recommend iedit for symbol renames. Press C-c C-c to commit. Dependencies: ripgrep counsel, wgrep, iedit are on MELPA


4

Python: https://github.com/python-rope/ropemacs https://github.com/jorgenschaefer/elpy (also base on rope) C++: https://github.com/tuhdo/semantic-refactor https://github.com/thoni56/c-xrefactory


4

You can use swiper Run M-x swiper-all type your regex, it will list all results, you can move with up/down to see a preview for each result. Now press M-q and it will ask you what you want to replace the matches with, type it and press enter. It will now walk you through an interactive replace, you can use y/n/! on each, y to replace, n to skip, and ! to ...


4

For some generic approaches, look under the "Replace Across Files" heading on the Emacs Wiki search & replace page: http://www.emacswiki.org/emacs/CategorySearchAndReplace Also see the answers to: Using Emacs to recursively find and replace in text files not already open.


3

Your initial steps are a good starting point. You can implement #2 using Babel Templates and sessions. Having all the source blocks run in one sessions means you can easily split them into multiple chunks with the same result. Just make sure when you split it, it is not inside a loop. That would be OK for when you tangle, but it wouldn't let you execute the ...


3

Maybe you could try to use SPC p R which runs the command projectile-replace this might not be exactly what you want (a specific js refactor tool) but it gets the job done and is language agnostic. Another more advanced option would be to search the name of that function with helm, once you are in the helm buffer C-c C-e runs helm-ag-edit, this will give ...


3

It seems like you should pass this to python, let it handle the dictionary, and get a string back. Here is basically that, although it does replace all the " with ' before passing it to python. (defun d2args () (interactive) (unless (looking-at "{") (re-search-backward "{")) (mark-sexp) (let* ((start (region-beginning)) (end (region-end)) ...


1

You can do most of it with query-replace-regexp. Replace each quote-key-quote-colon part by key-equals. Before you do the replacement, select the braced group. Before or after doing the replacement, remove the braces. This assumes that the values are not too complex. They can be non-atomic expressions, but my solution assumes that they don't contain any ...


1

One package, which might help here, is hide-show. You can call hs-hide-all, which will show you only the function definition lines plus a language-dependent abbreviation of the hidden part. You get an overview this way and can copy and paste the functions as needed with the standard commands. When you are done, you can invoke hs-show-all to return to the ...


1

There's the js2-refactor package which does many things but doesn't rename functions. Perhaps you could extend it.


1

As far as I know rope is the only option for now since redbaron is at quite an early stage and hasn't been adopted by emacs yet. But there is an awesome rope wrapper called "Traad" made by Austin Bingham, who still maintains it. Here's its homepage: https://github.com/abingham/traad. He also gave a talk in EuroPython 2014 about it: https://www.youtube.com/...


1

My version (avoids inserting into (let ...) which is not the dominating node of the variable being promoted): (defun wvxvw/promote-var-to-let (varname) (interactive (list (thing-at-point 'symbol))) (save-excursion (while (not (looking-at "(let")) (backward-up-list)) (when (looking-at "(let") (forward-word) (forward-sexp) (...


1

my 2 cents :) (defun my-let-add (var) (interactive "swhat do add? ") (save-excursion (beginning-of-defun) (search-forward "(let" nil t) (search-forward ")" nil t) (left-char) (unless (looking-back "(") (insert " ")) (insert var))) nice reference: http://...


1

Well the profound consensus appears to be "don`t do that", meaning that I'm probably not going to get an answer, and probably shouldn't do that. I guess I'm going to have to answer this myself. I think the answer for the (probably too broad for SE) meta-question of "jumping between let's, let*'s and the body of a function is irritating' is a combination of: ...


1

The noccur package makes it easier to edit multiple (not-necessarily opened) files with multi-occur. After installing, this is an example of how to do a multi-occur edit: M-x noccur-project, and provide a search regexp and directory to be searched. In the multi-occur buffer that appears, type e to switch to edit mode. Make any changes to the multi-occur ...


1

M-x project-find-regexp could help, followed by typing r in the xref buffer. It's not a "real" refactoring, but well along the lines of other answers here. Or use and LSP client, such as eglot or lsp-mode, along with a suitable LSP server such as pyls. Those offer smarter rename operations.


Only top voted, non community-wiki answers of a minimum length are eligible