PyDev tab alignment in inline comments - python

I'm sure there is an easy fix for this, but I've scoured the preferences and haven't been able to find an option with an appropriate sounding name.
Here's a simple example, the top line isn't in the code, but there to illustrate every 4th character position:
# # # # # # # #
a = 2 # something two
b = "ab" # something else foo
Between "something" and "two" I hit <tab> twice, between "something else" and "foo" I hit <tab> twice.
My expectation is that using tab inside a comment would insert the necessary spaces to get to the next tabstop (the way tab outside of a comment works) Instead, pressing tab always inserts exactly 4 spaces, regardless of the column you're currently in.
This doesn't happen in Eclipse inside a Java project, which leaves me to believe it's a PyDev thing.
Just to be clear, I expected that hitting tab twice on the first line and once in the second would produce:
# # # # # # # #
a = 2 # something two
b = "ab" # something else foo
Thanks in advance for what is almost definitely a very simple fix.
P.S. I was hesitant with tagging this with Python, if there's a user with edit privileges wants to untag it, I wouldn't be offended in the least.

This is really expected in PyDev right now.
As a note if someone would want to implement that, the related place is:
org.python.pydev.editor.autoedit.PyAutoIndentStrategy.customizeDocumentCommand -- with tests at org.python.pydev.editor.PyAutoIndentStrategyTest.
This currently enters the case where "if (!contentType.equals(ParsingUtils.PY_DEFAULT))" where we don't handle expected tab-stops as we'd on code partitions (i.e.: org.python.pydev.editor.autoedit.PyAutoIndentStrategy.handleTab).

Related

PyCharm, how to skip autocomplete suggestions

I like the autocomplete feature of PyCharm in most cases. But sometimes it just suggests nonsense.
For example if I want to name a method one it renames it to __round__(self, n=None)
How can I skip the suggestion in this case? I didn't find the correct keyword in the PyCharm documentation.
If I write eg. def one I would prefer the following behaviour:
tab or/and enter --> accept suggestion
shift + ctrl + enter --> complete statement to def one(self):
Maybe you can tap space when the autocomplete suggestion appears and then delete the space instead of using Mouse.
It works for the first time pycharm shows suggestion, but if you use ctrl+space for suggstion and then tapping space, it will autocomplete default code suggestion.
Anyway, space is enough for preventing coding interruption
Go to File -> Settings -> Editor -> General -> Code Completion
UNCHECK - Insert selected suggestion by pressing space, dot, or other context-dependent keys
Now, you can use SPACE to skip.
TAB or RETURN will insert.

Using ycm in vim with python, how to retain the docstring preview while e.g. detailing parameters?

YouCompleteMe is a lovely tool for autocompletion in vim. It also shows the docstring of the 'hovered' autocomplete candidate, which is a very useful tool for me. This preview is sadly closed as soon as one confirms the candidate, e.g. by opening parentheses.
Example:
First Docstring is shown:
Typing a parenthesis will kill the docstring though:
Now i would love to keep the docstring while my 'cursor' is in the parentheses of whatever i just autocompletion for (to be detailed: obviously the docstring of the innermost parentheses, if they are nested).
Can this be done, and if yes, how?
Thank you so much in advance,
LJKS
Add below to your vimrc
let g:ycm_autoclose_preview_window_after_completion = 0
or Default.
The optional g:ycm_autoclose_preview_window_after_completion is 0 by default.
I think this will help you out:
let g:ycm_autoclose_preview_window_after_completion = 0 " default
let g:ycm_autoclose_preview_window_after_insertion = 1
ycm_autoclose_preview_window_after_insertion:
When this option is set to 1, YCM will auto-close the preview window after the user leaves insert mode. This option is irrelevant if g:ycm_autoclose_preview_window_after_completion is set or if no preview window is triggered.
Default: 0

Is is possible to customize how comments are inserted via the Keyboard Shortcut?

