Fix yanking text into terminal

* eat.el (eat-yank): Use simpler, saner and better approach to get the
yanked string instead of the previous stupid, insane and buggy
approach.
* eat.el (eat-yank-pop): Remove, because it's not cancel the text
already sent to the terminal.
* eat.el (eat-yank-from-kill-ring): New function.  Behaves essentially
the same the previous (not properly working) 'eat-yank-pop'.
* eat.el (eat-semi-char-mode-map, eat-eshell-semi-char-mode-map):
Replace 'eat-yank-pop' with 'eat-yank-from-kill-ring'.
This commit is contained in:
Akib Azmain Turja 2022-12-10 15:37:09 +06:00
parent 12a5fb72b2
commit 51eebc562b
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B

55
eat.el
View file

@ -4580,44 +4580,27 @@ ARG is passed to `yank', which see."
(interactive "*P")
(when eat--terminal
(funcall eat--synchronize-scroll-function)
(cl-letf* ((inhibit-read-only t)
(insert-for-yank (symbol-function #'insert-for-yank))
((symbol-function #'insert-for-yank)
(lambda (&rest args)
(cl-letf (((symbol-function #'insert)
(lambda (&rest args)
(eat-send-string-as-yank
eat--terminal
(mapconcat (lambda (arg)
(if (stringp arg)
arg
(string arg)))
args "")))))
(apply insert-for-yank args)))))
(yank arg))))
(eat-send-string-as-yank
eat--terminal (let ((yank-hook yank-transform-functions))
(with-temp-buffer
(setq-local yank-transform-functions yank-hook)
(yank arg)
(buffer-string))))))
(defun eat-yank-pop (&optional arg)
"Same as `yank-pop', but for Eat.
(defun eat-yank-from-kill-ring (string &optional arg)
"Same as `yank-from-kill-ring', but for Eat.
ARG is passed to `yank-pop', which see."
(interactive "p")
STRING and ARG are passed to `yank-pop', which see."
(interactive (list (read-from-kill-ring "Yank from kill-ring: ")
current-prefix-arg))
(when eat--terminal
(funcall eat--synchronize-scroll-function)
(cl-letf* ((inhibit-read-only t)
(insert-for-yank (symbol-function #'insert-for-yank))
((symbol-function #'insert-for-yank)
(lambda (&rest args)
(cl-letf (((symbol-function #'insert)
(lambda (&rest args)
(eat-send-string-as-yank
eat--terminal
(mapconcat (lambda (arg)
(if (stringp arg)
arg
(string arg)))
args "")))))
(apply insert-for-yank args)))))
(yank-pop arg))))
(eat-send-string-as-yank
eat--terminal (let ((yank-hook yank-transform-functions))
(with-temp-buffer
(setq-local yank-transform-functions yank-hook)
(yank-from-kill-ring string arg)
(buffer-string))))))
;; When changing these keymaps, be sure to update the manual, README
;; and commentary.
@ -4640,7 +4623,7 @@ ARG is passed to `yank-pop', which see."
[?\e ?!] [?\e ?&] [?\C-y] [?\e ?y]))))
(define-key map [?\C-q] #'eat-quoted-input)
(define-key map [?\C-y] #'eat-yank)
(define-key map [?\M-y] #'eat-yank-pop)
(define-key map [?\M-y] #'eat-yank-from-kill-ring)
(define-key map [?\C-c ?\C-c] #'eat-self-input)
(define-key map [?\C-c ?\C-e] #'eat-emacs-mode)
(define-key map [remap insert-char] #'eat-input-char)
@ -5260,7 +5243,7 @@ PROGRAM can be a shell command."
[?\e ?!] [?\e ?&] [?\C-y] [?\e ?y]))))
(define-key map [?\C-q] #'eat-quoted-input)
(define-key map [?\C-y] #'eat-yank)
(define-key map [?\M-y] #'eat-yank-pop)
(define-key map [?\M-y] #'eat-yank-from-kill-ring)
(define-key map [?\C-c ?\C-e] #'eat-eshell-emacs-mode)
(define-key map [remap insert-char] #'eat-input-char)
map)