fgallina / python.el Goto Github PK
View Code? Open in Web Editor NEWPython's flying circus support for Emacs
License: GNU General Public License v3.0
Python's flying circus support for Emacs
License: GNU General Public License v3.0
While installing using el-get I get this error "Error: IO error reading /Users/nyaruka/.emacs.d/el-get/python.el: Is a directory" this error is linked to the name of your repository.
It will be better if you just name it something different to the file itself.
For following code the python-indent-calculate-indentation returns wrong offset:
if blah:
do_something
else:
if blah:
do_something
else: # For this, the function return 0 as offset, when it should be 4
The electric colon causes that the last else: drops all the way to the zero indentation level, as current-indentation is 4 and python-indent-calculate-indentation is 0.
Calling M-x mark-defun
when inside a method marks the entire class definition instead of just the method itself.
Will be great if your python.el support python-describe-symbol as in Emacs python.el.
def foo(word1, word2, word3, word4, word5,
When you type a long def like this, and need more arguments, you expect enter after "word5" to put your point under the "w" in "word1" so you can continue adding args, like so:
def foo(word1, word2, word3, word4, word5,
word6, word7)
However enter puts my point at the start of the line, and will not move it.
You should add Version and URL fields in the file header comments to make it compatible with current ELPA standards. This way users will be able to submit to package repositories like Google's Marmalade.
Have a look here for more details.
Like so:
event_transitions[data['period']] = right_now_iso8601
also functions in dictionaries:
event_transitions['%s-%s' % tuple(data['score'])] = right_now_iso8601
I have looked through previous (now closed) issues on the subject, but I'm encountering a problem getting ipython to run. Rather than either 'run-python' or C-c C-c opening ipython, python is opened instead.
I have python.el installed from the marmalade repos on Emacs 24.
Here is the relevant snippet from my init.el
(setq
python-shell-interpreter "ipython"
python-shell-interpreter-args ""
python-shell-prompt-regexp "In \[[0-9]+\]: "
python-shell-prompt-output-regexp "Out\[[0-9]+\]: "
python-shell-completion-setup-code ""
python-shell-completion-string-code "';'.join(__IP.complete('''%s'''))\n")
A minor issue, but: repr(foo) correctly hilights repr. However, print repr(foo) leaves repr unhilighted.
When starting a debug session on Emacs 24.0.50 on Windows, pdbtrack does not mark the correct line in the source.
This happens because the following code (from line 1295):
(line-num
(save-excursion
(string-match
(format python-pdbtrack-stacktrace-info-regexp
(regexp-quote
inferior-python-mode-current-temp-file))
full-output)
inferior-python-mode-current-temp-file is inserted into the python-pdbtrack-stacktrace-info-regexp. On Windows the regexp quoted string looks like this "C:/Docu1/Temp/pyakdah" (or similar). However, the full-output of the shell on Windows contains the Windows style path, e.g. "C:\Docu1\Temp\pyakdah". Therefore, the string-match returns nil and the line-number is always 0.
One fix would be to do a string replace of '/' with '\'. However, I am not sure why the path to the file is even included in the python-pdbtrack-stacktrace-info-regexp. Maybe there is a cleaner more portable solution.
Hi,
Your python.el seems to provide the best support for py3. However, I have not been able to make completion work correctly using ipython3.
I use the following
(setq
python-shell-interpreter "ipython3"
python-shell-interpreter-args "--classic --colors linux"
python-shell-prompt-regexp "In [[0-9]+]: "
python-shell-prompt-output-regexp "Out[[0-9]+]: "
python-shell-completion-setup-code ""
python-shell-completion-string-code
"';'.join(__IP.complete('''%s'''))\n")
The problem probably lies in python-shell-completion-string-code. The weirdest thing is that completion does not work in the inferior python shell, but it works when ipython3 is started from an ordinary shell outside of Emacs. I am just starting on Python for a Computational Mathematics course. . .
Thanks,
Rasmus
I'm using Emacs 24.0.50.1 (from git, I believe, built on 26 th January 2011), and tried to compile python.el
both using my ordinary Emacs setup (didn't work) and a plain Emacs (using emacs -Q -nw
), and they both provided me with the following error message when I tried to compile it:
Compiling file /home/oscar/git/python.el/python.el at Fri Feb 18 09:31:15 2011
python.el:275:16:Error: Symbol's value as variable is void: python-rx-constituents
In commit fdc4e56 the (beginning|end)-of-defun functions do not work.
The errors I get are:
Which error depends on where in the file the point is and whether I run C-M-a or C-M-e.
Hi,
I don't know whether this is a python.el issue or whether it is an eldoc issue, but with very long docstrings, like quad
of scipy (approx 70 lines), the bottom is shown rather than the top. Most likely, the user wants a quick view of possible arguments, not a snip from an example, which is usually found in the bottom of long docstrings.
This might be due to "bad" coding of docstrings, but long docstrings seems to be norm at least in scipy-related packages.
Maybe it would be possible to parse the docstring something similar to head
?
Thanks again,
Rasmus
T
Usually (in python-mode.el, Eclipse, ...) a new indentation level will be opened when a statement is splited in multiple lines e.g.
def foo():
long_var1, \
long_var2 = 1, 2
Should look like:
def foo():
long_var1, \
long_var2 = 1, 2
Keywords highlighting should be updated for Python 3. For instance print is no longer a keyword, None, True and False are new keywords, etc. Have a look here - http://docs.python.org/release/3.2/reference/lexical_analysis.html#keywords
whenever I try to indent something I get
let*: Arithmetic error
Tell me if you need that I run something to get more info.
system: Archlinux, emacs 23.2.1
Are there plans to have imenu support?
Since PEP 8 requires new line at the end of file I think this mode can set this explicitly to true. Thanks.
Example from Django:
if request.METHOD == 'POST':
# do something with post
request.method
is highlighted as though it's an assignment. So the same as:
thing = False
Hi all
I've been playing around with emacs-prelude, an Emacs 24 only package which uses python.el as the default python mode.
I've come across an issue with indentation which is probably easiest understood by looking at the 43 second screencast at - http://screencast.com/t/IQGNUV6T2qWW - some discussion can be found at https://github.com/bbatsov/emacs-prelude/issues/25
On the screen cast the left hand side is emacs-prelude with python.el and the right hand side the stock emacs24 python-mode.el (it is emacs 24 running under emacs -Q). The inserted closing parenthesis from electric-pair-mode seems to confuse python.el. I assume if you do this manually under Emacs23 the same issue would occur.
Any suggestions welcomed. If there is anything I can do to further test please let me know.
Many thanks
Ian
Directly from an email from Brett Hoerner
def func():
for x in open('file'):
try:
pass
except Exception: # after I've added the :, note that the except
# was just de-indented and now lines up with my "for" and not the
# "try" that it should line up with
The same code for the "Closes " will be useful to check this :)
Please add support for the new ipython 0.12
Hi Fabian,
The commentary should include a section on the dependency on readline for shell completion. On Windows, shell completion does not work out of the box, since readline is not available. However, installing pyreadline from here: http://ipython.scipy.org/moin/PyReadline/Intro solves the problem. I was expecting to have to adapt the python.el code to use pyreadline, but it just works out of the box.
Christoph
When invoking M-q
in a docstring, I see unexpected behavior. Given the following docstring:
"""A special-case of build_model that knows how to build a model based on
words from a corpus given as a string or a file-like object."""
Pressing M-q
causes the docstring to be reformatted like so:
"""A special-case of build_model that knows how to build a model based on
words from a corpus given as a string or a file-like object.
"""
As you can see, an extra newline is inserted at the end. This is not how I prefer my docstrings to be formatted. The following code, in python-fill-paragraph-function
at line 1511, controls this behavior:
;; If there is a newline in the docstring lets put triple
;; quote in it's own line to follow pep 8
(when (save-excursion
(re-search-backward "\n" string-start-marker t))
(newline)
(newline-and-indent))
When I remove that code, my docstrings are filled as I'd like them to be.
Is there any chance we could have a setting to control this? I'd never encountered that particular bit of PEP 8 style. I don't think I can stand to have all of my multiline docstrings end in a blank line and then the closing quotes.
Thanks for the promising new Python mode!
I'm wondering if it's possible to support "autoindent" in the same way that python-mode does? For example, if you have the following code:
def foo(self):
And the point is just at the right of the colon, pressing return in python-mode puts the cursor on the next line right beneath the "f" in foo. In python.el, it puts it all the way at the beginning of the line, and you need to hit the tab key to move it.
at least import
and from
should be mapped to font-lock-preprocessor-face
.
(font-lock-add-keywords 'python-mode `((,(rx symbol-start (or "import" "from") symbol-end) 0 font-lock-preprocessor-face)))
and @property
and other decorators should map to,
(font-lock-add-keywords
'python-mode
`(("^[ ]*\\(@\\)\\([a-zA-Z_][a-zA-Z_0-9.]+\\)\\((.+)\\)?"
(1 'font-lock-preprocessor-face)
(2 'font-lock-builtin-face))))
since @
is a preprocessor command and whatever follows should probably just follow the builtin syntax, even though what follows can be defined by the user also.
I am trying to get the solarized
theme to match with the VIM version and I am just finding these things which are minor changes which can make things a little more clear and colorful for us so inclined.
I am very busy atm but in a month i'll have time and hopefully i can submit a more formal patch if this isn't easy already. I don't know about font-lock in modes, just learned enough to get these minor patches in.
Hi,
ESS has and extremely useful function called Eval Line (C-c C-j). I miss it in python.el.
Personally, I think it would be nice and sufficient if python.el Eval Region (C-c C-r) would default to the current line if no region is selected.
Thanks,
Rasmus
I use emacs -q
(i.e. no unorthodox config) for test and python2 -i
as the inferior shell (python
is python 3 in my distribution).
Here is a snip that /always/ causes a freeze. Move the cursor over
dif.append or the following line with eldoc-mode enabled in the
following.
dif = [0.]
for i in range (1,1001) :
dif.append(abs(
e**(a*td[i])-u[i]
))
I don't know why it happens, though, but my best guess is a lost
connection to the inferior shell or lack of info from the inferior
shell... But I probably shouldn't be speculating.
Emacs Info
In GNU Emacs 24.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.22.1)
of 2011-03-12 on Pank
Windowing system distributor The X.Org Foundation', version 11.0.10904000 configured using
configure 'CFLAGS=-march=native -O2 -pipe -fno-optimize-sibling-calls' '--prefix=/usr' '--sysconfdir=/etc' '--localstatedir=/var' '--libexecdir=/usr/lib' '--mandir=/usr/share/man' '--without-sound' '--with-x-toolkit=gtk' 'LDFLAGS=-Wl,--hash-style=gnu -Wl,--as-needed''
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: nil
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: en_DK.UTF-8
value of $XMODIFIERS: nil
locale-coding-system: utf-8-unix
default enable-multibyte-characters: t
Major mode: Python
Minor modes in effect:
eldoc-mode: t
tooltip-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
beginning-of-defun
doesn't work correctly when the function name begins with an underscore. As far as I can tell, this happens because _
is defined as a symbol in the syntax table, but python-beginning-of-defun-regexp
looks for word constituents.
When using python-shell-send-file with a file that contains pdb.set_trace() the pdbtrack indicator is not indicating the correct line. This is because the python-pdbtrack-comint-output-filter-function uses the name of the temporary file (executing the open/execute/close code) instead of the real .py file name whereas the full-output from the shell contains the name of the .py file.
Directly from an email from Brett Hoerner
from app.models import Object
Object.objects.exclude(foo=1)\
.filter(bar=2)\
.values_list('baz')
This is how indentation should behave for that kind of lines.
It would be nice to have something like this (which I put in my init.el) so that python-mode has special highlighting of numbers. It's something I like(d) in VIM.
(make-face 'font-lock-number-face)
(set-face-attribute 'font-lock-number-face nil :inherit font-lock-constant-face)
(setq font-lock-number-face 'font-lock-number-face)
(defvar font-lock-number "[0-9]+\\([eE][+-]?[0-9]*\\)?")
(defvar font-lock-hexnumber "0[xX][0-9a-fA-F]+")
(defun add-font-lock-numbers ()
(font-lock-add-keywords nil (list
(list (concat "\\<\\(" font-lock-number "\\)\\>" )
0 font-lock-number-face)
(list (concat "\\<\\(" font-lock-hexnumber "\\)\\>" )
0 font-lock-number-face)
)))
(add-hook 'python-mode-hook 'add-font-lock-numbers)
Before sending the buffer to the shell, python-shell-send-buffer calls (widen) to disable any narrowing. I am not sure this is very useful. I expected it to honor the narrowing and send only the (narrowed) content of the buffer. Since narrowing has to be enabled explicitly by the user, I don't think this would lead to any confusion.
if True:
if True:
pass
else:
pass
Place your point after the ":" in the else and press tab, it will de-indent but not cycle through indent options with further tabs. However, you start your point at the beginning of "else" (or before it) it will cycle between the two possible indents.
Is this expected? It's certainly odd when I run up against it.
The following line in python-shell-send-file (l. 1216)
(find-file-noselect file-name)
will open the temporary buffer. However, the buffer stays open and since python-shell-send-file is called by a lot of shell operations, after a while I have dozens of temporary files open in my buffer list.
I am not sure what this line is doing anyway. It almost looks like debug code?
Christoph
When writing an if sentence, the intendation is not automatically reduced by one when writing an "else:". It would be cool if inserting the colon after "else" would make the indentation to decrease by one. Existing python-mode already does this, so it probably could be nicked from there ;)
Example of current behaviour:
if:
# this correctly adds intendation by one
do_something()
else:
# Writing the colon after else should take intendation back one step
do_something_else()
Can we have support for ipython shell. Working tab completion would make it really snazzy!
I am using emacs-starter-kit and I found that it binds to hook prog-mode-hook in order to set reasonable defaults for programming modes:
https://github.com/technomancy/emacs-starter-kit/blob/v2/starter-kit-defuns.el#L108
So I wonder is there any possibility to add integration between python.el and ESK using prog-mode-hook? Thanks.
Example:
from foo.bar.baz import \
something, something_else
The second line doesn't indent at all while I think it should indent one level
# We have this code here because of foo. For example:
Hitting enter there will drop you at the next line, indented as if you were in code.
Example:
request.session['flash'] = 'Contract group killed'
Hi,
IPython2 has a new completion mechanism (and a new interesting QT console).
Thus,
;; python-shell-completion-string-code
;; "';'.join(__IP.complete('''%s'''))\n")
doesn't work.
I have tried
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n"
"';'.join(get_ipython().Completer.complete('''s''')[1])\n"
but neither seems to function quite well
--Rasmus
Using latest code on ubuntu 10.10 and pdbtrack doesn't work... Are others seeing this too?
In python-mode.el, after indenting a region, the region is not cleared so you can immediately indent the block again. This comes in quite handy. It would be nice if this were available.
If I startup and edit a python file, autocompletion using ropemacs works fine.
If I then open a python-shell (C-c C-z) running python -i, then when I try again to use autocompletion in ropemacs, my emacs freezes.
I am using:
GNU Emacs 24.0.50.1 (x86_64-apple-darwin10.6.0, NS apple-appkit-1038.35) of 2011-03-15
I will do some more testing and maybe I need to use Pymacs 0.24.
In commit 6e46a01 sending simple files to the shell seems to be broken.
print "Hello World!"
works fine.
def foo():
print "Hello World!"
fails, as does
class Foo():
def __init__(self):
print "Hello World!"
The error is always something like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "d:/devel/python/test.py", line 1
def foo():
^
SyntaxError: invalid syntax
>>>
pointing to the end of the first line.
Thanks for this new python-mode. I really like it!
The closing parenthesis of the following function call indents wrongly:
def myfun():
fn(foo,
bar
)
I'm not sure where it's supposed to go, but current indentation - 1 is wrong for sure.
In Pep 8 is a hint that function arguments should be distinguished from the function body, e.g.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
Should look like:
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
In commit 98aca51:
The Python buffer does not show >>> prompt when invoking run-python.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.