emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master efcffc0 45/72: hydra-examples.el: Add example 9


From: Oleh Krehel
Subject: [elpa] master efcffc0 45/72: hydra-examples.el: Add example 9
Date: Fri, 06 Mar 2015 13:04:16 +0000

branch: master
commit efcffc037042d9cfebb5b8a62c396e737615d0eb
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    hydra-examples.el: Add example 9
---
 hydra-examples.el |   16 ++++++++++++++++
 hydra-test.el     |    5 ++---
 hydra.el          |    2 +-
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/hydra-examples.el b/hydra-examples.el
index fbe77ee..50773b0 100644
--- a/hydra-examples.el
+++ b/hydra-examples.el
@@ -218,6 +218,22 @@ _~_: modified
   ("q" quit-window "quit" :color blue))
 ;; Recommended binding:
 ;; (define-key Buffer-menu-mode-map "." 'hydra-buffer-menu/body)
+;;** Example 9: s-expressions in the docstring
+;; You can inline s-expresssions into the docstring like this:
+(when (bound-and-true-p hydra-examples-verbatim)
+  (eval-after-load 'dired
+    (defhydra hydra-marked-items (dired-mode-map "")
+      "
+Number of marked items: %(length (dired-get-marked-files))
+"
+      ("m" dired-mark "mark"))))
+
+;; This results in the following dynamic docstring:
+;;
+;;     (format "Number of marked items: %S\n"
+;;             (length (dired-get-marked-files)))
+;;
+;; You can use `format'-style width specs, e.g. % 10(length nil).
 
 ;;* Windmove helpers
 (require 'windmove)
diff --git a/hydra-test.el b/hydra-test.el
index ae3e4c7..2a6b579 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -691,8 +691,7 @@ _f_ auto-fill-mode:    %`auto-fill-function
     ("t" toggle-truncate-lines nil)
     ("w" whitespace-mode nil)
     ("q" nil "quit"))))
-           '(concat (format "
-% 3s abbrev-mode:       %S
+           '(concat (format "% 3s abbrev-mode:       %S
 % 3s debug-on-error:    %S
 % 3s auto-fill-mode:    %S
 " "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[[q]]: 
quit"))))
@@ -705,7 +704,7 @@ _f_ auto-fill-mode:    %`auto-fill-function
               'hydra-toggle nil
               "\n_n_ narrow-or-widen-dwim %(progn (message 
\"checking\")(buffer-narrowed-p))asdf\n"
               '(("n" narrow-to-region nil) ("q" nil "cancel"))))
-           '(concat (format "\n% 3s narrow-or-widen-dwim %Sasdf\n"
+           '(concat (format "% 3s narrow-or-widen-dwim %Sasdf\n"
                      "{n}"
                      (progn
                        (message "checking")
diff --git a/hydra.el b/hydra.el
index ca3e23a..a7114ed 100644
--- a/hydra.el
+++ b/hydra.el
@@ -415,7 +415,7 @@ The expressions can be auto-expanded according to NAME."
                     (substring docstring
                                (+ (match-end 2) offset -2)))))))
     (if (eq ?\n (aref docstring 0))
-        `(concat (format ,docstring ,@(nreverse varlist))
+        `(concat (format ,(substring docstring 1) ,@(nreverse varlist))
                  ,rest)
       `(format ,(concat docstring ": " rest ".")))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]