PyCharm: Reformat code breaks django template - django-templates

If I run "reformat code" PyCharm changes this line:
{% ajax_dialog_opener url=duplicate_url|add:'?hide_messages=true' reload_on_success=False label='FoooBaar' dialog_title='Foo foo baaar' type='link'
After reformat code:
{% ajax_dialog_opener url=duplicate_url|add:'?hide_messages=true' reload_on_success=False label='FoooBaar' dialog_title='Foo foo baaar' type='link'
data_shortcut="mod+d" %}
But this means the new code is broken.
Is there a way to stop PyCharm from breaking above line?
Version: PyCharm community 2018.2

Go to
Preferences > Editor > Code Style
Change "Hard Wrap At" value to something bigger like 1000 (max).

Related

IntelliJ: Auto-wrapping only for comments?

Is there a way to enable auto-wrapping only for comments? So far I only found the setting to enable auto-wrapping for everything.
Javadoc comments are covered by
Editor > Code Style > Java > JavaDoc > Wrap at right margin
(So called) single line comments such as ...
// this is a comment
... are another matter. There's no configuration item available in Editor > Code Style > <your_langauage> > Wrapping and Braces to control these.
Edit 1: based on your first reply to this answer: "I am looking for auto-wrapping only for JavaDoc."
Untick this item: Editor > Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded
Tick this item: Editor > Code Style > Java > JavaDoc > Wrap at right margin
Here's a pair of screenshots showing before and after formatting, with the above configuration in place:
Before
After
The IntelliJ formatter has not wrapped the code (because Editor > Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded is not ticked) but it has wrapped the Javaodc (because Editor > Code Style > Java > JavaDoc > Wrap at right margin is ticked).
IntelliJ IDEA 2019.1 - Wrap JavaDoc only
Settings > Editor > Cody Style > Java > Wrapping and Braces
Hard wrap at: [Your preferred value for JavaDoc wrapping]
Wrap on typing: No
Keep when reformatting > Ensure right margin is not exceeded: Disabled
If any setting here is set to Wrap if long or Chop down if long, then change it to Do not wrap.
Settings > Editor > Cody Style > Java > JavaDoc
Other > Wrap at right margin: Enabled
Unfortunately, you cannot use "Wrap on typing" for JavaDoc only, because it will wrap code too, even if code wrapping is completely disabled.
Use CTRL+ALT+L to wrap your JavaDoc (Reformat Code).
Settings > Editor > Cody Style > Java > Wrapping and Braces
Settings > Editor > Cody Style > Java > JavaDoc

How to change line width in IntelliJ (from 120 character)

I was wondering how I can change the line length in IntelliJ.
Since I use a pretty high resolution, I get that line that shows 120 characters straight through the middle of the screen. Can I change it from 120 to, say, 250?
IntelliJ IDEA 2018
File > Settings... > Editor > Code Style > Hard wrap at
IntelliJ IDEA 2016 & 2017
File > Settings... > Editor > Code Style > Right margin (columns):
You can alter the "Right margin" attribute in the preferences, which can be found via
File | Settings | Project Settings | Code Style - General
Right Margin (columns) In this text box, specify the number of columns
to be used to display pages in the editor.
Source: Jetbrains
It seems like Jetbrains made some renaming and moved settings around so the accepted answer is no longer 100% valid anymore.
Intellij 2018.3:
hard wrap - idea will automatically wrap the line as you type, this is not what the OP was asking for
visual guide - just a vertical line indicating a characters limit, default is 120
If you just want to change the visual guide from the default 120 to lets say 80 in my example:
Also you can change the color or the visual guide by clicking on the Foreground:
Lastly, you can also set the visual guide for all file types (unless specified) here:
It may be useful to notice that very good answers given above may not be enough. It is because of one more tick is required here:
Be aware that need to change both location:
File > Settings... > Editor > Code Style > "Hard Wrap at"
and
File > Settings... > Editor > Code Style > (your language) > Wrapping and Braces > Hard wrap at
I didn't understand why my this didn't work but I found out that this setting is now also under the programming language itself at:
'Editor' | 'Code Style' | < your language > | 'Wrapping and Braces' | 'Right margin (columns)'
Open .editorconfig in the root of your project (or create one if you don't have any) and add:
max_line_length = 80
The IDE should pick it up immediately (works in PhpStorm, developed by the same company). As a bonus, it can be committed to GIT and will stay consistent across different editors you may be using in the future. More info on .editorconfig.

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.

Xcode 4.0.2/4A2002a: Editor > Code Folding -> Focus follows selection: Grey/Disabled. Why?

I'd love to use the feature
"Editor > Code Folding > Focus follows selection"
but unfortunately it's greyed out/disabled.
Any idea how to turn it on?
To take your answer from the comment, here it is in a nice command line form. Just paste this command in the Terminal:
defaults write com.apple.dt.Xcode DVTTextCodeFocusFollowsSelection -bool TRUE

How do I get Vim's project plugin to load the in.vim on external buffer change?

I'm using the project plugin in Vim. For each project I'm working on, I have set up an own in.vim/out.vim where the project-specific stuff gets set.
For example, I set a shiftwidth of 2 in the in.vim, whereas in my .vimrc, I set it to 4. When I'm opening a file from the project tree, everything is fine: the sw is 2. Now, I compile the sources (Visual Studio) and get some compiler errors/warnings. Switch to Visual Studio, fix the errors, back to Vim then.
My editor did realize that I changed the file outside the editor and asks me to reload the file. After confirming the reload, the sw is set to 4.
Obviously, this is because the .vimrc is getting read on buffer reload and overwrites my setting of the shiftwidth stored in the in.vim configuration file.
My question is: is there any way to bring the project plugin (or vim itself) to load the in.vim upon buffer refresh?
Solution
The answer of ZyX pointed me to a handling that works for me:
In the in.vim, set a global variable to the path of in.vim:
let g:invimpath = "D:/project/vimstuff/in.vim"
In the .vimrc, try to load this specified file when FileChangedShellPost occurs:
autocmd FileChangedShellPost * if exists("g:invimpath") | exe 'source ' . g:invimpath | endif
Credits go to ZyX to point me to this path.
Yes, it is, with FileChangedShellPost autocommand, but I suggest you first add the following just before the beginning of your vimrc (but after scriptencoding statement, if it is present):
if exists("s:vimrc_loaded")
finish
endif
let s:vimrc_loaded=1