what I would like python.el to do (and maybe it does)

  • Thread starter Giovanni Gherdovich
  • Start date
G

Giovanni Gherdovich

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
http://www.emacswiki.org/emacs/PythonMode
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
issuing
'C-h v load-path RET
I see that
/usr/share/emacs/22.3/lisp/progmodes
is in that path; there I find a file named
python.elc
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

\C-c\C-c

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

Regards,
Giovanni
 
A

Arnaud Delobelle

Giovanni Gherdovich said:
Hello everybody,
Hi

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

What platform are you on?

I use Aquamacs (which is a packaged Emacs for macos X, based on GNU
Emacs 22.3.1) and for me C-c C-c works. It executes the content of the
current buffer in a Python interactive buffer called *Python* (which it
creates if it doesn't exist).
 
J

J Kenneth King

Giovanni Gherdovich said:
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
http://www.emacswiki.org/emacs/PythonMode
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
issuing
'C-h v load-path RET
I see that
/usr/share/emacs/22.3/lisp/progmodes
is in that path; there I find a file named
python.elc
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

\C-c\C-c

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

Regards,
Giovanni

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

Piet van Oostrum

J Kenneth King said:
JKK> I find that it does work, but unlike SLIME for lisp, it just imports the statement.
JKK> It confused me at first, but basically the interpreter doesn't provide
JKK> any feedback to emacs.
JKK> Try opening a python source file (start python-mode if you don't have
JKK> an autoload hook) and do C-c C-z to bring up the Python
JKK> interpreter. Type in a simple assignment statement (like "a = 1 + 2"
JKK> without the quotes) into the source file. Then just C-c C-c as
JKK> usual. I never get any feedback. Just C-x o to the interpreter and
JKK> print out the variable you just defined. It should be there.

What kind of feedback do you expect?
 
J

J Kenneth King

Piet van Oostrum said:
What kind of feedback do you expect?

Well, that's the thing -- type a statement into a python interpreter and
you just get a new prompt.

LISP has a REPL, so you get some sort of feedback printed.

However, some sort of visual cue on the emacs side would be nice. Either
just flash the block of code being sent or a minibuffer message would be
nice.

Look for some SLIME tutorial videos on youtube to see some great
interpreter <-> editor interaction.

The stock Python interpreter probably wouldn't cut it close to something
like SLIME in terms of features, but the iPython package might be a
start.
 
P

Piet van Oostrum

J Kenneth King said:
JKK> Well, that's the thing -- type a statement into a python interpreter and
JKK> you just get a new prompt.
JKK> LISP has a REPL, so you get some sort of feedback printed.

iPython also has a REPL, but only when you enter the Python code
manually in the iPython window.
JKK> However, some sort of visual cue on the emacs side would be nice. Either
JKK> just flash the block of code being sent or a minibuffer message would be
JKK> nice.
JKK> Look for some SLIME tutorial videos on youtube to see some great
JKK> interpreter <-> editor interaction.

I have tried out SLIME with SBCL (just some simple code) but I didn't
like the feedback. I got unnecessary compiler warnings, and it was
difficult to find some useful information in it.
JKK> The stock Python interpreter probably wouldn't cut it close to something
JKK> like SLIME in terms of features, but the iPython package might be a
JKK> start.

For now the iPython package for me has more options than I have had time
to try out.
On the other hand when you execute some code form a Python file (with
C-c C-c or C-c |) you get this
## working on region in file /tmp/python-26084kfr.py... in the *Python*
buffer which is very uninformative. This is generated by python-mode,
not by iPython. You do get any output printed in the code, however, as
well as exceptions.

I have made a change in my Python mode such that the
## working on region in file /tmp/python-26084kfr.py...
message will be replaced by the actual code executed, if that code is
not too big (size configurable). And that looks nicer.
 
J

J Kenneth King

Piet van Oostrum said:
iPython also has a REPL, but only when you enter the Python code
manually in the iPython window.



I have tried out SLIME with SBCL (just some simple code) but I didn't
like the feedback. I got unnecessary compiler warnings, and it was
difficult to find some useful information in it.


For now the iPython package for me has more options than I have had time
to try out.
On the other hand when you execute some code form a Python file (with
C-c C-c or C-c |) you get this
## working on region in file /tmp/python-26084kfr.py... in the *Python*
buffer which is very uninformative. This is generated by python-mode,
not by iPython. You do get any output printed in the code, however, as
well as exceptions.

I have made a change in my Python mode such that the
## working on region in file /tmp/python-26084kfr.py...
message will be replaced by the actual code executed, if that code is
not too big (size configurable). And that looks nicer.

If you have a patch file for that, I'd be interested in trying it out. :)
 
R

rustom

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.

Regards,
Giovanni

I dont see whats the problem.
Heres my attempt to show you my emacs windows using python-mode
(python.el never worked for me)
## Window 1 file foo.py (python mode)
x = 1

y = 2

## Window 2 python interpreter
####
Goto the python file (foo.py)
Select the x=1 line
C-c | (which is py-execute-region)
Goto python interpreter window....
NameError: y not defined

What more/less/else do you want?

Are you using python-mode.el or python.el?
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top