Multiple right margins in Pycharm - python

I am learning Pycharm Community Edition 3.4 and I was wondering If it was possible to have a right a margin for comments and docstring only, additionally to the regular margin for the rest of the code.
I ask because I am trying to stick to the PEP8 guideline of 72 characters per comment and 79 for regular code. I am constantly changing the right margin between 72/79 to make sure everything is fine but I don't find that very efficient.
Thanks in advance.

This feature was announced in September 2017.
Go to File -> Settings -> Editor -> Code Style -> Hard wrap at and Visual guides. For visual guides, you can enter multiple values separated by commas.

It is not possible in Pycharm given its basic configuration (without some plugins). But I am afraid that even plugins for this feature does not exist for Pycharm. At least, I could not find it.
In this question you may probably find something helpful:
https://superuser.com/questions/703425/intellij-ide-how-to-add-one-or-more-margins.

This is not yet a feature of any of the Intellij platforms.
You can follow/vote for the ticket here https://youtrack.jetbrains.com/issue/IDEA-99875

Related

Is it possible to change Python font in Visual Studio Code to cursive?

I'm sorry if this is a question already answered or if this kind of questions are not allowed.
I have been trying to figure out how to change the font (cursive like Fira Code iScript) in VS Code for Python like people have done for HTML and other languages to make it look prettier.
Attempts and Research
I spent last 3 hours to figure this out and watched multiple tutorials, but nothing seems to work for me. Now I have doubts that if it even works for Python in VS code.
I watched multiple tutorials on YouTube and other websites to figure it out but it just doesn't work for me.
This depends on your Syntax Highlighting theme. Either find the one that already has this text stylized or edit your current one to do it.
The parameter you need to set in there is called "fontStyle" and you need to set it as "italic" for all entities you want. You can find more about it in the Visual Studio Code documentation
This sounds difficult but it's not really, just bit time consuming. Fastest way would be of course finding a theme that already has it set though :) Good luck!
Modify the font through editor: Font Family in the Settings
or add the following configuration in settings.json.
"editor.fontFamily": "Ink Free,Consolas, 'Courier New', monospace",
The configuration content needs to be modified to the font name you need.

Are there any risks/downsides to putting emojis in code?

I sometimes use emojis in programs to highlight certain parts of the code (in open source libraries). I rarely use more than say 5-6 per script and I find they really stand out due to their colors in a text editor.
Typically, they are transient markers and will be removed when whatever issue they are associated with is closed.
My question is: are emojis liable to cause any issues in the general Python toolchain? This includes, but is not limited to: git, github, pypi, editors, linters, interpreter, CI/CD pipelines, command line usage...
I haven't seen any, but then again I rarely see emojis in code. This is a Python 3 only question, so Python 2 unicode aspects are out.
(This question is not about whether this looks professional or not. That's a valid, but entirely separate consideration.)
Some examples:
# ⚙️ this is where you configure foo
foo.max_cntr = 10
foo.tolerate_duplicates = False
# 🧟‍♂️🧟‍♂️🧟‍♂️ to indicate code to be removed
some dead code
# 👇 very important, don't forget to do this!
bar.deactivate_before_call()
In terms of risks, there aren't really any real ones. If you use them in comments they'll be removed/ignored at runtime anyway so performance-wise there's no issues.
The main issue that you could run into is that some Linux distributions (distros) DONT support emojis, so they'd fallback to some standard unicode character (generically a white rectangle with a cross through the middle), so this could make comments hard to understand.
But in personal use: no not really, there's no issues.
TLDR: Probably not, but maybe.

Setting different code styles for separate projects in Pycharm

I'm using Pycharm, and it's a great editor, but I have this issue while working on a number of projects at the same time. Unfortunately, the different projects I'm working on have different code styles.
The easiest example is that one uses spaces, while another uses tabs.
While I don't want to go into the whole Tabs vs Spaces debate, I'm wondering if there is a way to set Pycharm to use separate coding style rules per projects.
Thanks
Pycharm's Code Style configuration has built-in scheme setting just for your requirement.
Preference -> Editor -> Code Style -> Python
After setting the style, you can store it with the project, by clicking the Scheme pull-down menu list. Also you can store/export the style by clicking the gear icon next to it.
After reading the halfelf's answer, I found this option:
File -> Settings -> Editor -> Code Style -> Python
In the scheme options, there is a drop down list where you can choose project and set the choices to the relevant project only (the one that is currently chosen.
Hope this helps..

emacs Jedi disable #

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.

How can I make PyDev autoformat the maximum number of characters per line?

I am using PyDev for Python programming in Eclipse.
Is it possible to make PyDev auto-format my code to limit the maximum number of characters on a single line?
With standard PyDev
It seems that this option is only available in Eclipse's Java Editor.
The Java editor allows you to create "profiles" for the code formatter, while PyDev's options for the code formatter are very limited.
However,
You can hack this. PythonTidy.py is an awesome script that cleans up Python code to make it follow PEP8 conventions, and that can be tweaked with your own settings.
PythonTidy (code cleanup & formatting)
Get here (homepage) the source for PythonTidy.
You will see inside the file, at the beginning of the code and just after the comments, that many settings are defined.
The first one of these is COL_LIMIT with its default value set to 72. Now you can use PythonTidy to format your code the way you want.
Integration with PyDev
Now you have to make this work with PyDev's formatting. This blog post will explain it really better than me, but still I'll sum up the steps :
Write a Jython interface betwenn PyDev's editor (PyEdit) and PythonTidy. This blog's author already wrote a wrapper script in the public domain available in the above link or here in case the link goes 404.
Save this file anywhere you want, with the name pyedit_pythontidy.py, along with the PythonTidy.py file.
Configure PyDev to use this script as its Code Formatter. You can do this in Preferences > PyDev > Scripting PyDev
Note #1: I really recommend reading the original blog post to have a better understanding
Note #2: The wrapper script author did not implement Code Block formatting, so this means you can only format a full file. This should not be that hard to implement, up to you.
Note #3: All credits goes to bear330 for the PyDev integration part.

Categories

Resources