Automating multiple replacements in selected text (text > HTML)
Since there doesn't appear to be a tool in IDEA to do simple HTML encoding of the selected text, I thought I'd create a macro for it. As a simplified initial test, I started macro recording, and did the following:
ctrl-R (Replace)
typed '<' in Text to find and '<' in Replace with (without the quotes)
select scope of Selected text
pressed Enter
clicked All in the confirmation dlg
repeated the above steps, replacing '>' with '>'
stopped recording
When I played that back, all that happened was that the Replace dialog opened, with Text to find as '>g' and Replace with as '>'. The text in the dlg is wrong, and the rest of the steps never happened. That makes sense, now that I read that help saying that macros have this limitation: "You cannot record such actions as button clicks, navigating to pop-up dialog boxes, and accessing tool windows or menus."
What use *are* macros then? What can you do with them that's useful?
Short of writing a plugin, is there another way to automate this simple sequence of operations?
Thanks,
Dave
Please sign in to leave a comment.
Hello Dave,
Try using the equivalent keyboard shortcuts for the whole macro:
CtrlR < AltR < AltS AltF and so on...
Thanks for the idea Chris, but no go. I did the same steps, taking care never to use the mouse, navigating between fields in the Replace dlg using alt keys. The replace dlg opened, preset to a different wrong thing, and a small pink box that appeared to be listing keystrokes maybe appeared over it. The dlg wasn't preset correctly, and none of the other steps ever ran.
It's not actually possible to preset it completely using keystrokes, since the checkbox settings are toggles, starting from the last state of the dlg. What I'd hoped was that the intended replace action got recorded, with all its option settings. The macro facility seems to be keystroke oriented, not action oriented.
So I'm stuck still.
Just out of curioisity, has anyone used macros for anything useful? Like what?
Dave
I suppose everybody who tried them stopped after realising that they are useless
try to look at some scripting plugin, for example PMIP
few lines in ruby and voila
Yeah, judging from the deafening silence on this thread, I think you're right, they're actually as useless as I thought. Too bad.
Looked for scripting plugins for languages I know well, doesn't look like anything is available. Looked at PIMP a bit, looks promising. I've only fiddled w ruby a little, and not for a while, but what I need to do is pretty simple, so I may give it a go.
Thanks,
Dave
I use them ocassionally, though you're right they certainly do have their
limits. I find them most useful for performing repetitive one-off tasks like
stripping unwanted columns from csv data etc.
Not something I do a lot, but just out of curiosity,how do you do that with just keystroke automation? I've never tried to do that in IDEA, with or without macros.
Dave
Suppose I had the following:
Blah,123,99,xyz
Testing,0,44,abc123
Hello,9999,54321,x
and I wanted to extract just the third column into a comma-delimited list
like this:
99, 44, 54321
I'd position the cursor just before the 'B', start macro recording, then
type the following:
CtrlShiftRight (4 times)
Del
Ctrl+Right (2 times)
Shift+End
Del (2 times)
Space
Then end macro recording. Now you can playback the macro as many times as
you want to chop out the unwanted columns on each line. This is just a simple
example, you can get quite a bit more creative than that.
Of course it's not nearly as fast to playback as I'd like, there's no way
to repeat playback a certain number of times or until the end of the file
is reached, and using macros within macros seems not to work(?). The feature
could certainly be improved, most simple text editors have more powerful
macro capabilities than IDEA, and indeed that's what I often end up using
for this type of work (or of course 'cut' in Linux for this particular example)
To top it all off the example above doesn't actually work on IDEA X EAP 96.1190
because it inserts some weird control characters into the macro and everything
gets messed up! To see what I'm talking about, when you've finished recording
the macro go in to Tools -> Edit Macros. There's a bunch of Typing: "[]"
entries that need to be deleted before the macro will work properly...
Chris
wow
never thought to do such things with macros
I use regular expressions
ctrl+f
enable regex checkbox
start typing regex -> and you see result highlighted immediately in editor
smth like ^.*,.*,(.*),.*$
then ctrl+r, copypaste regex into appeared replace dialog, replace it to $1
then second pass -> replace \n to ,
Hello Wi,
Sure, I realise a regex (or command line tool for that matter) would work
just fine for that particular example too, maybe I should have picked something
a bit different. I find macros come into their own when the set of keyboard
commands required to achieve the goal is what is repetitive, rather than
the actual content. When you need commands like Ctrl], CtrlW for example.
Having said that, I don't use macros very often myself either.
I also need to automate multiple replacements in selected text. Thanks to you, I tried advise to use keyboard shortcuts instead of mouse clicks. But when I use this macros, I see replace toolbar during a few milliseconds and no replacement does happen. What I am doing wrong?
Action: Replace --from Ctrl+R
Typing: "+"
Keystroke: "Tab"
Typing: "||"
Keystroke: "alt A"
Keystroke: "ESCAPE"
FWIW - I've submitted this ticket regarding this.
The tickets you submit to support on this site are visible to you only, so it doesn't make sense to share the links in the forum, others will not be able to access them anyway. If you want a public ticket, submit it at https://youtrack.jetbrains.com/issues/IDEA instead.
Thanks! Copied ticket body to https://youtrack.jetbrains.com/issue/IDEA-59382 .