I'm using Atom at work for editing Python code, and I'm running against a painful interaction between muscle memory and a labor-saving feature.
Near as I can tell, Atom will, when you paste a snippet of code, redo the indentation so that it's consistent with the indentation of the line it was pasted into, preserving relative indents.
If I didn't have any baggage from using editors without this feature, I'm pretty sure it'd be great, but as it is, I can't break my habit of selecting back to the preceding newline, and pasting that, which tends to do crazy things when pasting to or from the first line of a block.
I've tried to turn off Auto Indent on Paste, but it's not on anywhere I can find, and I'm not even sure it's the same feature; it's just what I hear about from people complaining about Atom going crazy when they paste Python.
So, where do I look to disable this? I'm willing to work up from no extensions back to what I've got installed, so assume a vanilla install.
I guess the workflow I'm looking for is "paste, manual re-indent", because at least that way I know what I'm getting and my response is always the same. As it stands, I don't have to think about it until it converts simple line rearrangements into syntactic garbage, which is worse than just adjusting things every time.
EDIT: In response to Milo Price, I have just now tried setting both autoIndentOnPaste and normalizeIndentOnPaste to false. The behavior is unchanged.
FURTHER EDIT: I had to reload the configuration for it to take. It's working now.
You have to set the config options autoIndentOnPaste and normalizeIndentOnPaste both to false, and then reload the configuration.
Related
The word "file" in python is not a keyword, but my Vim highlights it as if it were. Can someone suggest a fix and explain this strange behaviour? It keeps messing with me. It bothers me every time I look at it.
Extra info
I think I use regular Vim—I haven't tinkered with my .vimrc much, certainly not with the syntax highlighting.
Many builtins were removed in the Python 2 to 3 transition. file is one of them. Lots of syntax highlighters still highlight them. Now that Python 2 is no longer supported, maintainers may be willing to remove them from the lists, so you can try opening an issue if it bothers you.
I'm using PyCharm Community Edition 4.5.4, and I hate how it notifies me of every little "mistake" I make even when I have full intention of fixing it within 30 seconds.
My style is to kind of write everything at once (instead of finishing one thing before moving to the other), and thus every second word in my code gets highlighted as variable 'x' is not used or Unresolved reference 'x' because I already moved to an other section of my code, intenting to finish the for loop later. If I do something like:
for x in my_list:
pass
And then move to define my_list on top of the file, it will instantly highlight Local variable 'x' is not used. I wish to write my whole code freely, and then after hitting save, I wanna know what mistakes I made.
Is there any way to disable the PEP8 checker, so it would only check when I actually save the file, instead of when I type anything at all?
I have had problems with this issue too.
Unfortunately, there seems to be no documented way of doing what you're requesting. The PyCharm Articles on Code Inspection and Configuring Inspections really don't hint at any such possibility.
Additionally the config file in ~/.PyCharm40/config/inspection/Default.xml isn't what you would call rich in options (note: I have no idea if more options exist, couldn't really find appropriate documentation).
Since pep8.py is apparently ran continuously as a background process in PyCharm, I also checked whether a configuration of these processes was possible. Unfortunately (again), no useful results were found.
To make things worse, there seems to be no relevant plugin available in their plugin repository to allow for further tweaking of the inspection tool.
The other option I tried was by changing the settings in PyCharm and resort to manual calls to pep8. I unselected the inspections for pep8 from Settings | Editor | Inspections | Python tab and then ran the manual inspection by pressing Ctrl + Alt + Shift + I and entering the two pep options. It does not seem to catch the same coding convention errors.
You probably have two options now, one is switching to another IDE as Adam Smith suggested (or noted, actually) and second is trying to maybe get some help on the PyCharm forum.
I have a working version of JEDI with Emacs 24.3 on osx. The autocomplete feature is wonderful, except for when I want to comment things out! I frequently comment/uncomment portions of my code and was hoping there was a way to prevent JEDI's auto completion from coming up when I type #. Any advice or thoughts would be greatly appreciated!
edit: When I go to comment multiple lines I enter in # typically followed by DownArrow and LeftArrow, but what usually happens with JEDI enabled is this dialog pops up preventing me from moving to the following line until I make a selection:
You can try to use company-jedi for your python completion. This package doesn't have this problem.
One way to get around this issue would be to select the lines (region) you would like to comment out and hit M-;. This runs the command comment-dwim which comments out the selected region (or uncomments it, if it is currently commented out).
When used in conjunction with e.g. mark-lines which allows you to select the current line with a single key stroke, this makes for a really fast way of (un)commenting portions of your code, even if they span just one or two lines.
emacs-jedi dev here. If emacs-jedi works as you describe, then that's a bug.
But I cannot say what is wrong from the limited information I have. So, just general directions:
First, always try to reproduce the misbehavior in a clean Emacs setting, described here http://tkf.github.io/emacs-jedi/latest/#quick-try
This helps you to find out if your setting is wrong or if it is actually a bug in emacs-jedi.
Give the output of M-x jedi:show-version-info. http://tkf.github.io/emacs-jedi/latest/#jedi:show-version-info
This helps people diagnosing the problem.
This is a guess from your screenshot but it seems that you have old version of popup.el. So maybe auto-complete.el could be old one if you install them at the same time. If you don't see the problem in the clean Emacs (step 1. I mentioned above) which installs newest libraries, then updating them could solve the problem.
Update
So, I found a way to reproduce the behavior which is close to what you mentioned: https://github.com/tkf/emacs-jedi/issues/147
But as I wrote in the issue, I think it is a rare case. If you find a case which could happen very frequently, then let me know.
Coming from Perl I've been used to hitting C-c t to reformat my code according to pre-defined Perl::Tidy rules. Now, with Python I'm astonished to learn that there is nothing that even remotely resembles the power of Perl::Tidy. PythonTidy 1.20 looks almost appropriate, but barfed at first mis-aligned line ("unexpected indent").
In particular, I'm looking for the following:
Put PEP-8 into use as far as possible (the following items are essentially derivations of this one)
Convert indentation tabs to spaces
Remove trailing spaces
Break up code according to the predefined line-length as far as it goes (Eclipse-style string splitting and splitting method chains)
Normalize whitespace around
(bonus feature, optional) Re-format code including indentation.
Right now, I'm going throught someone else's code and correct everything pep8 and pyflakes tell me, which is mostly "remove trailing space" and "insert additional blank line". While I know that re-indentation is not trivial in Python (even though it should be possible just by going through the code and remembering the indentation), other features seem easy enough that I can't believe nobody has implemented this before.
Any recommendations?
Update: I'm going to take a deeper look at PythonTidy, since it seems to go into the right direction. Maybe I can find out why it barfs at me.
There is a reindent.py script distributed with python in the scripts directory.
untabify.py (Tools/scripts/untabify.py from the root directory of a Python source distribution) should fix the tabs, which may be what's stopping Python Tidy from doing the rest of the work.
Have you tried creating a wrapper around pythontidy? There's one for the sublime editor here.
Also, does pythontidy break up long lines properly for you? When I have a long line that ends in a tuple, it creates a new line for every entry in the tuple, instead of using Python's implied line continuation inside parentheses, brackets and braces as suggested by PEP-8.
I have used autopep8 for this purpose and found it handy.
I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.
I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent.
Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)?
There's also Ctrl+n in insert mode which will autocomplete based on the words it has seen in any of the open buffers (even in other tabs).
You may try Pydiction (Excerpt below)
Description Pydiction allows you to
Tab-complete Python code in Vim,
including: standard, custom and
third-party modules and packages. Plus
keywords, built-ins, and string
literals.
Pyflakes has a vim plugin that does this pretty awesomely. Unlike Pydiction, you don't need to build a dictionary beforehand (so if you're bouncing between different virtualenvs it's a bit less hassle.) I haven't been using it long but it seems very slick.
Try hitting Ctrl-p while typing mid-word. Ctrl-p inserts the most recent word that starts with the prefix you're typing and Ctrl-n inserts the next match. If you have several possibilities, you can hit ctrl-p more than once to substitute each candidate in order.