在 Emacs term-mode 中使用 f-keys 的最佳实践

Best practice for using f-keys in Emacs term-mode

我一直在寻找在 Emacs term-mode 中使用 f 键的规范方法,因为我是 运行 需要它们的控制台应用程序。

是否已经有提供此功能的软件包?

我写了以下内容来映射 f 键,但这似乎不是最佳解决方案:

(defvar f-key-defs
  (let ((fkeys nil))
    (dotimes (i 12)
      (push (cons (intern (concat "f" (int-to-string (1+ i))))
                  (format "\e[%d~" (+ i (if (> i 4) 12 11))))
            fkeys))
    fkeys))

(defun send-f-key ()
  "Send an f-key escape sequence to the sub-process."
  (interactive)
  (term-send-raw-string (alist-get last-input-event f-key-defs)))

(dotimes (i 12)
  (define-key term-raw-map
    (vector (intern (concat "f" (int-to-string (1+ i))))
    #'send-f-key))

它对我来说看起来不是很理想(我调整了您的代码以使用 dotimesterm-send-raw-string)。默认情况下提供此功能可能很有意义,因此我建议您 M-x report-emacs-bug 请求此新功能(包括您的代码作为可能的解决方案)。