gptel-transient: Avoid clashes with the custom directive key (#219)
gptel-transient (gptel--system-prompt-setup): When assigning keys to directives, avoid clashes with the system-message edit key (`h`), and use an arbitrary unused key if no mnemonic key assignments are possible.
This commit is contained in:
parent
8ba07d042c
commit
149261ee79
1 changed files with 5 additions and 9 deletions
|
@ -185,22 +185,18 @@ which see."
|
||||||
(transient-parse-suffixes
|
(transient-parse-suffixes
|
||||||
'gptel-system-prompt
|
'gptel-system-prompt
|
||||||
(cl-loop for (type . prompt) in gptel-directives
|
(cl-loop for (type . prompt) in gptel-directives
|
||||||
with taken
|
;; Avoid clashes with the custom directive key
|
||||||
|
with unused-keys = (delete ?h (number-sequence ?a ?z))
|
||||||
with width = (window-width)
|
with width = (window-width)
|
||||||
for name = (symbol-name type)
|
for name = (symbol-name type)
|
||||||
for key =
|
for key = (seq-find (lambda (k) (member k unused-keys)) name (seq-first unused-keys))
|
||||||
(let ((idx 0) pos)
|
do (setq unused-keys (delete key unused-keys))
|
||||||
(while (or (not pos) (member pos taken))
|
|
||||||
(setq pos (substring name idx (1+ idx)))
|
|
||||||
(cl-incf idx))
|
|
||||||
(push pos taken)
|
|
||||||
pos)
|
|
||||||
;; The explicit declaration ":transient transient--do-return" here
|
;; The explicit declaration ":transient transient--do-return" here
|
||||||
;; appears to be required for Transient v0.5 and up. Without it, these
|
;; appears to be required for Transient v0.5 and up. Without it, these
|
||||||
;; are treated as suffixes when invoking `gptel-system-prompt' directly,
|
;; are treated as suffixes when invoking `gptel-system-prompt' directly,
|
||||||
;; and infixes when going through `gptel-menu'.
|
;; and infixes when going through `gptel-menu'.
|
||||||
;; TODO: Raise an issue with Transient.
|
;; TODO: Raise an issue with Transient.
|
||||||
collect (list (key-description key)
|
collect (list (key-description (list key))
|
||||||
(concat (capitalize name) " "
|
(concat (capitalize name) " "
|
||||||
(propertize " " 'display '(space :align-to 20))
|
(propertize " " 'display '(space :align-to 20))
|
||||||
(propertize
|
(propertize
|
||||||
|
|
Loading…
Add table
Reference in a new issue