(defun my-read-mb-lines (prompt some-keyseq)
(let ((keymap (copy-keymap minibuffer-local-map)))
(define-key keymap (kbd "RET") 'newline)
(define-key keymap some-keyseq 'exit-minibuffer)
(read-from-minibuffer prompt nil keymap)))
调用示例:
(my-read-mb-lines "Insert text (C-s to submit): " (kbd "C-s"))
'let' 块创建 minibuffer 的默认键盘映射的本地副本。接下来的两次“define-key”调用修改了键盘映射副本。之后,“read-from-minibuffer”将修改后的键映射传递给 minibuffer 以在提示用户时使用(而不是其默认键映射,“minibuffer-local-map”)。
FWIW,Cj 默认映射到“exit-minibuffer”,可以写一个简化版本:
(defun my-simplified-read-mb-lines (prompt)
(let ((keymap (copy-keymap minibuffer-local-map)))
(define-key keymap (kbd "RET") 'newline)
(read-from-minibuffer prompt nil keymap)))
调用示例:
(my-simplified-read-mb-lines "Insert text (C-j to submit): ")