How to replace parts of a line with search/replace in Intellij? - intellij-idea

I am trying to find all cases of println and replace them with log.debug() for starters, then clean up the logs. Is there a tool somewhere than can help me do that? Is this even possible? We are trying to replace both the beginning of a line with log.debug( AND the end of it, with the ).
We are on:
Groovy 2.5.11
Java 1.8
IntelliJ IDEA 2020.2.1 (Ultimate Edition) Build #IU-202.6948.69
Windows OS
Example:
//find all instances of (text in logs is varied)
println "this is a log"
//and replace with
log.debug("this is a log")

Search pattern: println "(.*?)"
Replace pattern: log.debug("$1")
Notice the regex search option is enabled (.* icon on the right).
More details in IntelliJ IDEA documentation.

Related

Enable Suggestions after dot (.) operator?

How do I enable suggestions after dot operator in Intellij 14?
For eg., If I have the following code,
String s = "hello"; --> line 1
s. ---> line 2
In line 2, If I enter . after the variable 's', the suggestions like variables and methods in class String is not shown in suggestions. How can I enable it in Intellij 14?
P.S : Java class path is set correctly and compilation happens properly. Just the development is screwing me up without showing suggestions.
From IntelliJ, try Help > Find Action..., and then type 'code completion'. Make sure the feature is enabled in Settings.

Clojure lein-environ plugin classpath error

I am using InteliJ IDEA to develop my application which was working as expected until I added the [lein-environ "1.0.1"] plugin to my project.clj.
If I run my application using lein it all runs as expected however, if I launch a debug repl (need to test the logic etc) then I get the following error:
Could not locate lein_environ/plugin__init.class or lein_environ/plugin.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
My 'project.clj' contents:
defproject some-project "1.0.0"
:description "Some random description"
:license {:name "FILLER DATA"}
:dependencies [[org.clojure/clojure "1.7.0"]
[environ "1.0.1"]
[stencil "0.5.0"]
[clj-http "2.0.0"]
[clj-ssh "0.5.11"]
[cheshire "5.5.0"]
[clj-time "0.11.0"]
[amazonica "0.3.33"]
[expectations "2.0.9"]
[im.chit/cronj "1.4.1"]
[dk.ative/docjure "1.9.0"]
[com.draines/postal "1.11.3"]
[org.clojure/data.csv "0.1.3"]
[org.clojure/java.jdbc "0.4.1"]
[...]]
:plugins [[lein-environ "1.0.1"]
[lein-expectations "0.0.8"]]
:resource-paths ["resources" "jobs"]
:profiles {:repl {:env {:in-repl? true}}}
:main source-file.core)
If I remove the [lein-environ "1.0.1"] from the plugins the debug repl launches and functions as expected however, I need the plugin to be able to generate the .lein-env from my profiles.clj
Any idea what is causing this issue? I have tried removing environ from ~/.m2/path/to/lein-environ but no luck.
This was a bug in a recent version of Cursive. If you upgrade it should be fixed.

Can FlyCheck be used with Komodo(for Django) for checking syntax on the fly?

I want to use Komodo IDE for building one Django project.I want to use flycheck syntax checker so that it indicates the syntax errors on the fly.If fly-check cannot be integrated with Komodo,is there any other possibility to syntax checking on the fly?
Use the following process:
Goto Toolbox=>Add=>New Command
Enter the emacs command line arguments in the Run field:
emacs eval('(progn
(flycheck-declare-checker go-gofmt
"A Go syntax and style checker using the gofmt utility."
:command '("gofmt" source-inplace)
:error-patterns '(("^\\(?1:.*\\):\\(?2:[0-9]+\\):\\(?3:[0-9]+\\): \\(?4:.*\\)$" error))
:modes 'go-mode)
(add-to-list 'flycheck-checkers 'go-gofmt)))
Check all the boxes
Enter the path to emacs in the Start In field
Click the Key Binding tab
Use Ctrl+0 as the New Key Sequence
Press Ctrl+A,Ctrl+0
References
Komodo Documentation: Run Commands
Emacs Wiki: Flycheck

How to auto-indent code in the Atom editor?

