this post was submitted on 14 Nov 2023
2 points (100.0% liked)

Emacs

313 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

I have this code:

(defun send-raw-key-fun (str)
  (lexical-let ((str str))
    (lambda ()
      (interactive)
      (term-send-raw-string (read-kbd-macro str)))))

 (define-key term-raw-map (kbd "C-c c") (send-raw-key-fun "C-c"))

and it doesn't work anymore with ansi-term. I'm not able to end the process inside.

Got error:

(wrong-type-argument stringp [3])

Does anyone know what to do to make this code work again?

top 1 comments
sorted by: hot top controversial new old
[–] 7890yuiop@alien.top 1 points 1 year ago

Looks like a bug (whether documentation or code) as read-kbd-macro still claims to return a string if possible, but nowadays it forcibly returns a vector. Please M-x report-emacs-bug to get that clarified.

You could extract a string of characters from the vector:

(mapconcat (lambda (event)
             (and (characterp event)
                  (char-to-string event)))
           (read-kbd-macro "C-c"))

But if you look at the code for read-kbd-macro you'll see that it calls this:

(defun edmacro-parse-keys (string &optional _need-vector)
  (let ((result (kbd string)))
    (if (stringp result)
        (seq-into result 'vector)
      result)))

Hence the string value you wanted is coming from kbd:

(kbd "C-c") => "^C"

There are of course arguments you can pass to kbd which won't return a string, but that would always have been the case for your code, and presumably you're not attempting to use any of those.