[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master cb28124 44/72: Allow sexps in Ruby-style docstrings
From: |
Oleh Krehel |
Subject: |
[elpa] master cb28124 44/72: Allow sexps in Ruby-style docstrings |
Date: |
Fri, 06 Mar 2015 13:04:16 +0000 |
branch: master
commit cb28124af8c9f0231662f4d184d1cbc8d7e83a86
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow sexps in Ruby-style docstrings
* hydra.el (hydra--format): Improve. No error handling or checking yet,
but should work fine if the docstring is correct.
* hydra-test.el (hydra-format-with-sexp): Add test.
Fixes #42.
---
hydra-test.el | 15 ++++++++++++++-
hydra.el | 45 +++++++++++++++++++++++++++++++++------------
2 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/hydra-test.el b/hydra-test.el
index fe02d6d..ae3e4c7 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -697,7 +697,20 @@ _f_ auto-fill-mode: %`auto-fill-function
% 3s auto-fill-mode: %S
" "{a}" abbrev-mode "{d}" debug-on-error "{f}" auto-fill-function) "[[q]]:
quit"))))
-
+(ert-deftest hydra-format-with-sexp ()
+ (should (equal
+ (let ((hydra-fontify-head-function
+ 'hydra-fontify-head-greyscale))
+ (hydra--format
+ '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"
+ "{n}"
+ (progn
+ (message "checking")
+ (buffer-narrowed-p)))
+ "[[q]]: cancel"))))
(provide 'hydra-test)
diff --git a/hydra.el b/hydra.el
index 5ea4640..ca3e23a 100644
--- a/hydra.el
+++ b/hydra.el
@@ -378,21 +378,42 @@ The expressions can be auto-expanded according to NAME."
(body-color (hydra--body-color body))
(prefix (symbol-name name))
(start 0)
- varlist)
+ varlist
+ offset)
(while (setq start
(string-match
- "\\(?:%\\(
?-?[0-9]*\\)`\\([a-z-A-Z/0-9]+\\)\\)\\|\\(?:_\\([a-z-~A-Z]+\\)_\\)"
+ "\\(?:%\\(
?-?[0-9]*\\)\\(`[a-z-A-Z/0-9]+\\|(\\)\\)\\|\\(?:_\\([a-z-~A-Z]+\\)_\\)"
docstring start))
- (if (eq ?_ (aref (match-string 0 docstring) 0))
- (let* ((key (match-string 3 docstring))
- (head (assoc key heads)))
- (if head
- (progn
- (push (hydra-fontify-head head body) varlist)
- (setq docstring (replace-match "% 3s" nil nil docstring)))
- (error "Unrecognized key: _%s_" key)))
- (push (hydra--unalias-var (match-string 2 docstring) prefix) varlist)
- (setq docstring (replace-match (concat "%" (match-string 1 docstring)
"S") nil nil docstring 0))))
+ (cond ((eq ?_ (aref (match-string 0 docstring) 0))
+ (let* ((key (match-string 3 docstring))
+ (head (assoc key heads)))
+ (if head
+ (progn
+ (push (hydra-fontify-head head body) varlist)
+ (setq docstring (replace-match "% 3s" nil nil docstring)))
+ (error "Unrecognized key: _%s_" key))))
+
+ ((eq ?` (aref (match-string 2 docstring) 0))
+ (push (hydra--unalias-var
+ (substring (match-string 2 docstring) 1) prefix) varlist)
+ (setq docstring
+ (replace-match
+ (concat "%" (match-string 1 docstring) "S")
+ 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)))))))
(if (eq ?\n (aref docstring 0))
`(concat (format ,docstring ,@(nreverse varlist))
,rest)
- [elpa] master a4c4eb6 36/72: Add example for `Buffer-menu-mode', (continued)
- [elpa] master a4c4eb6 36/72: Add example for `Buffer-menu-mode', Oleh Krehel, 2015/03/06
- [elpa] master 88b32d5 24/72: hydra.el (hydra--hint): Add exception, Oleh Krehel, 2015/03/06
- [elpa] master c41c932 31/72: README.md: fix tables, Oleh Krehel, 2015/03/06
- [elpa] master 1eebfed 34/72: Allow `format'-style width specifiers in docstring, Oleh Krehel, 2015/03/06
- [elpa] master e962ff1 39/72: hydra.el: remove no :pre, :post restriction for Emacs<24.4, Oleh Krehel, 2015/03/06
- [elpa] master a6c6a55 38/72: Improve compatibility for Emacs <= 24.3, Oleh Krehel, 2015/03/06
- [elpa] master 2c01db0 42/72: hydra.el (hydra--handle-nonhead): Update signature, Oleh Krehel, 2015/03/06
- [elpa] master a71b76e 35/72: Intercept quit signals, Oleh Krehel, 2015/03/06
- [elpa] master ae70e9a 41/72: Fix pink and teal Hydras running :post, Oleh Krehel, 2015/03/06
- [elpa] master 71d70f6 46/72: Add :body-pre switch, Oleh Krehel, 2015/03/06
- [elpa] master cb28124 44/72: Allow sexps in Ruby-style docstrings,
Oleh Krehel <=
- [elpa] master ace99b3 51/72: hydra.el (hydra--make-defun): Update signature, Oleh Krehel, 2015/03/06
- [elpa] master efcffc0 45/72: hydra-examples.el: Add example 9, Oleh Krehel, 2015/03/06
- [elpa] master ef1f61d 40/72: hydra.el (hydra--handle-nonhead): Fix bug, Oleh Krehel, 2015/03/06
- [elpa] master 2eddb83 43/72: hydra-test.el (hydra-format): New test, Oleh Krehel, 2015/03/06
- [elpa] master 5242aad 48/72: Fix :exit t / :exit nil inheritance issue, Oleh Krehel, 2015/03/06
- [elpa] master 0f733d8 37/72: Add an option to fontify heads in a custom way, Oleh Krehel, 2015/03/06
- [elpa] master c413b5f 54/72: Allow for a custom key format spec in docstrings, Oleh Krehel, 2015/03/06
- [elpa] master 54004d2 52/72: hydra.el (hydra-verbose): New defcustom, Oleh Krehel, 2015/03/06
- [elpa] master 0d9c95e 47/72: Update README.md, Oleh Krehel, 2015/03/06
- [elpa] master 3c06695 56/72: Amend the key regex in docstring to include <>, Oleh Krehel, 2015/03/06