Can IntelliJ IDEA automatically format a code block after finishing it? - intellij-idea

Some IDEs offer the feature to automatically format a line or block of code after finishing it e.g. by writing the closing curly or semicolon.
I find it hard to believe that IDEA does not offer this kind of feature. Or does it?
If you know how to turn it on - or if I maybe need some plugin - let me and the world know, please!

If it's a single line, you can use the Complete Current Statement action (which adds a closing bracket, semi-colon, and so on) with ctrl-shift-enter - this seems to reformat the whole line.
Otherwise, you can obviously rebind ctrl-w and ctrl-alt-l (to reformat selected text) or just ctrl-alt-l (reformat whole file) to faster / easier keybindings so that you can quickly reformat whenever you want to.

There is no automatic reformat feature, related requests:
IDEABKL-5806 Automatically trigger code formatter on file save
IDEABKL-475 Hard (auto-)reformat code
See also my answer to the similar question with the Complete Current Statement workaround.

Related

Intellij Plugin Completion exits on dot?

What I wanna achieve?
When the Completion list shows up, my code will map all the language files located in .neon files and show them as auto complete text.
What I have done?
I restricted the completion to only show up when your caret is in between double quotes or single quotes
Issue
When I start typing it works as expected
But as soon as I type the dot character it miss behaves
I need the completion list to look up my whole string I wrote, not only those after the dot character
As a really bad workaround is to don't write the dot character
Can it be done somehow?
Okay, i got it. This is a default behavior of intelliJ where i was testing it.
After opening and testing the plugin in a proper intelliJ Ultimate instance. It works by default. I don't know why the sandboxed version has porblems with it.

How to stop IntelliJ from placing semicolons after an auto-completion?

so this is annoying me because I use tab to leave brackets etc and when I use auto-complete and a semicolon is being placed after the bracket this happens:
https://streamable.com/i9as2
as you can see in the first statement I'm having problems "jumping" over the semicolon while when I dont use the auto-completion in the second statement (and don't get the semicolon automatically) it's way easier to navigate through it with tab. I know that there is the shift-enter shortcut but I don't really want to develop a habbit of using it so often because I can imagine trying to do that when working with my other IDE's can become quite annoying. I searched through the options but did not find any option do disable that behavior. Does anyone know a way to get around this?
Second Tab press should jump after the semicolon, I've created a feature request for that.
It's already fixed and the fix will be available starting from 2019.2 IDE version.

Is there an IntelliJ IDEA action that select a word if there is no selection but stay unchanged if there is?

I want to write a macro that if there is no selection it automatically operates on the current word, otherwise it operates on the selection. However I cannot find a suitable action, EditorSelectWord keeps on expanding the selection forever.
p.s. The macro is meant to change "xyz" to "{#code xyz}", but it also needs to change "x/y/z" to "{#code x/y/z}".
IntelliJ IDEA does not appear to be the best tool for this specific job. It looks like macros only support a fixed list of steps that will always be executed, without the possibility for if statements: https://www.jetbrains.com/idea/help/using-macros-in-the-editor.html.
You could use Ctrl-W manually when there is no selection, but it would of course be much nicer if the macro could handle it. Another possibility is to use a tool like the stream editor sed. The substitution command of sed might be usable in your case, unless the text occurs in places where you do not want to substitute it:
sed 's/xyz/{#code xyz}/g' inputFileName > outputFileName
It might also be a great reason to write a small program of your own that for example modifies only specific strings in Javadocs in your source files.

Set breakpoint in VBA code programmatically

I have a very large piece of code written in VBA (>50,000 lines - numerous modules). There is one array of interest to me, and I'd like to find all the conditions under which the value of any element of this array changes. The values can change in any module. Running the script line by line is not the most efficient option due to the size of the code.
I am looking for better ways to solve this problem. Two ways that come to my mind is to programmatically set a breakpoint (which I am not sure if can be done) or programmatically insert an if-block after each assignment that somehow alerts me that the value has changed. (not preferred).
So my question boils down to:
Is it possible to programmatically set breakpoints in VBA code?
If the answer to the above question is No, what is an efficient way to solve this problem?
UPDATE:
Thanks for the comments/replies. As I had implied, I am interested in the least amount of modification to the current code (i.e. inserting if-blocks, etc) and most interested in the break-point idea. I'd like to know if it's doable.
Use the keyword STOP to break te code if a certain condition is true.
There are Two Ways to do that:
Use Stop Key word. Example as given below, set a break point at Stop
if (x = 21 ) Then
Stop
End If
Using Add Watch
Go to Debug -> Select Add Watch
NB:I know this is an old topic but this could help others.
You could use Watches:
Right click on the variables you wish to monitor -> Add Watch...
In Watch Type: 'Break when value changes'
While you run your code, you can check the status of your Watches thanks to the Watch Window (accessible from the 'View' menu)
in the hope someone can benefit from this :
In such situations regardless of the programming language used - writing a few lines of code either in Perl, AWK or even shell scripts can solve the problem :
search for a regular expression containing the array name (ignoring case).
Once you export all modules and classes in the Workbook(s) into a given directory - the scripts can search those for you.

Saving a position while coding?

Back in olden times, I used to code with an editor that allowed you to mark where you were in the code with a keypress. You could jump to another point in the same or another file to check a reference or somesuch. When you were ready, you could hit another keypress and return to the point you saved.
I've long since migrated to Dreamweaver and wanted this functionality. Does it exist in DW? If so, I missed that part of the manual. If not, any suggestions on an editor that DOES have that functionality?
Scott.
There is no official way to do it, but you could use the code collapse feature to create something like a bookmark. Collapse the single line and DW will have a mark at that line number until you clear it.