Difference in solarized gvim theme - python

I am using a Solarized theme for (g)vim, and having an issue with small difference between the screenshot on the site and what I am actually having.
The screenshot for python on the theme's site is here:
(source: ethanschoonover.com)
, and mine is
They have a small difference (that I can see) in import statement (color is different). It sort of drives me crazy. Is my case correct, and that's what supposed to happen, or my settings are wrong?
I've installed the theme using vim-addon-manager plugin system.
Thanks.

The first thing you can check is what :highlight groupings are being applied to your import statement, I have a key mapping for a function which can do this:
" Show the stack of syntax hilighting classes affecting whatever is under the
" cursor.
function! SynStack()
echo join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), " > ")
endfunc
nnoremap <F8> :call SynStack()<CR>
If you :source a file containing this or put this in your .vimrc and reopen vim, we can now check what highlighting is being applied to import.
When I press F8 on an import I receive the message pythonInclude, now if you don't see that there may be something wrong with the parsing of python file and the keyword import hasn't been picked up on. We can then look at what rules are being applied to that-
:highlight pythonInclude
This gives me-
pythonInclude xxx links to Include
If we follow this then we can see what rules are being applied to Include group. This will probably go deeper, Include xxx links to PreProc. If you get this far your highlighting groups are probably correct. If you didn't link to PreProc there maybe another plugin overwriting the highlight group, or a similar issue. You can then check what colors the PreProc is setting. You can override a highlight group link, :highlight link pythonInclude Function this will now display imports as the same color as Functions!
You can also modify the colors and formatting applied to different highlight groupings however I will leave you to discover those on your own. Much more help can be found in :h :highlight, but I hope this helps start your debugging process!

Related

Disable on-the-fly PEP8 checks, only check when saving file

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.

Pycharm's code style inspection: ignore/switch off specific rules

I'm trying to import existing project into PyCharm. I can refactor the code so that PyCharm will be pleased, but we like to have spaces around colons in dictionaries, like this: {"A" : "B"}. We also like aligning assignments:
a = 1
abc = 3
Is there a way to configure PyCharm, so that he'll ignore all errors/warnings related to this specific stuff?
Using PyCharm 5 (community edition), you can do the following: Code –> Inspect Code. Then select the required inspection error, and click on the "Suppress" option or "Ignore errors like this" option on right hand side.
Please look at the screenshot below:
When you choose the "Suppress" option, it adds a comment as shown in the screenshot below:
Suppressing can be done at the statement, or function/method, levels. If trying to suppress an argument to a function, the suppression only works at the function level (meaning it also suppresses other name reference violations that might exist within that function).
You also have the option of switching off "PEP8 coding style violations" altogether (by ticking the box shown below), or explicitly managing "Ignore Errors" manually. Screenshot given below:
In general, you should perhaps question why you are suppressing PEP8 guidelines. However, sometimes it appears necessary, for instance when using the pytest module, it is necessary to shadow variables, etc, which the PEP8 Inspection complains about in. In such cases, this feature in PyCharm is very helpful.
If you're ok to ignore all matching issues, you can just press Alt-Enter (or click on the lightbulb) and choose "Disable Inspection". Saves you going into the settings and trying to figure out the inspection rule that matches.
From http://iambigblind.blogspot.jp/2013/02/configuring-pep8py-support-in-pycharm-27.html
#Krzysztof Stanisławek, function is different as Pycharm follows the PEP8 coding style, so it is recommended that there is no whitespace between the function variables and ":", if you don't want this, you can disable it by
"Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation"
However, this is not recommended.
I got the same issue, and the neat solution has been pointed by #fantabolous, from configuring PEP8.py support in PyCharm 2.7
Example before
Adding the error code either manually or with "Alt+Enter" on error highlight
The error code can be found here
After the changes
It's great to select precisely some rules instead of disabling all warning from PEP8. Thanks to the previous comments.
to have spaces around colons in dictionaries, configure Settings > Editor > Python Spaces
Other > Before ':'
and
Other > After ':'

Locate the Containing Package or Module **Before** Importing

