branch: master commit 8dec3cd07bbc7dfae0ef1de356ebd6da87aa8a70 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
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)