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

[Suggestion] interactive vterm-send-key instead of vterm-define-key

Open Inc0n opened this issue 2 years ago • 1 comments

Make vterm-send-key interactive, frees out a lot of function definitions, and could be a more flexible approach.

(defun vterm-translate-event-to-args (event)
  (let ((modifiers (event-modifiers event))
	(base (event-basic-type event)))
    (list (char-to-string base)
	  (memq 'shift modifiers)
	  (memq 'meta modifiers)
	  (memq 'control modifiers))))

(defun vterm-send-key ((key &optional shift meta ctrl accept-proc-output))
  (interactive (if (string= (this-command-keys) (string last-command-event))
		   (vterm-translate-event-to-args last-command-event)
		 (user-error "cannot send this key %s" (this-command-keys))))
  ...)

Now just bind them to keys, for example:

(define-key vterm-mode-map [?\M-f] #'vterm-send-key)

Pressing M-f in a vterm buffer will send M-f approperiately, as it will get translated using last-command-event with the correct modifier and base flag.

This method is very similar to vterm-send, except this can send whatever key that is just pressed.

Inc0n avatar Jun 24 '22 13:06 Inc0n

It has been some time since, my suggestion, which I personally would like to see happen to take place in vterm.

This change effectively would eliminate 26 + 78 = 104 vterm-send--- function definitions. Two things should happen to the implementation:

  1. The macro vterm-define-key is removed and its associated macro expansions
  2. All vterm-mode-map keys are mapped to the interactive version of #'vterm-send-key

If I had missed anything, please let me know. If there is some potential roadblocks that I may not be aware of, please let me know also.

Inc0n avatar Aug 05 '22 19:08 Inc0n

see #618 #619 #620

jixiuf avatar Aug 20 '22 15:08 jixiuf

Issue closed as it has been addressed.

Inc0n avatar Aug 22 '22 11:08 Inc0n