sage-view, under emacs

36 views
Skip to first unread message

Pierre

unread,
Feb 19, 2009, 5:24:29 AM2/19/09
to sage-devel
hello all,

i've posted this in sage-support with no luck. Strikes me it might be
for sage-devel...

I've installed the latest package for emacs, now with sage-view. Wow !
very very cool, all the bugs are gone.

I was wondering, however, how the plots work within sage-view : if i
try

P= plot(lambda x : sin(x), (-2,2))

Then none of "P" or "show(P)" or anything lets me see the plot... with
sage-view disabled, i can just ask for "P" and the default image
viewer on my system starts with the png image, which is great.

could i combine this behavior with the nice formulae of sage-view ?
this would be the definite death of the notebook for me (not that i've
ever used it much anyway).

thanks !
pierre

Matthias Meulien

unread,
Feb 19, 2009, 6:22:29 AM2/19/09
to sage-...@googlegroups.com
Hi Pierre,

> I've installed the latest package for emacs, now with sage-view. Wow !
> very very cool, all the bugs are gone.

Thanks to Nick Alexander's great work!

> could i combine this behavior with the nice formulae of sage-view ?
> this would be the definite death of the notebook for me (not that i've
> ever used it much anyway).

Lets quote Nick Alexander announcement for sage-mode 0.5 (post called
`ANN: sage-mode 0.5' posted on sage-devel on Sat, 31 Jan 2009) :

> (...) Use sage-view in an inferior sage buffer to have all your output
> latexed and your plot commands appear inline in the inferior sage
> buffer -- after you apply the patch at
> http://trac.sagemath.org/sage_trac/ticket/5147.
>
I've not tried it. But it seems to be the thing your are looking for,
isn't it?
--
Matthias

Pierre

unread,
Feb 19, 2009, 8:20:42 AM2/19/09
to sage-devel
> > (...) Use sage-view in an inferior sage buffer to have all your output
> > latexed and your plot commands appear inline in the inferior sage
> > buffer -- after you apply the patch at
> >http://trac.sagemath.org/sage_trac/ticket/5147.
>
> I've not tried it. But it seems to be the thing your are looking for,
> isn't it?

after a while i came accross this message, too. But i've also realized
that i haven't got a clue how to apply a patch!! anyone ? the webpage
seems to suggest a direct change in the source of Sage, but i can't
even locate the right file (it's meant to be plot.py and i've got many
files in my system with that name...)

it seems this fix would make the plots appear within emacs. In fact, i
think i'd rather stick to the behavior without sage-view, to have the
plots appear in new windows... seems to me that it would just be
necessary to disable one of two functions in sage-view, any idea ?

> --
> Matthias

mabshoff

unread,
Feb 19, 2009, 8:24:30 AM2/19/09
to sage-devel


On Feb 19, 5:20 am, Pierre <pierre.guil...@gmail.com> wrote:

Hi Pierre,
You can do two things:

* Wait for Sage 3.3 out in a day or two.
* run

hg_sage.apply("http://trac.sagemath.org/sage_trac/attachment/
ticket/5147/trac_5147-plot-output-filename.patch")

and exit sage followed by a "sage -b". Then restart Sage and it
should be fixed.

> > --
> > Matthias

Cheers,

Michael

Pierre

unread,
Feb 19, 2009, 8:40:35 AM2/19/09
to sage-devel
>  * run
>
>     hg_sage.apply("http://trac.sagemath.org/sage_trac/attachment/
> ticket/5147/trac_5147-plot-output-filename.patch")

i've tried that. It didn't seem to complain too much, though i did get
the message:

WARNING:
Make sure to create a ~/.hgrc file:
----------------------------------------------------------------------
[ui]
username = William Stein <wst...@gmail.com>
----------------------------------------------------------------------

shall i really create an empty file with this name now ? (.hgrc) or
create the file and re-try ?

>
>  and exit sage followed by a "sage -b". Then restart Sage and it
> should be fixed.

this also seems to work (no error messages i mean), but the plots
under emacs are still missing. Well, it may also have something to do
with Aquamacs, which I'm using, and which might be different from
other emacsen.

thanks for helping anyway !


mabshoff

unread,
Feb 19, 2009, 9:23:41 AM2/19/09
to sage-devel, Nick Alexander


On Feb 19, 5:40 am, Pierre <pierre.guil...@gmail.com> wrote:
> >  * run

Hi Pierre,

> >     hg_sage.apply("http://trac.sagemath.org/sage_trac/attachment/
> > ticket/5147/trac_5147-plot-output-filename.patch")
>
> i've tried that. It didn't seem to complain too much, though i did get
> the message:
>
> WARNING:
> Make sure to create a ~/.hgrc file:
> ----------------------------------------------------------------------
> [ui]
> username = William Stein <wst...@gmail.com>
> ----------------------------------------------------------------------
>
> shall i really create an empty file with this name now ? (.hgrc) or
> create the file and re-try ?

The patch has already been imported, so unless you will import more
patches you can ignore that. Creating the file cannot hurt either
way.

> >  and exit sage followed by a "sage -b". Then restart Sage and it
> > should be fixed.
>
> this also seems to work (no error messages i mean), but the plots
> under emacs are still missing.

Ok. Good so far.

> Well, it may also have something to do
> with Aquamacs, which I'm using, and which might be different from
> other emacsen.

Sure. Do you have an X based Emacs to see if this fixes the problem? I
am CCing Nick on this email since I haven't seen him around for a
couple days and want to make sure he will become aware of the issue in
case he is in "deep research mode". It is also quite early on the west
coast, so he might reply soonish. Nick uses MacOSX, so he might be
able to narrow it down quickly.

> thanks for helping anyway !

Well, if this is a bug we should fix it, but until someone can nail it
down to say XEmacs vs. Aquamacs we should hold off on opening a
ticket.

Cheers,

Michael

Nick Alexander

unread,
Feb 19, 2009, 11:19:24 AM2/19/09
to sage-devel
> It is also quite early on the west
> coast, so he might reply soonish. Nick uses MacOSX, so he might be
> able to narrow it down quickly.

He just woke up!

Let me make sure I know the situation: you have applied that small
patch, you have installed sage-mode-0.5.1 (from the wiki), and you are
running Aquamacs? (I haven't tried it with aquamacs.) Also, the
inline equations are being displayed correctly?

Nick

Nick Alexander

unread,
Feb 19, 2009, 11:41:46 AM2/19/09
to sage-...@googlegroups.com

On 19-Feb-09, at 2:24 AM, Pierre wrote:

>
> hello all,
>
> i've posted this in sage-support with no luck. Strikes me it might be
> for sage-devel...
>
> I've installed the latest package for emacs, now with sage-view. Wow !
> very very cool, all the bugs are gone.

Would that were true! There are plenty of bugs left, maybe you will
help me fix them :)

> I was wondering, however, how the plots work within sage-view : if i
> try
>
> P= plot(lambda x : sin(x), (-2,2))
>
> Then none of "P" or "show(P)" or anything lets me see the plot... with
> sage-view disabled, i can just ask for "P" and the default image
> viewer on my system starts with the png image, which is great.

I don't use this myself, so an error has slipped in: there seems to be
some problem with synching temporary directories correctly. I will
investigate and try to get a patch to you before the weekend.

Nick

Matthias Meulien

unread,
Feb 19, 2009, 11:56:38 AM2/19/09
to sage-devel
> Would that were true!  There are plenty of bugs left, maybe you will  
> help me fix them :)

I am currently working on `the multiple output bug'. More precisely,
in case we run the following code, three overlays should be inserted
in the sage buffer:

m = Matrix(QQ, 5)
m.randomize()
for i in range(3): m^i

Not so easy to fix...

Pierre

unread,
Feb 19, 2009, 12:54:43 PM2/19/09
to sage-devel
> Let me make sure I know the situation: you have applied that small  
> patch, you have installed sage-mode-0.5.1 (from the wiki), and you are  
> running Aquamacs?  

exactly, but in reverse order (applying the patch came last)

>(I haven't tried it with aquamacs.)  Also, the  
> inline equations are being displayed correctly?

yes, it's beautiful latex work ! it's just the plots. And again, i'm
not sure if the "correct" behaviour of sage-view is to insert the
plots in emacs or to start an external viewer, but i'd prefer the
latter (which is what happens with sage-view disabled). Indeed it's
one of the things i dislike with the notebook, not being able to have
the sage instructions in one window, and the plots, if any, in another.

Nick Alexander

unread,
Feb 19, 2009, 1:06:37 PM2/19/09
to sage-...@googlegroups.com

On 19-Feb-09, at 9:54 AM, Pierre wrote:

>
>> Let me make sure I know the situation: you have applied that small
>> patch, you have installed sage-mode-0.5.1 (from the wiki), and you
>> are
>> running Aquamacs?
>
> exactly, but in reverse order (applying the patch came last)

That's fine.

>> (I haven't tried it with aquamacs.) Also, the
>> inline equations are being displayed correctly?
>
> yes, it's beautiful latex work ! it's just the plots. And again, i'm
> not sure if the "correct" behaviour of sage-view is to insert the
> plots in emacs or to start an external viewer, but i'd prefer the
> latter (which is what happens with sage-view disabled).

Interesting. It's supposed to insert them inline... but that should
be a toggle, right? I'll work that up and post a patch.

Nick

Nick Alexander

unread,
Feb 19, 2009, 1:09:43 PM2/19/09
to sage-...@googlegroups.com

On 19-Feb-09, at 8:56 AM, Matthias Meulien wrote:

>
>> Would that were true! There are plenty of bugs left, maybe you will
>> help me fix them :)
>
> I am currently working on `the multiple output bug'. More precisely,
> in case we run the following code, three overlays should be inserted
> in the sage buffer:

I never tried to make this work, but I see now that it should not be
difficult.

> m = Matrix(QQ, 5)
> m.randomize()
> for i in range(3): m^i
>
> Not so easy to fix...

With the original code, yes. With the newer code that accumulates
output and post-processes it, not so hard.

Nick

Nick Alexander

unread,
Feb 19, 2009, 1:13:18 PM2/19/09
to sage-...@googlegroups.com
>> Not so easy to fix...
>
> With the original code, yes. With the newer code that accumulates
> output and post-processes it, not so hard.

Now I agree. The difficult part is having three latex processes with
three sentinels.

Nick

Nick Alexander

unread,
Feb 19, 2009, 4:15:54 PM2/19/09
to sage-...@googlegroups.com

On 19-Feb-09, at 9:54 AM, Pierre wrote:

sage-mode-0.5.2 is up at http://wiki.sagemath.org/sage-mode. It has
brief docs (very brief!) but you can now use sage-view-
{enable,disable}-inline-{plots,output} to toggle bits of behaviour.
In addition, multiple plots/output works better. Matthieu, you should
work with this one if you implement multiple sentinels for multiple
outputs.

As always, let me know what is borked.

Nick

Matthias Meulien

unread,
Feb 20, 2009, 7:24:52 AM2/20/09
to sage-...@googlegroups.com
> Now I agree. The difficult part is having three latex processes with
> three sentinels.

That's it!

I shifted to the version shipped with sage-mode-0.5.2 this morning. I'll
be away for a couple of days, so you'll hopefully get the multiple
outputs stuff in the middle of next week.

Regards,
--
Matthias

Pierre

unread,
Feb 23, 2009, 5:43:15 AM2/23/09
to sage-devel
brilliant ! 0.5.2 works really well ! the toggle idea is very nice : i
sense that i'm going to use both inline and external plots.

if i may add something to the list of bug reports, i'd say that python-
send-region and python-send-defun apparently do nothing. When i want
to send a part of a file (and C-c C-c is not appropriate), i use the
following function, it's very very silly but it works:

(defun sage-send-current-line ()
"send the current line to sage and moves point to the beginning of the
next line"
(interactive)
(message (concat "SAGE executing " (current-line-string)))
(process-send-string (get-buffer "*SAGE-main*")
(concat (current-line-string) "\n" ))
(next-line)
(beginning-of-line))

i bind this to C-c C-e (reminds me of C-x C-e for lisp evaluation, and
everything related to sage ought to start with C-c...) and it becomes
quite easy to send 4 or 5 lines to sage (thanks to the moving
cursor!). For a very large function definition, it would still be good
to have python-send-defun working.

cheers
pierre

mabshoff

unread,
Feb 23, 2009, 5:55:12 AM2/23/09
to sage-devel


On Feb 23, 2:43 am, Pierre <pierre.guil...@gmail.com> wrote:

Hi,
Sounds good to me. For those people with trac access I just created a
sage-mode component which defaults to being assigned to Nick. This
will hopefully make it easier to find and track sage-mode related
issues for Nick and sooner than later sage-mode should ship with Sage
per default anyway :)

> cheers
> pierre

Cheers,

Michael

Pierre

unread,
Feb 23, 2009, 5:58:12 AM2/23/09
to sage-devel
here's another trick i use, by the way. It simply attaches the current
buffer to sage, so you just need to go C-x C-s on your file in order
to send everything :

(defun sage-attach-current-buffer ()
"attach current .sage file"
(interactive)
(process-send-string (get-buffer "*SAGE-main*")
(concat
"attach \""
(buffer-file-name (current-buffer))
"\"\n")))

I don't know how well this would work with a .py file that's imported
as a module in the current sage session... is it possible to attach
modules ? i don't think so.

here's a last one:

(defun sage-add-to-path ()
"adds the path to the current buffer to the sage path"
(interactive)
(process-send-string (get-buffer "*SAGE-main*")
(concat
"import sys\n"
"import os\n"
"sys.path.append("
" os.path.split('"
(buffer-file-name (current-buffer))
"' )[0] )\n"
"print 'added to SAGE path:', sys.path[-1]\n")))


may be useful for "import" commands to work, sometimes.

pierre

Pierre

unread,
Feb 25, 2009, 4:16:51 AM2/25/09
to sage-devel
found another little bug. The function sage-view-disable-inline-plots
works fine when called interactively (after run-sage, that is) -- but
in my case it does not work when placed in sage-startup-hook as
suggested on the wiki page ! i mean i have

(add-hook 'sage-startup-hook 'sage-view-always 'sage-view-disable-
inline-plots)

in my .emacs, to no effect.

Nicolas M. Thiery

unread,
Mar 6, 2009, 11:30:34 AM3/6/09
to sage-...@googlegroups.com
Hi Nick!

On Thu, Feb 19, 2009 at 01:15:54PM -0800, Nick Alexander wrote:
> sage-mode-0.5.2 is up at http://wiki.sagemath.org/sage-mode. It has
> brief docs (very brief!) but you can now use sage-view-
> {enable,disable}-inline-{plots,output} to toggle bits of behaviour.
> In addition, multiple plots/output works better. Matthieu, you should
> work with this one if you implement multiple sentinels for multiple
> outputs.

Just wanted to take the occasion to finally thank you so much for
'rerun-sage', and the other improvements!

Cheers,
Nicolas
--
Nicolas M. Thiéry "Isil" <nth...@users.sf.net>
http://Nicolas.Thiery.name/

Nick Alexander

unread,
Mar 6, 2009, 12:17:45 PM3/6/09
to sage-...@googlegroups.com

On 6-Mar-09, at 8:30 AM, Nicolas M. Thiery wrote:

>
> Hi Nick!
>
> On Thu, Feb 19, 2009 at 01:15:54PM -0800, Nick Alexander wrote:
>> sage-mode-0.5.2 is up at http://wiki.sagemath.org/sage-mode. It has
>> brief docs (very brief!) but you can now use sage-view-
>> {enable,disable}-inline-{plots,output} to toggle bits of behaviour.
>> In addition, multiple plots/output works better. Matthieu, you
>> should
>> work with this one if you implement multiple sentinels for multiple
>> outputs.
>
> Just wanted to take the occasion to finally thank you so much for
> 'rerun-sage', and the other improvements!

You are very welcome. Matthias also sent a much improved version of
sage-view that I have yet to put on the wiki; sorry Matthias!

Nick

Reply all
Reply to author
Forward
0 new messages