Discussion:
How to run python script in emacs
devilkin
2009-09-26 15:54:49 UTC
Permalink
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?

also please recommand some emacs plug-ins for python programming, i'm
also beginner in emacs.currently i'm only using python.el. Are any
plugins supply code folding and autocomplete?

BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
Join hack
2009-09-27 03:10:23 UTC
Permalink
you can use emacs command shell for that

2009/9/26 devilkin <devilspell at gmail.com>
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
also please recommand some emacs plug-ins for python programming, i'm
also beginner in emacs.currently i'm only using python.el. Are any
plugins supply code folding and autocomplete?
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
--
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090927/566503df/attachment.html>
Nobody
2009-09-27 04:43:45 UTC
Permalink
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
According to "C-h m":

M-C-x py-execute-def-or-class
C-c ! py-shell
C-c | py-execute-region
C-c return py-execute-import-or-reload
C-c C-c py-execute-buffer
C-c C-s py-execute-string

Also, "C-c ?" from within a python-mode buffer provides an introductory
tutorial on python-mode.
devilkin
2009-09-28 02:44:07 UTC
Permalink
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
M-C-x py-execute-def-or-class
C-c ! py-shell
C-c | py-execute-region
C-c return py-execute-import-or-reload
C-c C-c py-execute-buffer
C-c C-s py-execute-string
Also, "C-c ?" from within a python-mode buffer provides an introductory
tutorial on python-mode.
Thanks, I tried C-c C-c, it gives no output, perhaps because I'm using
emacs on Windows. I'll test it on Ubuntu later.
and does the python-mode support auto-complete?
Nobody
2009-09-28 18:10:19 UTC
Permalink
Post by devilkin
and does the python-mode support auto-complete?
No.
Brian
2009-09-28 20:47:48 UTC
Permalink
I do all my python coding in emacs. It's awesome. Here's how I do it:

*Create windmove bindings*
This is important - it maps *Meta-i,j,k,l* to move your window focus up,
left, down, right. It's used in conjunction with *C-x 3* (split window
vertically) and *C-x 2* (split window horizontally). So this is how you
divide emacs into quadrants and then move around them:
*
C-x 3 C-x 2 M-l M-x 2*

You'll now find yourself in the upper right quadrant. Getting to the lower
left just takes three keystrokes: *M-kj*. Getting back is *M-li*. Highly
efficient. Put this in your .emacs file:

