tpapp / julia-repl

Run an inferior Julia REPL in a terminal inside Emacs
Other
171 stars 35 forks source link

evaluate function #6

Open tpapp opened 7 years ago

tpapp commented 7 years ago

Add the following functionality: when inside a function, select the whole body of the function and send it to the REPL, Similarly to C-c C-c in ESS. Should work with embedded functions.

function foo()
    function bar()
        # cursor here
    end
end

should send function foo() ... end.

Possibly the same machinery that is used for indentation in julia-mode can be used for selecting the relevant block.

giordano commented 7 years ago

This would be as difficult as calling mark-defun, but you need a proper definition of beginning-of-defun-function and end-of-defun-function and I think that julia-mode doesn't set them. Thus I think that most of the work should be done in the upstream mode. This is also closely related to #7.

Getting the end of defun is tricky, because you have to skip the end keywords of other blocks, like begin, for, etc... If I remember well, fortran-mode has a fairly robust implementation of this function.

MasonProtter commented 6 years ago

One thing that could be done as a stopgap solution is to just rely on the indentation. ie., once the editor sees function, every line after that is seen as part of that function until the indentation comes back to the same level as function. Obviously, this isn't ideal but it should cover most cases.

tpapp commented 6 years ago

Unfortunately, this would not work for functions with empty lines in them (which are not uncommon).

MasonProtter commented 6 years ago

Can’t we just make it ignore empty lines?

tpapp commented 6 years ago

Ignoring empty lines still does not solve the nested case in the issue.

Also, I have to admit that with Revise.jl, this issue is not as pressing as it once was.