gcv / julia-snail

An Emacs development environment for Julia
GNU General Public License v3.0
235 stars 23 forks source link

Is it possible to use term instead of vterm #108

Closed reachtarunhere closed 2 years ago

reachtarunhere commented 2 years ago

I don't really like vterm as it hinders some use-cases of mine.

  1. Unable to complete snippets as buffer is read only
  2. Can't use Alt + Enter when editing a function inside repl. This is really useful when redefining functions.

I would be grateful if someone can help me understand how tightly coupled the code is with vterm and what changes can I make maybe in a fork or in the repo to allow people to select their term.

Thanks!

(I am aware of other projects like julia-repl which support term but so far julia-snail seems to have worked best for me.)

gcv commented 2 years ago

It’s not terribly difficult to replace vterm with another terminal implementation if you really want to do it. Just search for the string vterm in the Elisp code and replace the vterm API calls with whatever you want. I considered making the terminal back-end switchable, but decided it’s not worth the effort. I selected vterm for Snail because term.el is slow and buggy to the point of being unusable. It chokes on the Julia REPL on non-trivial output (like a matrix with long rows).

With regard to your problems, have you looked into vterm’s own configuration? vterm-keymap-exceptions and vterm-mode-map should help with the keyboard shortcut. I’m not sure about snippets, but it sounds like something that can be handled with a dozen lines of Elisp that determines the snippet you want (perhaps with an auxiliary buffer to prompt for input) and uses vterm-send-string to insert it.

reachtarunhere commented 2 years ago

Thanks for the response.

I solved the first issue in a rather hacky way and am sharing it here if it should help anyone, vterm for some reason does not have a defined function for M-ret. They do have functions for pretty much every other combination. Using the --insert function they have just tends to insert some random characters without actually inserting a newline.

So instead I mapped M-ret to M-i. (Pressing M-ret would send M-i to the REPL) and then made some changes to the REPL to make M-i work.

Code added to my init.el

(define-key vterm-mode-map (kbd "M-RET") #'vterm-send-M-i)

Code added to my ~/.julia/config/startup.jl

import REPL.LineEdit

const mykeys = Dict{Any,Any}(
    "\ei" => (s, o...)->LineEdit.edit_insert_newline(s)
)

function customize_keys(repl)
    repl.interface = REPL.setup_interface(repl; extra_repl_keymap = mykeys)
end

atreplinit(customize_keys)

I also tried the vterm-send-string trick where I open up a minibuffer. This however has very bad UX. By default yasnippet doesn't support expansions in mini-buffers. And even after resolving that. Multi line expansions break for me.

This really has to do with a lack of line-mode in vterm unlike term/ansi-term which leads to not really great integration with emacs. However, I agree that those packages have their own performance issues.

Thanks for helping anyway!