(global-set-key "\M-j" 'windmove-left)
(global-set-key "\M-l" 'windmove-right)
(global-set-key "\M-i" 'windmove-up)
(global-set-key "\M-k" 'windmove-down)

*Create a python buffer*
The easiest way to get a python buffer is to create a python file and then
open it. I use emacs exclusively in no window mode (-nw) since the gui is so
ugly and highlighted code looks so much better on a black background.
*
touch my_python_file.py
emacs -nw my_python_file.py* # you're automatically put in python-mode

You can also just open emacs -nw and create a new buffer like so:

*emacs -nw
C-x b my_python_file.py
C-x C-s my_python_file.py
M-x python-mode*

*Create a python shell that is linked to your buffer*

This is where we really get to show off the power of emacs. After you've got
a single window split emacs horizontally (*C-x 3*). Now you've got two
copies of your my_python_file.py buffer visible, one on the left, one on the
right. We're going to stick a python shell on the right with *C-c !*. Now
your cursor is on the right, in your python shell and your python buffer is
on the left

Let's move back to the python buffer with *M-j* and now let's write a small
bit of code. I want to demonstrate how powerful/useful/efficient this new
mode is by showing you how to execute only* part* of a for loop.

while True:
print "hi"
break
print "bye"

This is obviously some silly code, It's going to print hi once, and then
it's going to stop, and it's never going to print bye. You can test this out
by running py-execute-buffer, which is linked to *C-c C-c*. You should see
the word hi printed in the output of your shell, and your focus is also in
this shell.

Use *M-j* to get back to the python code. Now we're just going to execute
two lines of this code: While True: print "hi" - an infinite loop.

*M-Shift-<* # takes you back to the beginning of the buffer
*Ctrl-Spacebar* # tells emacs to start highlighting
*Ctrl-n n* # tells emacs to move the cursor down two lines, and
emacs highlights both of those lines as well.
*Ctrl-c |* # tells emacs to run the highlighted code only.

Uh-oh, you just ran an infinite loop. 'hi' is being printed in your shell a
zillion times a second. Let's stop it:
*
M-l* # move over to the shell
*C-c C-c* # tells emacs to stop the code execution - KeyboardInterrupt

Ok we're good. If you want, you can repeat the above steps, except just
execute the print "bye" part of the for loop:
*
M-j * # move back to our python ocde
*M-Shift-<* # move back to start of buffer
*Ctrl-n n n* # move to the print "bye" line
*Ctrl-Spacebar * # start highlighting
*Ctrl-e* # move cursor to the end of the line, highlighting
that line
*Ctrl-c |* # run this line of code

*The major benefits of this style of coding - efficiency*

After you get a handle on these keyboard shortcuts - and there really aren't
that many - you will be a highly efficient python hacker because of your
enhanced ability to debug. You can open up large python files and execute
the computationally intensive parts of them selectively, and then continue
coding up the file without having to rerun that code. You can hack on
multiple files at the same time in the same shell. You can modify the state
(e.g., variables) of your code execution by going into your shell, and
modifying or deleting it. You can kill your shell (*C-x k enter*) and start
a new one. And if you end up needing a real debugger you can install pydb,
which comes with a handy-dandy emacs mode:
http://bashdb.sourceforge.net/pydb/
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
also please recommand some emacs plug-ins for python programming, i'm
also beginner in emacs.currently i'm only using python.el. Are any
plugins supply code folding and autocomplete?
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
--
http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090928/6f80b904/attachment.html>
OdarR
2009-10-07 16:01:47 UTC
Permalink
I'm just starting learning python, and coding inemacs. I usually
splitemacswindow into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks likeemacsshort cut?
also please recommand someemacsplug-ins for python programming, i'm
also beginner inemacs.currently i'm only using python.el. Are any
plugins supply code folding and autocomplete?
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
hello,

I was not so long ago in the same situation.
I switch to emacs too, why ?
probably because the movement is more natural than in vi (used for 12+
years),
python-mode automatically starts on the machines I'm using, this is
very convenient for *re-indentation* .
Python could be difficult to maintain if you don't have a flexible
text editor.
if you want, i can suggest you some lines for the init file .emacs,
in order to keep the text indented with 4 spaces, no tab at all (very
important).

I also suggest you to have a look on ipython shell, which is a super
shell you keep side the text editor.
once you discover it, you'll understand.

I didn't hear for an autocompletion in emacs.
but ipython has a autocompletion. It can sound weird to auto-complete
outside your editor, but I like it.
you can test little code snippets in ipython, discover the
documentation and methods, and try them.
I discover this clever advice in http://oreilly.com/catalog/9780596515829/

currently I work with Mac (Aquamacs), and I was recently on Solaris or
XP as well.
PS: emacs on Mac Terminal with a french keyboard is a bit of a
nightmare considering the META key...:-(
Aquamacs solves this finally.


Olivier
Sells, Fred
2009-10-07 20:07:28 UTC
Permalink
Hitting ctrl-c, twice quickly works for me.
-----Original Message-----
From: python-list-bounces+frsells=adventistcare.org at python.org
[mailto:python-list-bounces+frsells=adventistcare.org at python.org] On
Behalf Of OdarR
Sent: Wednesday, October 07, 2009 12:02 PM
To: python-list at python.org
Subject: Re: How to run python script in emacs
I'm just starting learning python, and coding inemacs. I usually
splitemacswindow into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks likeemacsshort cut?
also please recommand someemacsplug-ins for python programming, i'm
also beginner inemacs.currently i'm only using python.el. Are any
plugins supply code folding and autocomplete?
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
hello,
I was not so long ago in the same situation.
I switch to emacs too, why ?
probably because the movement is more natural than in vi (used for 12+
years),
python-mode automatically starts on the machines I'm using, this is
very convenient for *re-indentation* .
Python could be difficult to maintain if you don't have a flexible
text editor.
if you want, i can suggest you some lines for the init file .emacs,
in order to keep the text indented with 4 spaces, no tab at all (very
important).
I also suggest you to have a look on ipython shell, which is a super
shell you keep side the text editor.
once you discover it, you'll understand.
I didn't hear for an autocompletion in emacs.
but ipython has a autocompletion. It can sound weird to auto-complete
outside your editor, but I like it.
you can test little code snippets in ipython, discover the
documentation and methods, and try them.
I discover this clever advice in
http://oreilly.com/catalog/9780596515829/
currently I work with Mac (Aquamacs), and I was recently on Solaris or
XP as well.
PS: emacs on Mac Terminal with a french keyboard is a bit of a
nightmare considering the META key...:-(
Aquamacs solves this finally.
Olivier
--
http://mail.python.org/mailman/listinfo/python-list
----------------------------------------------------------------------
[**CONFIDENTIALITY NOTICE**]: The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer.
OdarR
2009-10-08 06:34:33 UTC
Permalink
Post by Sells, Fred
Hitting ctrl-c, twice quickly works for me.
?
what do you mean ?

Olivier
Sells, Fred
2009-10-12 18:46:13 UTC
Permalink
Here is the .emacs file I place at c:\ on xp. I don't understand it and
cannot explain it. It was developed by a few guys I worked with 20
years ago and still does the job. Probably quite obsolete by now, but
if it ain't broke...
In response to your "what do you mean"
With the cursor in a python buffer (and the mode must say python). Hold
down the control key and hit the "c" key twice.
------------------------------------------------------------------
(setq initial-major-mode 'c-mode)
(setq text-mode-hook 'turn-on-auto-fill)
(setq-default indent-tabs-mode nil)
(global-set-key "\C-z" 'narten-suspend-emacs)
(global-set-key "\C-_" 'help-command)
(setq help-char 31)
(define-key global-map "\C-h" 'backward-delete-char-untabify)
(global-set-key "\C-x\C-e" 'compile)
(global-set-key "\C-x1" 'my-delete-other-windows)
(setq manual-program "man")
(setq manual-formatted-dir-prefix (list "/usr/man/cat"
"/usr/local/X11R4/man"))
(setq manual-formatted-dirlist (list
"/usr/man/cat1" "/usr/man/cat2" "/usr/man/cat3" "/usr/man/cat4"
"/usr/man/cat5" "/usr/man/cat6" "/usr/man/cat7" "/usr/man/cat8"
"/usr/man/catl" "/usr/man/catn" "/usr/local/X11R4/man/catn"
"/usr/local/X11R4/man/cat3" ))
(global-set-key "\em" 'manual-entry)
(global-set-key "\eg" 'goto-line)
(global-set-key "\C-xb" 'my-switch-to-buffer)
(global-set-key "\C-m" 'newline-and-indent)
(global-set-key "\C-q" 'electric-buffer-list)
(global-set-key "\C-x\C-b" 'buffer-menu)
(global-set-key "\C-x\C-y" 'cd)
(global-set-key "\es" 'shell)
(global-set-key "\C-xd" 'display-filename)
(global-set-key "\C-i" 'narten-do-a-tab)
(global-set-key "\C-x\C-b" 'buffer-menu)
(global-set-key "\C-_\C-_" 'help-for-help)
(global-set-key "\C-_\C-a" 'apropos)
(global-unset-key "\C-_\C-c")
(global-unset-key "\C-_\C-d")
(global-unset-key "\C-_\C-n")
(global-unset-key "\C-_\C-w")
(defun my-delete-other-windows ()
(interactive)
(delete-other-windows)
(recenter))
(defun narten-suspend-emacs ()
(interactive)
(save-all-buffers)
(suspend-emacs))
(defun narten-do-a-tab ()
(interactive)
(cond ((looking-at "^")
(progn (delete-horizontal-space)
(indent-relative)))
((looking-at "[ \t]*")
(tab-to-tab-stop)))
(let ((beg (point)))
(re-search-backward "[^ \t]")
(tabify (point) beg))
(re-search-forward "[ \t]+"))
(defun display-filename ()
(interactive)
(message buffer-file-name))
(defun save-all-buffers ()
(interactive)
(save-some-buffers 1)
(message "done!"))
(defun my-switch-to-buffer ()
"switch to buffer, using completion to prevent bogus buffer names from
being given"
(interactive)
(switch-to-buffer (read-buffer "Switch to buffer: " (other-buffer)
"t")))
;;;
;;; GNUS stuff
;;;
(setq gnus-nntp-server "astro")
(setq gnus-your-domain "sunrise.com")
(setq gnus-your-organization "Sunrise Software International")

(setq display-time-day-and-date t)
(setq display-time-no-load t)
(setq display-newmail-beep t)
(display-time)
;;(setq-default tab-width 4 );;;;;;;;;;;;;;;;fred

(put 'narrow-to-region 'disabled nil)


(put 'narrow-to-page 'disabled nil)

(put 'insert-file 'disabled nil)

(autoload 'python-mode "python-mode" "" t)
(setq auto-mode-alist
(cons '("\\.py$" . python-mode) auto-mode-alist))
;;(my-delete-other-windows)
;;(electric-buffer-list)

;;(cond (window-system
;; (setq hilit-mode-enable-list '(not text-mode)
;; hilit-background-mode 'light
;; hilit-inhibit-hooks nil
;; hilit-inhibit-rebinding nil)
;;
;; (require 'hilit19)
;; ))

;;
;; Hilit stuff
;;
;;(cond (window-system
;; (setq hilit-mode-enable-list '(not text-mode)
;; hilit-background-mode 'light
;; hilit-inhibit-hooks nil
;; hilit-inhibit-rebinding nil)
;;
;; (require 'hilit19)
;; ))
;;(require 'paren)

(setq-default transient-mark-mode t)

;;(electric-buffer-menu-mode)
(my-delete-other-windows)


(put 'erase-buffer 'disabled nil)

(put 'upcase-region 'disabled nil)

----------------------------------------------------------------------
[**CONFIDENTIALITY NOTICE**]: The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer.
Chris
2009-10-08 17:24:03 UTC
Permalink
Post by OdarR
if you want, i can suggest you some lines for the init file .emacs,
in order to keep the text indented with 4 spaces, no tab at all (very
important).
I would be interest in the .emacs changes for python mode.
rustom
2009-10-13 12:12:49 UTC
Permalink
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
also please recommand some emacs plug-ins for python programming, i'm
also beginner in emacs.currently i'm only using python.el.
python.el comes with emacs
python-mode.el comes from python https://launchpad.net/python-mode/
Because of some emacs politics the first ships with emacs although
most uses prefer the second.
Note 1. The key bindings are different
Note 2. Does not work with python3. See my post
http://groups.google.com/group/comp.lang.python/browse_thread/thread/d65139d6d1822ad4?pli=1
Post by devilkin
Are any plugins supply code folding and autocomplete?
See rope http://rope.sourceforge.net/ropemacs.html if you want
but its an installation headache (requires pymacs bleeding edge
version etc)
I suggest you just get used to python-mode first (C-c ! and C-c C-c)
and then explore these questions a bit later.
Post by devilkin
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
grammer is spelt grammar :-)
doug
2009-11-25 17:38:54 UTC
Permalink
When I type C-c C-c my emacs window just hangs. If I use Task Manager
to kill cmdproxy I can get emacs back but of course interactivity with
Python is not accomplished. By the way, if I do C-c ! then I get a
functional python shell. Does anybody know a solution to this?
Post by rustom
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
also please recommand some emacs plug-ins for python programming, i'm
also beginner in emacs.currently i'm only using python.el.
python.el comes with emacs
python-mode.el comes from python ?https://launchpad.net/python-mode/
Because of some emacs politics the first ships with emacs although
most uses prefer the second.
Note 1. The key bindings are different
Note 2. Does not work with python3. See my posthttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...
Post by devilkin
Are any plugins supply code folding and autocomplete?
See ropehttp://rope.sourceforge.net/ropemacs.htmlif you want
but its an installation headache (requires pymacs bleeding edge
version etc)
I suggest you just get used to python-mode first (C-c ! and C-c C-c)
and then explore these questions a bit later.
Post by devilkin
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
grammer is spelt grammar :-)
Pedro Insua
2009-12-23 00:34:44 UTC
Permalink
Post by doug
When I type C-c C-c my emacs window just hangs. If I use Task Manager
to kill cmdproxy I can get emacs back but of course interactivity with
Python is not accomplished. By the way, if I do C-c ! then I get a
functional python shell. Does anybody know a solution to this?
run emacs with --debug-init , then see the *Messages* Buffer.

With Python, I use python-mode, pymacs with rope, pysmell, and
anything with iPython.

I prefer iPython like shell..

But see http://www.emacswiki.org/ , there's a lot of documentation.

And .. Emacs version? Python version? .. etc
Post by doug
Post by rustom
Post by devilkin
I'm just starting learning python, and coding in emacs. I usually
split emacs window into two, coding in one, and run script in the
other, which is not very convenient. anyone can help me with it? is
there any tricks like emacs short cut?
also please recommand some emacs plug-ins for python programming, i'm
also beginner in emacs.currently i'm only using python.el.
python.el comes with emacs
python-mode.el comes from python ?https://launchpad.net/python-mode/
Because of some emacs politics the first ships with emacs although
most uses prefer the second.
Note 1. The key bindings are different
Note 2. Does not work with python3. See my posthttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...
Post by devilkin
Are any plugins supply code folding and autocomplete?
See ropehttp://rope.sourceforge.net/ropemacs.htmlif you want
but its an installation headache (requires pymacs bleeding edge
version etc)
I suggest you just get used to python-mode first (C-c ! and C-c C-c)
and then explore these questions a bit later.
Post by devilkin
BTW, I'm not a english native speaker, any grammer mistakes, please
correct them. :)
grammer is spelt grammar :-)
--
Porqu? loitar e matar, se podes amar e sonhar

/"\
\ / CAMPANHA DA FITA ASCII - CONTRA MAIL HTML
X ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
/ \
Continue reading on narkive:
Loading...