Is it possible to change the way PyCharm adds the hash # when using the keyboard shortcut to comment a line? (default CTRL+/)
I'd like the # to be at column 1 rather than at the indent level. Also, the cursor is moved down a line after the keyboard shortcut and I'd rather it stay on the same line.
Currently:
def foo():
my_uncommented_line
# commented_with_keyboard_shortcut
var = "and now the cursor is at the start of this line"
What I'd like:
def foo():
my_uncommented_line
# commented_with_keyboard_shortcut
var = "cursor stays on the previous line"
I'm currently searching around the JetBrains plugin repo for something that does this, but no luck thus far.
I know that this doesn't follow PEP8. I'd like to be able to make this change so that I can be consistent with the rest of the project:
Some other good reasons to ignore a particular guideline:
2. To be consistent with surrounding code that also breaks [the guideline].
The most you can do is alter the style:

Is there a way to make == work in vim to reindent python code?

Let's say I have the following Python code:
if conditionOne():
if conditionTwo():
foo = bar
foo += 1
bar -= 2
If I later remove conditionTwo, I would like to dedent the three lines of the block so it looks consistent with all my other code. Normally I'd just reach for =% (my primary language is C++), but that won't work here, so I tried 3== on the first line of the block. That led to this:
if conditionOne():
foo = bar
foo += 1
bar -= 2
That's not what I was looking for. I could have gone with 3<< and gotten a better result, but that's not a command I normally use. I'd rather not have to remember special indentation commands just for Python. In the spirit of Don't Make Me Think, is there a way to make the = filters work with Python code as I expect?
Whereas in C or C++ indenting a program does not affect its behaviour, in Python it could really, since indentation is part of the flow control.
Therefore in Python a program with a different indentation will have a different behaviour and for an editor it is impossible to guess whether the developer wanted to indent a line (in an inner scope) or not.
Hence auto-indenting features of your editor are designed to work with C-like languages, not Python.
If you use the vim-indent-object plugin, you could do the following to delete the line and dedent the block:
With the cursor on the conditional: <iidd
With the cursor anywhere in the block: <aidd
With this in mind, maybe you could :nmap =% <ii and :nmap == <ai and delete the conditional as you wish. This isn't a perfect solution but it seems like a decent alternative to me.

In pdb how do you reset the list (l) command line count?

From PDB
(Pdb) help l
l(ist) [first [,last]]
List source code for the current file.
Without arguments, list 11 lines around the current line
or continue the previous listing.
With one argument, list 11 lines starting at that line.
With two arguments, list the given range;
if the second argument is less than the first, it is a count.
The "continue the previous listing" feature is really nice, but how do you turn it off?
Late but hopefully still helpful. In pdb, make the following alias (which you can add to your .pdbrc file so it's always available):
alias ll u;;d;;l
Then whenever you type ll, pdb will list from the current position. It works by going up the stack and then down the stack, which resets 'l' to show from the current position. (This won't work if you are at the top of the stack trace.)
Try this.
(pdb) l .
Maybe you can always type the dot.
ps.
You may consider to use pudb. This is a nice UI to pdb what gdbtui is to gdb.
If you use epdb instead of pdb, you can use "l" to go forward like in pdb, but then "l." goes back to the current line number, and "l-" goes backwards through the file. You can also use until # to continue until a given line. Epdb offers a bunch of other niceties too. Need to debug remotely? Try serve() instead of set_trace() and then telnet in (port 8080 is the default port).
import epdb
epdb.serve()
I don't think there is a way to turn it off. It's annoyed me enough that once I went looking in the pdb source to see if there was an undocumented syntax, but I didn't find any.
There really needs to be a syntax that means, "List the lines near the current execution pointer."
You could monkey patch it for the behavior you want. For example, here is a full script which adds a "reset_list" or "rl" command to pdb:
import pdb
def Pdb_reset_list(self, arg):
self.lineno = None
print >>self.stdout, "Reset list position."
pdb.Pdb.do_reset = Pdb_reset_list
pdb.Pdb.do_rl = Pdb_reset_list
a = 1
b = 2
pdb.set_trace()
print a, b
One could conceivably monkey patch the standard list command to not retain the lineno history.
edit: And here is such a patch:
import pdb
Pdb = pdb.Pdb
Pdb._do_list = Pdb.do_list
def pdb_list_wrapper(self, arg):
if arg.strip().lower() in ('r', 'reset', 'c', 'current'):
self.lineno = None
arg = ''
self._do_list(arg)
Pdb.do_list = Pdb.do_l = pdb_list_wrapper
a = 1
b = 2
pdb.set_trace()
print a, b

Categories