Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

How to run python script in emacs

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


devilspell at gmail

Sep 26, 2009, 8:54 AM

Post #1 of 14 (763 views)
Permalink
How to run python script in emacs

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


joinhack at gmail

Sep 26, 2009, 8:10 PM

Post #2 of 14 (726 views)
Permalink
Re: How to run python script in emacs [In reply to]

you can use emacs command shell for that

2009/9/26 devilkin <devilspell [at] gmail>

> 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
>


nobody at nowhere

Sep 26, 2009, 9:43 PM

Post #3 of 14 (721 views)
Permalink
Re: How to run python script in emacs [In reply to]

On Sat, 26 Sep 2009 08:54:49 -0700, devilkin wrote:

> 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.

--
http://mail.python.org/mailman/listinfo/python-list


devilspell at gmail

Sep 27, 2009, 7:44 PM

Post #4 of 14 (719 views)
Permalink
Re: How to run python script in emacs [In reply to]

On 9ÔÂ27ÈÕ, ÏÂÎç12ʱ43·Ö, Nobody <nob...@nowhere.com> wrote:
> On Sat, 26 Sep 2009 08:54:49 -0700, devilkin wrote:
> > 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.

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?
--
http://mail.python.org/mailman/listinfo/python-list


nobody at nowhere

Sep 28, 2009, 11:10 AM

Post #5 of 14 (712 views)
Permalink
Re: How to run python script in emacs [In reply to]

On Sun, 27 Sep 2009 19:44:07 -0700, devilkin wrote:

> and does the python-mode support auto-complete?

No.

--
http://mail.python.org/mailman/listinfo/python-list


Brian.Mingus at colorado

Sep 28, 2009, 1:47 PM

Post #6 of 14 (714 views)
Permalink
Re: How to run python script in emacs [In reply to]

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/

On Sat, Sep 26, 2009 at 9:54 AM, devilkin <devilspell [at] gmail> wrote:

> 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
>


olivier.darge at gmail

Oct 7, 2009, 9:01 AM

Post #7 of 14 (678 views)
Permalink
Re: How to run python script in emacs [In reply to]

On 26 sep, 17:54, devilkin <devilsp...@gmail.com> wrote:
> 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


fred.sells at adventistcare

Oct 7, 2009, 1:07 PM

Post #8 of 14 (679 views)
Permalink
RE: How to run python script in emacs [In reply to]

Hitting ctrl-c, twice quickly works for me.

> -----Original Message-----
> From: python-list-bounces+frsells=adventistcare.org [at] python
> [mailto:python-list-bounces+frsells=adventistcare.org [at] python] On
> Behalf Of OdarR
> Sent: Wednesday, October 07, 2009 12:02 PM
> To: python-list [at] python
> Subject: Re: How to run python script in emacs
>
> On 26 sep, 17:54, devilkin <devilsp...@gmail.com> wrote:
> > 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.
--
http://mail.python.org/mailman/listinfo/python-list


olivier.darge at gmail

Oct 7, 2009, 11:34 PM

Post #9 of 14 (679 views)
Permalink
Re: How to run python script in emacs [In reply to]

On 7 oct, 22:07, "Sells, Fred" <fred.se...@adventistcare.org> wrote:
> Hitting ctrl-c, twice quickly works for me.
>

?
what do you mean ?

Olivier
--
http://mail.python.org/mailman/listinfo/python-list


chris.felton at gmail

Oct 8, 2009, 10:24 AM

Post #10 of 14 (666 views)
Permalink
Re: How to run python script in emacs [In reply to]

> 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.


--
http://mail.python.org/mailman/listinfo/python-list


fred.sells at adventistcare

Oct 12, 2009, 11:46 AM

Post #11 of 14 (646 views)
Permalink
RE: How to run python script in emacs [In reply to]

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.
--
http://mail.python.org/mailman/listinfo/python-list


rustompmody at gmail

Oct 13, 2009, 5:12 AM

Post #12 of 14 (646 views)
Permalink
Re: How to run python script in emacs [In reply to]

On Sep 26, 8:54 pm, devilkin <devilsp...@gmail.com> wrote:
> 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

> 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.

>
> BTW, I'm not a english native speaker, any grammer mistakes, please
> correct them. :)

grammer is spelt grammar :-)
--
http://mail.python.org/mailman/listinfo/python-list


doug.stevens73 at gmail

Nov 25, 2009, 9:38 AM

Post #13 of 14 (486 views)
Permalink
Re: How to run python script in emacs [In reply to]

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?

On Oct 13, 7:12 am, rustom <rustompm...@gmail.com> wrote:
> On Sep 26, 8:54 pm, devilkin <devilsp...@gmail.com> wrote:
>
> > 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/...
>
> > 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.
>
>
>
> > BTW, I'm not a english native speaker, any grammer mistakes, please
> > correct them. :)
>
> grammer is spelt grammar :-)

--
http://mail.python.org/mailman/listinfo/python-list


pedroinsua at gmail

Dec 22, 2009, 4:34 PM

Post #14 of 14 (447 views)
Permalink
Re: How to run python script in emacs [In reply to]

On Wed, Nov 25, 2009 at 09:38:54AM -0800, doug wrote:
>
> 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




> On Oct 13, 7:12 am, rustom <rustompm...@gmail.com> wrote:
> > On Sep 26, 8:54 pm, devilkin <devilsp...@gmail.com> wrote:
> >
> > > 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/...
> >
> > > 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.
> >
> >
> >
> > > 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
/ \
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.