This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-29
Channels
- # aws (2)
- # babashka (2)
- # beginners (86)
- # calva (1)
- # cider (17)
- # clojure (46)
- # clojure-conj (1)
- # clojure-nl (1)
- # clojure-uk (6)
- # clojurescript (8)
- # clojutre (2)
- # cursive (3)
- # data-science (1)
- # datascript (5)
- # datomic (1)
- # fulcro (9)
- # funcool (5)
- # jackdaw (1)
- # leiningen (6)
- # pathom (2)
- # re-frame (2)
- # rewrite-clj (2)
- # shadow-cljs (19)
- # spacemacs (12)
- # sql (2)
- # vim (26)
I assume the best way to rename a function/defn is using clj refactors change symbol name. Are there other ways? The podcast mentions iedit, that's a text based replacement right?
@drewverlee
Yes, you can use iedit to rename multiple instances of text in a buffer.
In Evil normal mode, if the cursor is on a symbol name, like a function name, def or let binding, then pressing *
or ‘#’ will highlight all instances and show the symbol transient menu. Pressing e
will take you into iedit mode (turning the cursor red). Or you can just use /
to search
You can then edit the highlighted text as normal and all other instances change at the same time.
Use narrowing before selecting / searching to be more selective in what text is show and therefore highlighted and changed. E.g. if you just want to change a specific function or range of text.
If you want to change text throughout a project, then press *
or ‘#’ to show the symbol transient menu. Use project search by selecting /
which will display all matches throughout the project.
C-z
will give you a list of actions you can perform on the results of the project search
F4
will open the results in a new buffer for editing.
Now we can use iedit again, SPC s e
, on any text we select in the project search results. Or simply manually edit the file (or even use multiple cursors).
C-c C-c
will commit the changes you have made, updating the changes throughout all the relevant files in the project.
Interesting, so you can use SPC *
instead of *
and then /
to open the project search on that symbol. Thanks.
thanks!. Right now i seem better at using projectile-replace. But ill look more into iedit.
SPC p R
for projectile-replace looks very handy, especially when its a simple case of replacing one name with a new one. Using helm-ag and iedit has a few more steps but can manage more complicated replacements, but most of the time replace should be just fine.
@drewverlee I can only recommend updating to recent develop
and using clj-kondo.
I have spacemacs develop installed and cider-version
says
CIDER 0.18.1snapshot (package: 20180923.1759)
but in the cider github project page I see that the melpa stable version is 0.22.1. is that normal? for example, I don't seem to have cider-clojuredocs
even though it's bound to ,hd
in spacemacs
@drewverlee
Yes, you can use iedit to rename multiple instances of text in a buffer.
In Evil normal mode, if the cursor is on a symbol name, like a function name, def or let binding, then pressing *
or ‘#’ will highlight all instances and show the symbol transient menu. Pressing e
will take you into iedit mode (turning the cursor red). Or you can just use /
to search
You can then edit the highlighted text as normal and all other instances change at the same time.
Use narrowing before selecting / searching to be more selective in what text is show and therefore highlighted and changed. E.g. if you just want to change a specific function or range of text.
If you want to change text throughout a project, then press *
or ‘#’ to show the symbol transient menu. Use project search by selecting /
which will display all matches throughout the project.
C-z
will give you a list of actions you can perform on the results of the project search
F4
will open the results in a new buffer for editing.
Now we can use iedit again, SPC s e
, on any text we select in the project search results. Or simply manually edit the file (or even use multiple cursors).
C-c C-c
will commit the changes you have made, updating the changes throughout all the relevant files in the project.
The symbol highlight transient state is a really useful menu for finding names of things https://practicalli.github.io/spacemacs/navigating-code/names-symbols.html
Interesting, I just noticed if you did TAB
on a function name it lists all the matching functions.
For example, i pressed TAB
when the cursor was on reduce
and a helm popup appeared listing a search of all matching functions in Clojure core. That's nice.
Ah, if you select one of the alternative functions listed in the helm popup it replaces it for you (just at the cursor though)