[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8dec3cd 70/72: Allow for a %s(test) spec in docstring
From: |
Oleh Krehel |
Subject: |
[elpa] master 8dec3cd 70/72: Allow for a %s(test) spec in docstring |
Date: |
Fri, 06 Mar 2015 13:04:26 +0000 |
branch: master
commit 8dec3cd07bbc7dfae0ef1de356ebd6da87aa8a70
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow for a %s(test) spec in docstring
* hydra.el (hydra-set-transient-map): Avoid compiler warnings.
(hydra--format): Add s? to regex.
- %(test) will translate to (format "%S" (test))
- %s(test) will translate to (format "%s" (test))
The width specifiers should work for both, e.g. % -10(test) or %
-10s(test).
Example:
(defhydra hydra-marked-items (dired-mode-map "")
"
Number of marked items: %(length (dired-get-marked-files))
Directory size: %s(shell-command-to-string \"du -hs\")
"
("m" dired-mark "mark"))
Fixes #65.
---
hydra.el | 34 ++++++++++++++++++++--------------
1 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/hydra.el b/hydra.el
index 308de99..dcdf03b 100644
--- a/hydra.el
+++ b/hydra.el
@@ -83,7 +83,8 @@
(if (fboundp 'set-transient-map)
'set-transient-map
(lambda (map keep-pred &optional on-exit)
- (set-temporary-overlay-map map (hydra--pred on-exit)))))
+ (with-no-warnings
+ (set-temporary-overlay-map map (hydra--pred on-exit))))))
(defun hydra--pred (on-exit)
"Generate a predicate on whether to continue the Hydra state.
@@ -463,7 +464,7 @@ The expressions can be auto-expanded according to NAME."
offset)
(while (setq start
(string-match
- "\\(?:%\\(
?-?[0-9]*\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_\\(
?-?[0-9]*\\)\\([a-z-~A-Z0-9/|?<>={}]+\\)_\\)"
+ "\\(?:%\\(
?-?[0-9]*s?\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_\\(
?-?[0-9]*\\)\\([a-z-~A-Z0-9/|?<>={}]+\\)_\\)"
docstring start))
(cond ((eq ?_ (aref (match-string 0 docstring) 0))
(let* ((key (match-string 4 docstring))
@@ -488,18 +489,23 @@ The expressions can be auto-expanded according to NAME."
nil nil docstring 0)))
(t
- (setq offset
- (with-temp-buffer
- (insert (substring docstring (1+ start)))
- (goto-char (point-min))
- (push (read (current-buffer)) varlist)
- (point)))
- (setq docstring
- (concat
- (substring docstring 0 start)
- "%" (match-string 1 docstring) "S"
- (substring docstring
- (+ (match-end 2) offset -2)))))))
+ (let* ((spec (match-string 1 docstring))
+ (lspec (length spec)))
+ (setq offset
+ (with-temp-buffer
+ (insert (substring docstring (+ 1 start (length spec))))
+ (goto-char (point-min))
+ (push (read (current-buffer)) varlist)
+ (point)))
+ (when (or (zerop lspec)
+ (/= (aref spec (1- (length spec))) ?s))
+ (setq spec (concat spec "S")))
+ (setq docstring
+ (concat
+ (substring docstring 0 start)
+ "%" spec
+ (substring docstring
+ (+ (match-end 2) offset -2))))))))
(if (eq ?\n (aref docstring 0))
`(concat (format ,(substring docstring 1) ,@(nreverse varlist))
,rest)
- [elpa] master eb1e0fc 58/72: Don't bind nil heads in outside keymaps, (continued)
- [elpa] master eb1e0fc 58/72: Don't bind nil heads in outside keymaps, Oleh Krehel, 2015/03/06
- [elpa] master 41ec124 50/72: Avoid generating multiple defuns with same name, Oleh Krehel, 2015/03/06
- [elpa] master db0415e 49/72: hydra.el (hydra-keyboard-quit): Add, Oleh Krehel, 2015/03/06
- [elpa] master 55682e7 57/72: Improve handling of heads with duplicate cmd, Oleh Krehel, 2015/03/06
- [elpa] master 7de26d0 64/72: Add `hydra-repeat': hydra-specific `repeat', Oleh Krehel, 2015/03/06
- [elpa] master f231dc0 55/72: Simplify the hint part of each head, Oleh Krehel, 2015/03/06
- [elpa] master 764f4b6 67/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master 8e90037 65/72: Add some features for generating tables, Oleh Krehel, 2015/03/06
- [elpa] master 3040f45 61/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master e1e2e3e 69/72: lv.el (lv-window): Bind `golden-ratio-mode' to nil, Oleh Krehel, 2015/03/06
- [elpa] master 8dec3cd 70/72: Allow for a %s(test) spec in docstring,
Oleh Krehel <=
- [elpa] master 9fc928b 63/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master 989ed95 53/72: Rename compat toggle - :nonheads -> :foreign-keys, Oleh Krehel, 2015/03/06
- [elpa] master 9c68e0a 68/72: Add :timeout option to hydra body, Oleh Krehel, 2015/03/06
- [elpa] master e342c33 71/72: hydra-ox.el: Emulate org-mode export dispatch, Oleh Krehel, 2015/03/06
- [elpa] master 6d6bbd4 62/72: hydra.el (hydra-key-format-spec): set default to "%s", Oleh Krehel, 2015/03/06
- [elpa] master 26c3fee 60/72: Remove hydra-exit, Oleh Krehel, 2015/03/06
- [elpa] master 41f98bd 66/72: Don't wrap `hydra-repeat', Oleh Krehel, 2015/03/06
- [elpa] master 3222b0c 72/72: Merge commit 'e342c330807fdd09adba974611122d1c95bdf07d' from hydra, Oleh Krehel, 2015/03/06