Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created August 24, 2010 20:56
Show Gist options
  • Save kosh04/548292 to your computer and use it in GitHub Desktop.
Save kosh04/548292 to your computer and use it in GitHub Desktop.
;; -*- xyzzy -*-
#|
グローバルキーマップで[C-x RET]をプレフィックスキーに、その後
ローカルキーマップで[C-x RET]にコマンドを定義するとdescribe-keyなどの
キーシーケンス読み込み時に最長一致のグローバルマップを(この例では)選んでしまう。
※実際のコマンドでは最短一致のキーコマンドを呼び出すらしい
そのため、最短一致のキーを返すように修正する。
【例】
(global-set-key '(#\C-x #\RET #\f) 'change-fileio-encoding)
(define-key *html+-mode-map* '(#\C-x #\C-m) 'html+-select-link-dialog)
;; Before
M-x: describe-key [C-x RET f] ;=> change-fileio-encoding
;; After
M-x: describe-key [C-x RET] ;=> html+select-link-dialog
|#
(defun ed::read-key-sequence (local global minor-maps &optional prompt)
(do ((result)
(keymap (append (list (current-selection-keymap)) minor-maps
(list local) (list global))))
((progn
(when prompt
(minibuffer-prompt "~a~{~:c ~}" prompt result))
(or (some #'commandp keymap)
(notany #'keymapp keymap)))
(if (consp (cdr result))
result
(car result)))
(let ((c (read-char *keyboard*)))
(setq result (nconc result (list c)))
(setq keymap (mapcan #'(lambda (x)
(when (keymapp x)
(let ((y (lookup-keymap x c)))
(and y (list y)))))
keymap)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment