what I would like python.el to do (and maybe it does)
J Kenneth King
james at agentultra.com
Mon May 25 15:44:45 CEST 2009
Giovanni Gherdovich <giovanni.gherdovich at sophia.inria.fr> writes:
> Hello everybody,
> basically I'm writing here since I cannot
> make my python.el work (a major mode for writing
> python with emacs), but I would also like to share
> my user experience and tell you what I think
> an emacs mode should do, why do I like them
> and hopefully have some feedbacks to see if I
> misunderstood/underestimate something.
> == 1) my python.el doesn't behave very well ==
> I learnt somewhere
> that there are two major emacs mode for python around:
> python-mode.el and python.el.
> Asking my Emacs 22.3.1 about the variable load-path
> 'C-h v load-path RET
> I see that
> is in that path; there I find a file named
> which I assume to be some kind of emacs lisp bytecode
> since is pretty much unreadable.
> So I searched the web for a plain version of it,
> finding that the feature I use more, i.e.
> sending a line of a text file to the
> python buffer for evaluation (see below), correspond
> to the key sequence
> (well, it's python-send-buffer, so maybe not a single
> line but the whole buffer; the closest to my needs, anyway).
> However: I open my Emacs, issue M-x python-mode,
> then M-x run-python to have the interpreter in
> a second buffer, I type something in the
> first buffer and then C-c C-c, but nothing happens.
> Am I missing something?
> Do I have any hope of having some sort of
> send-line-to-python-buffer function working?
> == 2) How do I use emacs modes for interpreted languages ==
> Please note that what follows is just the personal perspective
> of an unexperienced user.
> Syntax highlighting is a great thing, but is not as critical
> to me as the feature I describe below.
> When I work with interpreted languages, I really hate doing it
> in the shell; after 20 commands I easily lose control on
> what happens and on which definitions are around.
> I use Emacs instead, so that I can have two buffers; in the
> first I type my expressions, in the second I evaluate them
> using some key bindings so that I can easily send the text
> from the first buffer to the second one line by line.
> In this way I can easily refactor my code, and eventually package it
> in a script if I like.
> Usually after a while the intepreter buffer is a big mess,
> so I restart it but my code is safe and sound in the first buffer.
> To do so, I don't really need a major mode, I admit; I just need
> to put the following code in my .emacs:
> (fset 'send-line-other-window
> [?\C-a ?\C- ?\C-e ?M-w right
> ?C-x ?o ?C-y return ?\C-x ?o])
> (global-set-key [f11] 'send-line-other-window)
> Then I open emacs, C-x 2 to have a second buffer,
> C-x o to switch to it and M-x shell to run bash in it.
> Then, in the case of python, I run "python" in the
> bash buffer. Then I type my code in the first and with F11
> I send lines to the interpreter.
> But since i like to do it The Right Way, I would
> like to let the python-mode worry about this...
> Sorry if this is just a bunch of obvious thoughts to most of you.
I find that it does work, but unlike SLIME for lisp, it just imports the statement.
It confused me at first, but basically the interpreter doesn't provide
any feedback to emacs.
Try opening a python source file (start python-mode if you don't have
an autoload hook) and do C-c C-z to bring up the Python
interpreter. Type in a simple assignment statement (like "a = 1 + 2"
without the quotes) into the source file. Then just C-c C-c as
usual. I never get any feedback. Just C-x o to the interpreter and
print out the variable you just defined. It should be there.
More information about the Python-list