M-/ (dabbrev-expand) requires buffer to be writable
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.
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?
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.
I am reopening this. It shouldn't be too difficult to implement a fix, but I haven't looked into this yet.
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.
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.