How to run python script in emacs

D

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. :)
 
N

Nobody

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

devilkin

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

OdarR

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
 
S

Sells, Fred

Hitting ctrl-c, twice quickly works for me.
-----Original Message-----
From: [email protected]
[mailto:p[email protected]] On
Behalf Of OdarR
Sent: Wednesday, October 07, 2009 12:02 PM
To: (e-mail address removed)
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
 
C

Chris

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

Sells, Fred

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

rustom

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 :)
 
D

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top