emacs-libvterm icon indicating copy to clipboard operation
emacs-libvterm copied to clipboard

M-/ (dabbrev-expand) requires buffer to be writable

Open sje30 opened this issue 5 years ago • 6 comments

Hi,

if I use M-/ (dabbrev-expand) in a vterm buffer, I get the error:

command-execute: Buffer is read-only: #<buffer vterm<3>>

I'm relatively new to vterm (but not Emacs); I can see that toggling read-only with C-x C-q allows dabbrev-expand to work. Is there any reason why read-only is on? I'd regard dabbrev-expand has completion similar to TAB completion.

sje30 avatar Jul 10 '20 12:07 sje30

The reason vterm buffers are read-only is that we have to properly send the keys to the underlying shell. Just writing on the buffer is not enough.

I am surprised if dabbrev-expand works once you toogle read only. It may write something on screen, but I suspect that those character are not sent to the shell. Am I wrong?

Sbozzolo avatar Jul 16 '20 12:07 Sbozzolo

Thanks, and you were right. Although it completes in the buffer, when I hit RET the completed text does not get sent to the shell.

sje30 avatar Jul 17 '20 21:07 sje30

I am reopening this. It shouldn't be too difficult to implement a fix, but I haven't looked into this yet.

Sbozzolo avatar Jul 20 '20 14:07 Sbozzolo

Hello, here's what I found. I miss the last steps.

Disable read-only mode, use dabrrev, insert what was completed to vterm:

    ;; user types "foo" and wants to complete:
    (vterm-insert (s-chop-prefix dabbrev--last-abbreviation dabbrev--last-expansion))
    ;;                                          ^^ foo                                  ^^ foo_bar  => append "_bar" to the existing "foo".   

This constructs a usable line for vterm.

I looked for dabbrev hooks to do this automatically after an expansion but couldn't find hooks.

I tried to re-bind M-/ to a custom function, but I wasn't able to make it take precedence^^

(defun my-vterm-dabbrev ()
         (call-interactively #'dabbrev-expand)
         (vterm-insert (s-chop-prefix dabbrev--last-abbreviation dabbrev--last-expansion)))

(define-key vterm-mode-map [M-/]    #'my-vterm-dabbrev)  ;; it still calls dabbrev-expand directly.

vindarel avatar Dec 29 '20 11:12 vindarel

https://github.com/t0yv0/t0yv0-emacs/blob/e8dfd5422105e77a7a66203c9cabfbd74e6e3c21/t0yv0-ware.el#L24 FWIW I've got something working for myself by dropping to lower-level primitives such as dabbrev--find-expansion.

t0yv0 avatar Aug 14 '23 01:08 t0yv0