Skip to content

Commit 4f8c087

Browse files
author
Dan Sutton
committed
Helper method to register functions
rather than having to `(push '(....))` and remember the structure, now you can just `resize-window-add-choice` and use some eldoc lovin'
1 parent e487973 commit 4f8c087

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

resize-window.el

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,9 @@ CHOICE is a \(key function description allows-capital\)."
187187
(resize-window--choice-documentation choice))))
188188

189189
(defun resize-window--get-documentation-strings ()
190-
(cl-reduce (lambda (c1 c2)
191-
(concat c1 c2 "\n"))
192-
(mapcar 'resize-window--display-choice
193-
resize-window-dispatch-alist)))
190+
(mapconcat #'identity (mapcar 'resize-window--display-choice
191+
resize-window-dispatch-alist)
192+
"\n"))
194193

195194
(defun resize-window--make-background ()
196195
"Place a background over the current window."
@@ -312,5 +311,24 @@ If no SIZE is given, extend by `resize-window-default-argument`"
312311
(set-window-configuration config)
313312
(resize-window--create-overlay))))
314313

314+
(defvar resize-window--capital-letters (number-sequence ?A ?Z))
315+
(defvar resize-window--lower-letters (number-sequence ?a ?z))
316+
317+
(defun resize-window--key-available? (key)
318+
(let ((keys (mapcar #'resize-window--choice-keybinding resize-window-dispatch-alist)))
319+
(not (member key keys))))
320+
321+
(defun resize-window-add-choice (key func doc &optional allows-capitals)
322+
"Register a function for resize-window.
323+
KEY is the char (eg ?c) that should invoke the FUNC. DOC is a doc
324+
string for the help menu, and optional ALLOWS-CAPITALS should be
325+
t or nil. Functions should be of zero arity if they do not allow
326+
capitals, and should be of optional single arity if they allow
327+
capitals. Invoking with the capital will pass the capital
328+
argument."
329+
(if (resize-window--key-available? key)
330+
(push (list key func doc allows-capitals) resize-window-dispatch-alist)
331+
(message "The `%s` key is already taken for resize-window." (char-to-string key))))
332+
315333
(provide 'resize-window)
316334
;;; resize-window.el ends here

test/resize-window-test.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@
5151
(resize-window-uppercase-argument)))
5252
(should (equal resize-window-fine-argument
5353
(resize-window-lowercase-argument)))))
54+
55+
(ert-deftest resize-window--key-already-used-tests ()
56+
(should (resize-window--key-available? ?e))
57+
(should-not (resize-window--key-available? ?n)))

0 commit comments

Comments
 (0)