Skip to content
/ devil Public
forked from susam/devil

Commit

Permalink
Support command sequences with special suffix
Browse files Browse the repository at this point in the history
This adds some special cases to `devil--find-command` based on the last
completely translated key press. If it is

1. C-g, then run `keyboard-quit` instead of doing any further lookups
2. C-h, then run `devil-describe-prefix-bindings`, which first translates the
key sequence and then calls `describe-bindings` with it.

`devil-describe-prefix-bindings` might also be assigned to
`prefix-help-command`.

In both cases the last key can either be entered via devil (e.g. ', h') or
directly (e.g. 'C-h).

Fixes susam#12
Fixes susam#26
  • Loading branch information
fbrosda committed Nov 24, 2024
1 parent c2dc9fc commit 6c9e500
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions devil.el
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ locally."
(describe-key key)
(funcall exit-function)))))

(defun devil-describe-prefix-bindings ()
"Describe possibly translated prefix."
(interactive)
(let* ((key (this-command-keys))
(parsed-key (kbd (devil--translate key)))
(prefix (substring parsed-key 0 (1- (length parsed-key)))))
(describe-bindings prefix)))


;;; Command Lookup ===================================================

Expand Down Expand Up @@ -393,16 +401,22 @@ TRANSLATED-KEY is translated further by invoking the `car' of
this list. Then this function is called recursively with the
`cdr' of this list."
(let* ((parsed-key (ignore-errors (kbd translated-key)))
(suffix (and (stringp parsed-key)
(substring parsed-key (1- (length parsed-key)))))
(binding (when parsed-key (key-binding parsed-key))))
(cond ((devil--incomplete-key-p translated-key)
(devil--log "Ignoring incomplete key: %s" translated-key)
nil)
((string= (kbd "C-g") suffix)
(devil--binding-result key nil #'keyboard-quit))
((keymapp binding)
(devil--log "Ignoring prefix key: %s" translated-key)
nil)
((commandp binding)
(devil--log "Found command: %s => %s" translated-key binding)
(devil--binding-result key translated-key binding))
((and suffix (char-equal help-char (string-to-char suffix)))
(devil--binding-result key nil #'devil-describe-prefix-bindings))
(t
(devil--log "Undefined key: %s => %s" translated-key binding)
(let ((fallback-key (when fallbacks (funcall (car fallbacks)
Expand Down

0 comments on commit 6c9e500

Please sign in to comment.