How do you auto-indent your code in the Atom editor? In other editors you can usually select some code and auto-indent it.
Is there a keyboard shortcut as well?
I found the option in the menu, under Edit > Lines > Auto Indent. It doesn't seem to have a default keymap bound.
You could try to add a key mapping (Atom > Open Your Keymap [on Windows: File > Settings > Keybindings > "your keymap file"]) like this one:
'atom-text-editor':
'cmd-alt-l': 'editor:auto-indent'
It worked for me :)
For Windows:
'atom-text-editor':
'ctrl-alt-l': 'editor:auto-indent'
The accepted answer works, but you have to do a "Select All" first -- every time -- and I'm way too lazy for that.
And it turns out, it's not super trivial -- I figured I'd post this here in an attempt to save like-minded individuals the 30 minutes it takes to track all this down. -- Also note: this approach restores the original selection when it's done (and it happens so fast, you don't even notice the selection was ever changed).
1.) First, add a custom command to your init script (File->Open Your Init Script, then paste this at the bottom):
atom.commands.add 'atom-text-editor', 'custom:reformat', ->
editor = atom.workspace.getActiveTextEditor();
oldRanges = editor.getSelectedBufferRanges();
editor.selectAll();
atom.commands.dispatch(atom.views.getView(editor), 'editor:auto-indent')
editor.setSelectedBufferRanges(oldRanges);
2.) Bind "custom:reformat" to a key (File->Open Your Keymap, then paste this at the bottom):
'atom-text-editor':
'ctrl-alt-d': 'custom:reformat'
3.) Restart Atom (the init.coffee script only runs when atom is first launched).
Package auto-indent exists to apply auto-indent to entire file with this shortcuts :
ctrl+shift+i
or
cmd+shift+i
Package url : https://atom.io/packages/auto-indent
I prefer using atom-beautify, CTRL+ALT+B (in linux, may be in windows also) handles better al kind of formats and it is also customizable per file format.
more details here: https://atom.io/packages/atom-beautify
You can just quickly open up the command palette and do it there
Cmd + Shift + p and search for Editor: Auto Indent:
This works for me:
'atom-workspace atom-text-editor':
'ctrl-alt-a': 'editor:auto-indent'
You have to select all with ctrl-a first.
This is the best help that I found:
https://atom.io/packages/atom-beautify
This package can be installed in Atom and then CTRL+ALT+B solve the problem.
On Linux
(tested in Ununtu KDE)
There is the option in the menu, under Edit > Lines > Auto Indent or press Cmd + Shift + p, search for Editor: Auto Indent by entering just "ai"
Note: In KDE ctrl-alt-l is already globally set for "lock screen" so better use ctrl-alt-i instead.
You can add a key mapping in Atom:
Cmd + Shift + p, search for "Settings View: Show Keybindings"
click on "your keymap file"
Add a section there like this one:
'atom-text-editor':
'ctrl-alt-i': 'editor:auto-indent'
If the indention is not working, it can be a reason, that the file-ending is not recognized by Atom. Add the support for your language then, for example for "Lua" install the package "language-lua".
If a File is not recognized for your language:
open the ~/.atom/config.cson file (by CTRL+SHIFT+p: type ``open config'')
add/edit a customFileTypes section under core for example like the following:
core:
customFileTypes:
"source.lua": [
"conf"
]
"text.html.php": [
"thtml"
]
(You find the languages scope names ("source.lua", "text.html.php"...) in the language package settings see here)
If you have troubles with hotkeys, try to open Key Binding Resolver Window with Cmd + .. It will show you keys you're pressing in the realtime.
For example, Cmd + Shift + ' is actually Cmd + "
You could also try to add a key mapping witch auto select all the code in file and indent it:
'atom-text-editor':
'ctrl-alt-l': 'auto-indent:apply'
I was working on some groovy code, which doesn't auto-format on save. What I did was right-click on the code pane, then chose ESLint Fix. That fixed my indents.
If you are used to the Eclipse IDE or the Netbeans, you can use the package eclipse-keybindings (https://atom.io/packages/eclipse-keybindings):
This Atom package provides Eclipse IDE key mappings for Atom. Currently, the Eclipse shortcuts are directly mapped to existing Atom commands.
To format all lines from a file, just use: Ctrl+Shift+F.
Ctrl+Shift+i worked for me in PHP under Windows ... but some files did not react. Not being the brightest it took me a while to work out that it was the include files that were the problem. If you are using echo(' ... PHP ...') then the PHP does not get re-formatted. To get over this, create a temporary PHP file, say t.php, copy the PHP part into that, reindent it (Ctrl+Shift+i ... did I mention that?) and then copy the newly reformatted PHP back into the original file. Whilst this is a pain, it does give you correctly formatted PHP.

literal string expected error

Please have a look at the following code
with text_io;
use text_io;
procedure hello is
begin
put_line("hello");
new_line(3);
end hello;
When I click "build all" in GPS IDE, I get this error
gnatmake -d -PC:\Users\yohan\firstprogram.gpr
firstprogram.gpr:1:06: literal string expected
firstprogram.gpr:2:01: "end" expected
gnatmake: "C:\Users\yohan\firstprogram.gpr" processing failed
[2013-04-03 13:29:58] process exited with status 4 (elapsed time: 00.47s)
I am very new to Ada, as you can see, this is my first program. Please help.
On the command line, gnatmake will happily compile a file which contains Ada code but has the extension .gpr. GPS knows "better" than that, and insists on treating myfirstprogram.gpr as a GNAT Project file, which of course it isn't.
You'll find life with GNAT much easier if you stick with its file naming conventions: .ads for a spec, .adb for a body, and the file name needs to be the unit name in lower case. In your case, the file should have been called hello.adb.
The simplest approach to creating a GNAT project file in GPS is to go to the Project menu and select New. The only places where you must enter data are on the "Naming the project" page (you might choose firstproject!) and the "Main files" page, where you'd click on the blue + to add hello.adb; you can Forward through the others.
After adding the main file, you can click Apply to install the new project file; now you can Build all and Run.
You may find the GPS tutorial helpful (Help menu, GPS ...)