Skip to content

Commit

Permalink
Simplify the hint part of each head
Browse files Browse the repository at this point in the history
* hydra.el (defhydra): All heads that don't have a hint, will get "" as
  hint. The behavior will remain the same.
(hydra--head-property): Simplify, since plist is now always `cdddr'.
(hydra--hint): Simplify, heads always have length at least 3. Simplify,
third element is always a string or nil.
  • Loading branch information
abo-abo committed Feb 24, 2015
1 parent c413b5f commit f231dc0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ should be a single statement. Wrap it in an interactive lambda."
(defun hydra--head-property (h prop &optional default)
"Return for Hydra head H the value of property PROP.
Return DEFAULT if PROP is not in H."
(let ((plist (if (or (stringp (cl-caddr h))
(null (cl-caddr h)))
(cl-cdddr h)
(cddr h))))
(let ((plist (cl-cdddr h)))
(if (memq prop h)
(plist-get plist prop)
default)))
Expand Down Expand Up @@ -396,20 +393,18 @@ NAME, BODY, DOCSTRING and HEADS are parameters to `defhydra'."
(dolist (h heads)
(let ((val (assoc (cadr h) alist))
(pstr (hydra-fontify-head h body)))
(unless (and (> (length h) 2)
(null (cl-caddr h)))
(unless (null (cl-caddr h))
(if val
(setf (cadr val)
(concat (cadr val) " " pstr))
(push
(cons (cadr h)
(cons pstr
(and (stringp (cl-caddr h)) (cl-caddr h))))
(cons pstr (cl-caddr h)))
alist)))))
(mapconcat
(lambda (x)
(format
(if (cdr x)
(if (> (length (cdr x)) 0)
(concat "[%s]: " (cdr x))
"%s")
(car x)))
Expand Down Expand Up @@ -703,6 +698,15 @@ result of `defhydra'."
(setq docstring "hydra"))
(when (keywordp (car body))
(setq body (cons nil (cons nil body))))
(dolist (h heads)
(cond ((< (length h) 2)
(error "Each head should have at least two items: %S" h))
((= (length h) 2)
(setcdr (cdr h) '("")))
((or (null (cl-caddr h))
(stringp (cl-caddr h))))
(t
(setcdr (cdr h) (cons "" (cddr h))))))
(let* ((keymap (copy-keymap hydra-base-map))
(body-name (intern (format "%S/body" name)))
(body-key (unless (hydra--callablep body)
Expand Down

0 comments on commit f231dc0

Please sign in to comment.