I often find myself needing to import something, but not quite sure of its fully qualified name. I usually end up opening a browser, performing an internet search like python [target_of_import], and scanning a page or two until I find it.
This works, but causes a relatively long break in my workflow, especially if I have to search for a few in a row. How do other people address this?
Is there something like Haskell's Hoogle for Python?
[Note: I currently use vim, in case anyone suggests an IDE-based solution.]
EDIT: For answers concerning autocomplete, please specify this. In general, autocomplete is probably a non-starter solution since in the particular case I am asking about the leftmost characters of the string to be autocompleted are not known.
EDIT 2: While I will not categorically rule out suggestions concerning switching to/learning a new IDE, I'm pretty unlikely to completely change the way I work to accomplish this (e.g., switching from vim on the command line to something like Eclipse + plugins).
You can do this in vim using the Unite.vim
Enable fuzzy file searching by adding the following to your .vimrc:
call unite#filters#matcher_default#use(['matcher_fuzzy'])
Search for file:
:UniteWithInput file_rec/async:/base/path:!<cr>
Search within files:
:UniteWithInut grep:/base/path<cr>
Search file names and within files
:UniteWithInput file_rec/async:/base/path:! grep:/base/path<cr>
(Use to change between sources)
See also :h :UniteWithCursorWord
This will open a buffer with the file matches. You can open the file by pressing enter but since you only want copy the file name simply use y$ to yank the line, q to close the buffer and the p to paste the yanked line.

Python highlighting in emacs

I am using emacs 23 -nw and xterm installed on Debian Squeeze. I need highlighting with python but I don't have it. How can I enable it?
Edit:
Thanks for all answers, the problem is that
I have googled a lot, really.
I have the code on a file with extension .py
The script starts with #!/usr/bin/python, as one of the the answers points I have changed to !#/usr/bin/env python
I used M-x and tried to find something related to python, well there many options which do not solve my problem.
Sorry my question was not very precise and I even accept -10 but I don't have highlight which would give me red highlight for lines starting # etc. To be more precise I have a very a dull highlight; lines with # are white, lines between """ """ are green, some of the variable names are yellow but don't know why not all. [import, as, from] are light blue, [open, max, and other function names] are dark blue etc. And besides my 200 lines of code is working.
I'm not sure if this is right, but try the following.
1) M-x
2) type in "python-mode". Tab completion works here so type in "pyth" and hit tab and you can see what your options are.
mj
If you run Emacs from xterm with emacs -nw, you'll have a different color layout than if you run the same color mode in an X window. Differences include big changes in the highlighting of comments, different colors assigned to various keywords and (rarely in my experience, though Python comments seem to fall into this category) failure to highlight some elements.
I'm not really sure why this happens, but it doesn't seem to be a problem on your end since it's consistent on every machine I've worked on. If it really bugs you, and you really, really want to keep running from xterm, take a look at the color-theme module, it may help.
Emacs 23 should know about Python out of the box. Does the name of your Python file end with .py, or does the file have #!/usr/bin/env python as the first line? If you're creating a new file, make sure the filename ends with .py. You can also use M-x python-mode as mentioned in another answer. If none of that works, check that your terminal actually supports color.

How can I make the PyDev editor selectively ignore errors?

I'm using PyDev under Eclipse to write some Jython code. I've got numerous instances where I need to do something like this:
import com.work.project.component.client.Interface.ISubInterface as ISubInterface
The problem is that PyDev will always flag this as an error and say "Unresolved import: ISubInterface". The code works just fine, it's just that I'd rather not have these little white/red X-marks next to my code and have my Problems tab littered with these errors.
Is there a way I can add a magic comment or something like that to the end of the line to make PyDev ignore the false error, similar to how you can sprinkle comments like "# pylint: disable-msg=E1101" to make PyLint ignore errors?
Also, there's a possibility I'm just doing it wrong when it comes to using Java interfaces in Jython. In which case a little bit of guidance would be very much appreciated.
You can add a comment
##UnresolvedImport
##UnusedVariable
So your import becomes:
import com.work.project.component.client.Interface.ISubInterface as ISubInterface ##UnresolvedImport
That should remove the error/warning. There are other comments you can add as well.
Add the hash character # at the end of the line then with the cursor on the flagged error, press Ctrl-1. One of the options in the menu will be something like #UndefinedVariable. Adding this comment will cause PyDev to ignore the error.
You can make the ignore like the other posts suggest, but the real problem is that Pydev cannot find that class... If you add a .jar that contains that class to your PYTHONPATH it should be able to resolve it (or if you have a Java project that has that class, you should be able to mark that project as a Pydev project and add its bin folder to the project PYTHONPATH -- in which case that class should be found too).
It is not a PYTHONPATH issue. It is related to importing/using static class-internal members of a Java class. I am getting the same sort of thing all over the place e.g. when trying to use constants in java.awt.Color:
import java.awt.Color as Color
borderColor = Color.BLACK # get "Undefined variable from import: BLACK" error
There is no way I've found to import Color.BLACK in this case. Thanks to iceman for at least pointing out the ##UndefinedVariable flag. That helps a lot. Note also that this is NOT a jython problem, the code runs just fine. It's just an issue with PyDev.

Categories

Resources