sagemath / sage-shell-mode

Emacs front end for SageMath
GNU General Public License v3.0
98 stars 16 forks source link

improvements sage-shell:send-doctest #24

Closed mantepse closed 7 years ago

mantepse commented 7 years ago

a sugestion for sage-shell:send-doctest: it would be great if it would not "leave" the current docstring.

By example, suppose I have

def foo(bar):
    """Do something really cool.

    sage: foo(1)
    yippe

    sage: foo(2)
    yes
    """

Then doing "sage-shell:send-doctest" in the line with foo(2) will move point to the next appearance of "sage: ", which may be anywhere.

It would be great if sage-shell-mode would "restrict" attention to the current docstring. (This worked in sage-mode.)

Besides: how can I bind sage-shell:send-doctest to a key in my .emacs? (I can only do it interactively in the scratch. with

(sage-shell:define-keys sage-shell:sage-mode-map "C-c C-j" 'sage-shell:send-doctest)

but if I put this into .emacs, emacs complains at startup.

Another observation: when I am in a Sage Document buffer, sage-shell:send-doctest doesn't like to send the first line. To reproduce, do

sage: ColoredPermutations?

move point to the first sage:, and do sage-shell:send-doctest...

stakemori commented 7 years ago

Thanks for suggesting. I will investigate the implementation of sage-send-doctest in sage-mode.

Besides: how can I bind sage-shell:send-doctest to a key in my .emacs? (I can only do it interactively in the scratch.

Packages in Melpa use autoload to reduce the start up time of Emacs. You can bind the key as follows:

(with-eval-after-load 'sage-shell-mode
  (define-key sage-mode-map (kbd "C-c C-j") 'sage-shell:send-doctest))

You need to put this code after (package-initialize) and (sage-shell:define-alias). If you don't mind the start up time, you can write as follows.

(package-initialize)
(require 'sage-shell-mode)
(sage-shell:define-alias)
(define-key sage-mode-map (kbd "C-c C-j") 'sage-shell:send-doctest)

Another observation: when I am in a Sage Document buffer, sage-shell:send-doctest doesn't like to send the first line.

With the current implementation, the point has to be before the sage: prompt. I will fix it.

mantepse commented 7 years ago

Thank you! Your support is wonderful!

stakemori commented 7 years ago

I fixed this in recent commits. Please update and try it. I also added sage-shell:send-all-doctests which evaluates all doctests in the current docstring. You can call it by C-u C-c C-j.

mantepse commented 7 years ago

It works sometimes, but not always. Here is a testcase:

class Foo():
    r"""
    A class modelling foo

    EXAMPLES::

        sage: 1+1
        2

    """
    def bang(self):
        r"""
        doit

        TESTS::

            sage: 2+3
            5
        """
        pass

Hitting C-c d (by the way: why not C-c C-d?) on the first sage: 1+1 line puts point on the sage: 2+3 line...

stakemori commented 7 years ago

@mantepse, thanks for reporting. I thought it was an expected behavior since sage-mode uses end-of-defun and end-of-defun sometimes returns the end point of the class.

I just fixed this in e8ca471d473ff7973e22149cbd03da2c789b21cf. I also fixed sage-shell:send-all-doctests and change the key-bind (C-c d => C-c C-d).

mantepse commented 7 years ago

Thank you!

besides: do you use some kind of testsuite to make sure nothing breaks?

stakemori commented 7 years ago

besides: do you use some kind of testsuite to make sure nothing breaks?

Yes. I use ert for unit testing. I wrote tests in https://github.com/sagemath/sage-shell-mode/blob/master/test/sage-shell-mode-test.el. But I write unit tests for low level functions. I usually test interactive functions such as sage-shell:send-doctest by hand.

mantepse commented 7 years ago

I think you can close this. I use sage-shell-mode every day, and C-c C-d roughly once a minute, and didn't notice any unexpected behaviour! Thank you so much!

BTW: C-c C-d is actually a very clever key binding for me!

stakemori commented 7 years ago

@mantepse, thank you for your report.