How to run python script in emacs

Discussion in 'Python' started by devilkin, Sep 26, 2009.

  1. devilkin

    devilkin Guest

    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. :)
    devilkin, Sep 26, 2009
    #1
    1. Advertising

  2. devilkin

    Nobody Guest

    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.
    Nobody, Sep 27, 2009
    #2
    1. Advertising

  3. devilkin

    devilkin Guest

    On 9ÔÂ27ÈÕ, ÏÂÎç12ʱ43·Ö, Nobody <> 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?
    devilkin, Sep 28, 2009
    #3
  4. devilkin

    Nobody Guest

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

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


    No.
    Nobody, Sep 28, 2009
    #4
  5. devilkin

    OdarR Guest

    On 26 sep, 17:54, devilkin <> 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
    OdarR, Oct 7, 2009
    #5
  6. devilkin

    Sells, Fred Guest

    Hitting ctrl-c, twice quickly works for me.

    > -----Original Message-----
    > From: python-list-bounces+frsells=
    > [mailto:python-list-bounces+frsells=] On
    > Behalf Of OdarR
    > Sent: Wednesday, October 07, 2009 12:02 PM
    > To:
    > Subject: Re: How to run python script in emacs
    >
    > On 26 sep, 17:54, devilkin <> 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.
    Sells, Fred, Oct 7, 2009
    #6
  7. devilkin

    OdarR Guest

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


    ?
    what do you mean ?

    Olivier
    OdarR, Oct 8, 2009
    #7
  8. devilkin

    Chris Guest


    > 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.
    Chris, Oct 8, 2009
    #8
  9. devilkin

    Sells, Fred Guest

    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.
    Sells, Fred, Oct 12, 2009
    #9
  10. devilkin

    rustom Guest

    On Sep 26, 8:54 pm, 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?


    >
    > 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 :)
    rustom, Oct 13, 2009
    #10
  11. devilkin

    doug Guest

    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 <> wrote:
    > On Sep 26, 8:54 pm, 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?

    >
    > > 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 :)
    doug, Nov 25, 2009
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pedro Werneck
    Replies:
    0
    Views:
    444
    Pedro Werneck
    Aug 18, 2003
  2. jmDesktop
    Replies:
    15
    Views:
    480
  3. cnb
    Replies:
    0
    Views:
    302
  4. Robinson
    Replies:
    2
    Views:
    2,185
  5. Adam Funk
    Replies:
    4
    Views:
    231
    Adam Funk
    Jan 29, 2007
Loading...

Share This Page