Skip to content

Commit

Permalink
refac(create-macro): store the assigned keys in a list
Browse files Browse the repository at this point in the history
Adds new variable `ship-mate-command-keys` that stores the keys that
were assigned for a given command.
  • Loading branch information
Walheimat committed Oct 29, 2024
1 parent 132249f commit 509f999
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion ship-mate.el
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ Each command created by `ship-mate-create-command' will
history. The general structure is ([COMMAND-SYMBOL] .
HASH-MAP<PROJECT-ROOT, HISTORY>).")

(defvar ship-mate-command-keys nil
"List of commands and their associated keys.
Each command created by `ship-mate-create-command' will add a new entry
in the form of ([COMMAND-SYMBOL] . KEY) if a key could be found.")

(defvar ship-mate-environment nil
"The project environment.
Expand Down Expand Up @@ -1003,7 +1009,9 @@ command."
`(push ,(symbol-name name) ship-mate-multiple))

,(if key
`(define-key ship-mate-command-map ,key ',function-name)
`(progn
(define-key ship-mate-command-map ,key ',function-name)
(add-to-list 'ship-mate-command-keys ',(cons name key)))
`(ship-mate--warn ,(format "Failed to find eligible key for `%s'" name)))

(put ',default-var 'safe-local-variable #'ship-mate-command--valid-default-p))))))
Expand Down
12 changes: 9 additions & 3 deletions test/ship-mate-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@
(interactive "P")
(ship-mate-command 'test arg))
(setq ship-mate-commands (plist-put ship-mate-commands 'test hash-table))
(define-key ship-mate-command-map "t" 'ship-mate-test)
(progn
(define-key ship-mate-command-map "t" 'ship-mate-test)
(add-to-list 'ship-mate-command-keys '(test . "t")))
(put 'ship-mate-test-default-cmd 'safe-local-variable #'ship-mate-command--valid-default-p)))

(bydi-match-expansion
Expand All @@ -591,7 +593,9 @@
(interactive "P")
(ship-mate-command 'test arg))
(setq ship-mate-commands (plist-put ship-mate-commands 'test hash-table))
(define-key ship-mate-command-map "t" 'ship-mate-test)
(progn
(define-key ship-mate-command-map "t" 'ship-mate-test)
(add-to-list 'ship-mate-command-keys '(test . "t")))
(put 'ship-mate-test-default-cmd 'safe-local-variable #'ship-mate-command--valid-default-p)))

(bydi-match-expansion
Expand All @@ -604,7 +608,9 @@
(ship-mate-command 'test arg))
(setq ship-mate-commands (plist-put ship-mate-commands 'test hash-table))
(push "test" ship-mate-multiple)
(define-key ship-mate-command-map "t" 'ship-mate-test)
(progn
(define-key ship-mate-command-map "t" 'ship-mate-test)
(add-to-list 'ship-mate-command-keys '(test . "t")))
(put 'ship-mate-test-default-cmd 'safe-local-variable #'ship-mate-command--valid-default-p)))

(setq key nil)
Expand Down

0 comments on commit 509f999

Please sign in to comment.