]> code.delx.au - gnu-emacs-elpa/log
gnu-emacs-elpa
9 years agohydra.el (hydra--format): Amend key regex
hura [Sat, 28 Feb 2015 01:01:57 +0000 (20:01 -0500)]
hydra.el (hydra--format): Amend key regex

Recognize the '{' and '}' keys.

9 years agoDon't wrap `hydra-repeat'
Oleh Krehel [Fri, 27 Feb 2015 19:32:09 +0000 (20:32 +0100)]
Don't wrap `hydra-repeat'

* hydra.el (hydra--delete-duplicates): Update.
(hydra--vconcat): Trim trailing spaces.

* hydra-test.el (hydra-red-error): Update test.
(hydra--table): Update test.

9 years agoAdd some features for generating tables
Oleh Krehel [Fri, 27 Feb 2015 18:05:43 +0000 (19:05 +0100)]
Add some features for generating tables

* hydra.el (hydra--pad): New defun.
(hydra--matrix): New defun.
(hydra--cell): New defun.
(hydra--vconcat): New defun.
(hydra-cell-format): New defcustom.
(hydra--table): New defun.
(hydra-reset-radios): New defun.
(defhydra): Allow docstring to be eval-able.
(defhydradio): Don't define `.../reset-radios', instead define
`.../names' that can be passed to `hydra-reset-radios'.
(hydra-multipop): New defmacro.
(hydra--radio): Update the order - the docstring is now a mandatory
second arg, value is the optional third.

* hydra-test.el (defhydradio): Update test.
(hydra--pad): Add test.
(hydra--matrix): Add test.
(hydra--cell): Add test.
(hydra--vconcat): Add test.
(hydra--table): Add test.

9 years agoAdd `hydra-repeat': hydra-specific `repeat'
Oleh Krehel [Fri, 27 Feb 2015 12:15:13 +0000 (13:15 +0100)]
Add `hydra-repeat': hydra-specific `repeat'

* hydra.el (hydra-repeat): New defun.
(hydra-repeat--command): New defvar.
(hydra-repeat--prefix-arg): New defvar.

Example:

(defhydra hydra-vi ()
  "vi"
  ("h" backward-char)
  ("j" next-line)
  ("k" previous-line)
  ("l" forward-char)
  ("." hydra-repeat))
(global-set-key (kbd "C-v") 'hydra-vi/body)

"C-v 4l.." will result in movement forward by 4 chars 3 times: first
time from "4l", the other two from "..".

Fixes #59.

9 years agohydra.el (hydra--format): Amend key regex
François Févotte [Thu, 26 Feb 2015 15:43:34 +0000 (11:43 -0400)]
hydra.el (hydra--format): Amend key regex

Recognize the '=' key.

9 years agohydra.el (hydra-key-format-spec): set default to "%s"
Oleh Krehel [Wed, 25 Feb 2015 15:56:19 +0000 (16:56 +0100)]
hydra.el (hydra-key-format-spec): set default to "%s"

* hydra-test.el (hydra-format): Update test.
(hydra-format-with-sexp): Update test.

9 years agohydra.el (hydra--format): Amend key regex
Oleh Krehel [Wed, 25 Feb 2015 10:37:58 +0000 (11:37 +0100)]
hydra.el (hydra--format): Amend key regex

Re #50.

9 years agoRemove hydra-exit
Oleh Krehel [Tue, 24 Feb 2015 18:20:46 +0000 (19:20 +0100)]
Remove hydra-exit

* hydra-test.el: Revert tests.

* hydra.el (hydra-exit): Delete, since `hydra-exit' doesn't run :post.
(hydra--delete-duplicates): Simplify.
(defhydra): Simplify.

Hydras with nil body will still not be bound in outside keymaps.

Re #48
Fixes #53

9 years agolv.el (lv-window): set-window-parameter 'no-other-window
Oleh Krehel [Tue, 24 Feb 2015 17:34:11 +0000 (18:34 +0100)]
lv.el (lv-window): set-window-parameter 'no-other-window

9 years agoDon't bind nil heads in outside keymaps
Oleh Krehel [Tue, 24 Feb 2015 14:50:49 +0000 (15:50 +0100)]
Don't bind nil heads in outside keymaps

* hydra.el (hydra-exit): New command to be used for nil heads.
(hydra--delete-duplicates): Update for `hydra-exit'.
(defhydra): Don't bind `hydra-exit' in outside keymaps.

* hydra-test.el (hydra-blue-toggle): Update test.
(hydra-amaranth-vi): Update test.

Fixes #48.

9 years agoImprove handling of heads with duplicate cmd
Oleh Krehel [Tue, 24 Feb 2015 14:31:46 +0000 (15:31 +0100)]
Improve handling of heads with duplicate cmd

hydra.el (hydra--delete-duplicates): Modify :cmd-name property of
duplicate head to to name of the head that it duplicates.
Heads are considered duplicate if their CMD and COLOR is the same.
The first of the duplicates gets a defun, the rest call it.

* hydra.el (defhydra): Bring heads into a uniform notation. If a
  docstring is missing, set it to "". Set :cmd-name property to the
  head's name.

* hydra-test.el: Add tests.

Fixes #52.

9 years agoAmend the key regex in docstring to include <>
Oleh Krehel [Tue, 24 Feb 2015 11:02:27 +0000 (12:02 +0100)]
Amend the key regex in docstring to include <>

Re #50.

9 years agoSimplify the hint part of each head
Oleh Krehel [Tue, 24 Feb 2015 10:42:00 +0000 (11:42 +0100)]
Simplify the hint part of each head

* 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.

9 years agoAllow for a custom key format spec in docstrings
Oleh Krehel [Mon, 23 Feb 2015 22:03:13 +0000 (23:03 +0100)]
Allow for a custom key format spec in docstrings

* hydra.el (hydra-key-format-spec): New defcustom.
(hydra--format): Use `hydra-key-format-spec'. Allow for 0-9 and / in key
bindings.

Here's an example of how to use a flexible format spec for each key:

(let (hydra-key-format-spec)
  (defhydra hydra-zoom (global-map "<f2>")
    "
zoom: _g_reater _ -5l_esser re_ 7c_enter zer_0_"
    ("g" text-scale-increase nil)
    ("l" text-scale-decrease nil)
    ("c" recenter-top-bottom nil)
    ("0" (text-scale-set 0) nil :exit t)))

Fixes #50.

9 years agoRename compat toggle - :nonheads -> :foreign-keys
Oleh Krehel [Mon, 23 Feb 2015 17:40:12 +0000 (18:40 +0100)]
Rename compat toggle - :nonheads -> :foreign-keys

* hydra-test.el: Add tests.

* hydra.el (hydra--head-color): Update.
(hydra--body-foreign-keys): New defun.
(hydra--body-color): Update.
(hydra--handle-nonhead): Update.

* README.md: Update.

9 years agohydra.el (hydra-verbose): New defcustom
Oleh Krehel [Mon, 23 Feb 2015 15:45:45 +0000 (16:45 +0100)]
hydra.el (hydra-verbose): New defcustom

* hydra.el (hydra--head-color): Switch from `error' to `hydra--complain'
  in one case.
(hydra--complain): New defun.

Fixes #47.

9 years agohydra.el (hydra--make-defun): Update signature
Oleh Krehel [Mon, 23 Feb 2015 14:46:48 +0000 (15:46 +0100)]
hydra.el (hydra--make-defun): Update signature

9 years agoAvoid generating multiple defuns with same name
Oleh Krehel [Mon, 23 Feb 2015 14:12:17 +0000 (15:12 +0100)]
Avoid generating multiple defuns with same name

* hydra.el (hydra--head-name): New defun.
(hydra--delete-duplicates): New defun.
(defhydra): Update to use `hydra--delete-duplicates' and `hydra--head-name'.

9 years agohydra.el (hydra-keyboard-quit): Add
Oleh Krehel [Mon, 23 Feb 2015 13:50:25 +0000 (14:50 +0100)]
hydra.el (hydra-keyboard-quit): Add

* hydra.el (hydra--handle-nonhead): Use `hydra-keyboard-quit'.
(defhydra): Work-around multiple definitions.

* hydra-test.el (hydra-red-error): Update test.
(hydra-blue-toggle): Update test.

9 years agoFix :exit t / :exit nil inheritance issue
Oleh Krehel [Mon, 23 Feb 2015 10:54:29 +0000 (11:54 +0100)]
Fix :exit t / :exit nil inheritance issue

* hydra-test.el (hydra-compat-colors): Add test.

* hydra.el (hydra--aggregate-color): New defun.
(hydra--head-color): Update.

Fixes #46.

9 years agoUpdate README.md
hura [Sun, 22 Feb 2015 20:14:26 +0000 (15:14 -0500)]
Update README.md

9 years agoAdd :body-pre switch
Oleh Krehel [Sat, 21 Feb 2015 16:44:34 +0000 (17:44 +0100)]
Add :body-pre switch

It will be run as the first thing in the prefix/body function.

re #41

Example:

    (defvar hydra-vi/init-pos nil)
    (defhydra hydra-vi (:body-pre (setq hydra-vi/init-pos (point))
                        :color pink)
      "vi"
      ;; arrows
      ("h" backward-char)
      ("j" next-line)
      ("k" previous-line)
      ("l" forward-char)
      ;; exit points
      ("q" (goto-char hydra-vi/init-pos) "ins" :exit t)
      ("C-n" (forward-line 1) nil :exit t)
      ("C-p" (forward-line -1) nil :exit t))

9 years agohydra-examples.el: Add example 9
Oleh Krehel [Sat, 21 Feb 2015 16:43:40 +0000 (17:43 +0100)]
hydra-examples.el: Add example 9

9 years agoAllow sexps in Ruby-style docstrings
Oleh Krehel [Sat, 21 Feb 2015 10:15:16 +0000 (11:15 +0100)]
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.

9 years agohydra-test.el (hydra-format): New test
Oleh Krehel [Sat, 21 Feb 2015 09:33:14 +0000 (10:33 +0100)]
hydra-test.el (hydra-format): New test

* hydra.el (hydra-fontify-head-greyscale): New defun. Usable as
  `hydra-fontify-head-function'.

9 years agohydra.el (hydra--handle-nonhead): Update signature
Oleh Krehel [Sat, 21 Feb 2015 09:21:06 +0000 (10:21 +0100)]
hydra.el (hydra--handle-nonhead): Update signature

* hydra.el (hydra--format): Update docstring.
(hydra-pink-fallback): Add docstring.
(defhydra): Update call to `hydra--handle-nonhead'.

9 years agoFix pink and teal Hydras running :post
Oleh Krehel [Fri, 20 Feb 2015 17:35:04 +0000 (18:35 +0100)]
Fix pink and teal Hydras running :post

* hydra.el (hydra--make-defun): Update.

9 years agohydra.el (hydra--handle-nonhead): Fix bug
Oleh Krehel [Fri, 20 Feb 2015 17:17:26 +0000 (18:17 +0100)]
hydra.el (hydra--handle-nonhead): Fix bug

9 years agohydra.el: remove no :pre, :post restriction for Emacs<24.4
Oleh Krehel [Fri, 20 Feb 2015 17:16:52 +0000 (18:16 +0100)]
hydra.el: remove no :pre, :post restriction for Emacs<24.4

9 years agoImprove compatibility for Emacs <= 24.3
Oleh Krehel [Fri, 20 Feb 2015 16:51:52 +0000 (17:51 +0100)]
Improve compatibility for Emacs <= 24.3

* hydra.el (hydra-set-transient-map): Always take 3 arguments.
(hydra--pred): New defun.
(hydra-disable): Update, `overriding-terminal-local-map' is actually
also bound in 24.3.

Fixes #29

9 years agoAdd an option to fontify heads in a custom way
Oleh Krehel [Fri, 20 Feb 2015 14:41:32 +0000 (15:41 +0100)]
Add an option to fontify heads in a custom way

* hydra.el (hydra--hint): Forward to `hydra-fontify-head'.
(hydra-fontify-head-function): New defvar.
(hydra-fontify-head-default): New defun that represents the classic
fontification behavior.
(hydra-fontify-head): Fontification dispatch - use
`hydra-fontify-head-default'
unless `hydra-fontify-head-function' is set.
(hydra--format): Forward to `hydra-fontify-head'.

Example:

    (setq hydra-fontify-head-function
          (lambda (head body)
            (let ((color (hydra--head-color head body)))
              (format
               (if (eq color 'blue)
                   "[%s]"
                 "{%s}") (car head)))))

Call `defhydra' here, then reset:

    (setq hydra-fontify-head-function nil)

Call another `defhydra' here.

9 years agoAdd example for `Buffer-menu-mode'
Oleh Krehel [Fri, 20 Feb 2015 13:18:21 +0000 (14:18 +0100)]
Add example for `Buffer-menu-mode'

9 years agoIntercept quit signals
Oleh Krehel [Fri, 20 Feb 2015 13:09:41 +0000 (14:09 +0100)]
Intercept quit signals

* hydra.el (hydra--format): Make keys wider.
(hydra--make-defun): Catch quit.
(hydra-pink-fallback): Catch quit.

* hydra-test.el: Update tests.

9 years agoAllow `format'-style width specifiers in docstring
Oleh Krehel [Fri, 20 Feb 2015 10:24:54 +0000 (11:24 +0100)]
Allow `format'-style width specifiers in docstring

* hydra.el (hydra--hint): Process less data.
(hydra--format): Change to add `format'-style width specifiers.

Example:

(defhydra hydra-toggle (:color pink)
  "
_a_ abbrev-mode:    % 4`abbrev-mode^^^^     _f_ auto-fill-mode:    %`auto-fill-function
_d_ debug-on-error: % 4`debug-on-error^     _t_ truncate-lines:    %`truncate-lines
_w_ whitespace-mode:% 4`whitespace-mode     _g_ golden-ratio-mode: %`golden-ratio-mode
"
  ("a" abbrev-mode nil)
  ("d" toggle-debug-on-error nil)
  ("f" auto-fill-mode nil)
  ("g" golden-ratio-mode nil)
  ("t" toggle-truncate-lines nil)
  ("w" whitespace-mode nil)
  ("q" nil "quit"))

Here, ^^^ represent empty characters used to compensate for the fact
that the lengths of variable symbols are different.
You can choose not to use them. The result will be the same, but your
code will look misaligned.

Fixes #39.

9 years agohydra.el (hydra-add-font-lock): Add `defhydradio'
Oleh Krehel [Fri, 20 Feb 2015 09:40:22 +0000 (10:40 +0100)]
hydra.el (hydra-add-font-lock): Add `defhydradio'

9 years agohydra.el (hydra--head-color): Improve
Oleh Krehel [Thu, 19 Feb 2015 21:23:14 +0000 (22:23 +0100)]
hydra.el (hydra--head-color): Improve

* hydra.el (hydra--face): Second arg should be BODY.
(hydra--head-color): Second arg should be BODY.

9 years agoREADME.md: fix tables
Oleh Krehel [Thu, 19 Feb 2015 20:53:32 +0000 (21:53 +0100)]
README.md: fix tables

9 years agoAdd compat color-less syntax
Oleh Krehel [Thu, 19 Feb 2015 20:45:01 +0000 (21:45 +0100)]
Add compat color-less syntax

* hydra.el (hydra--head-color): Adapt compat switches.
(hydra--body-color): Adapt compat switches.
(hydra--handle-nonhead): Move verbatim from `defhydra'.
(defhydra): Move verbatim to `hydra--handle-nonhead'.

* README.md: Update with two tables.

* hydra-test.el: Add compat tests.

New compat switches are:

- ":exit t" for ":color blue"
- ":nonheads warn" for ":color amaranth"
- ":nonheads warn :exit t" for ":color teal"
- ":nonheads run" for ":color pink"

See the compat tests to get the intuition of how both ways translate
between each other.

Fixes #27.

9 years agoGenerate a global resetter in `defhydradio'
Oleh Krehel [Thu, 19 Feb 2015 17:45:46 +0000 (18:45 +0100)]
Generate a global resetter in `defhydradio'

* hydra.el (defhydradio): `NAME/reset-radios' will be generated.
(hydra--quote-maybe): Don't quote nil.

* hydra-test.el: Update test.

9 years agohydra.el (defhydra): Fix typo
Oleh Krehel [Thu, 19 Feb 2015 17:29:12 +0000 (18:29 +0100)]
hydra.el (defhydra): Fix typo

Re #38

9 years agohydra.el (hydra-pink-fallback): Add
Oleh Krehel [Thu, 19 Feb 2015 17:13:11 +0000 (18:13 +0100)]
hydra.el (hydra-pink-fallback): Add

* hydra.el (defhydra): More advanced handling of the pink fallback.

Re #38.

9 years agoFix typos
Oleh Krehel [Thu, 19 Feb 2015 16:51:12 +0000 (17:51 +0100)]
Fix typos

* hydra.el (defhydra): Fix A/An and "aboring".

9 years agohydra-examples.el: Add example 7
Oleh Krehel [Thu, 19 Feb 2015 15:49:15 +0000 (16:49 +0100)]
hydra-examples.el: Add example 7

9 years agohydra.el (hydra--hint): Add exception
Oleh Krehel [Thu, 19 Feb 2015 15:48:31 +0000 (16:48 +0100)]
hydra.el (hydra--hint): Add exception

* hydra.el (hydra--hint): Don't add semicolon to docstrings that start
  with a newline.

9 years agohydra.el (hydra--head-color): fix for teal color
Oleh Krehel [Thu, 19 Feb 2015 15:06:48 +0000 (16:06 +0100)]
hydra.el (hydra--head-color): fix for teal color

9 years agoAdd teal body color
Oleh Krehel [Thu, 19 Feb 2015 14:56:17 +0000 (15:56 +0100)]
Add teal body color

* hydra.el (hydra-face-teal): New face.
(hydra--face): Update.
(defhydra): Teal color is the same as amaranth, except the heas inherit
blue instead of red.

This Hydra can reasonably be either blue or teal:

    (global-set-key
       (kbd "C-c C-v")
       (defhydra hydra-toggle (:color teal)
         "toggle"
         ("a" abbrev-mode "abbrev")
         ("d" toggle-debug-on-error "debug")
         ("f" auto-fill-mode "fill")
         ("t" toggle-truncate-lines "truncate")
         ("w" whitespace-mode "whitespace")
         ("q" nil "cancel")))

9 years agohydra.el (hydra--hint): Take same arguments as `defhydra'
Oleh Krehel [Thu, 19 Feb 2015 14:50:50 +0000 (15:50 +0100)]
hydra.el (hydra--hint): Take same arguments as `defhydra'

9 years agoUpdate faces
Oleh Krehel [Thu, 19 Feb 2015 14:48:41 +0000 (15:48 +0100)]
Update faces

* hydra.el (hydra-face-red): Set default to actual color red.
(hydra-face-blue): Set default to actual color blue.
(hydra-face-amaranth): Explain better in the doc.
(hydra-face-pink): Explain better in the doc.

9 years agohydra.el (hydra--hint): Take same arguments as `defhydra'
Oleh Krehel [Thu, 19 Feb 2015 14:15:01 +0000 (15:15 +0100)]
hydra.el (hydra--hint): Take same arguments as `defhydra'

9 years agohydra.el (hydra--message): Take same arguments as `defhydra'
Oleh Krehel [Thu, 19 Feb 2015 14:06:34 +0000 (15:06 +0100)]
hydra.el (hydra--message): Take same arguments as `defhydra'

9 years agoMinor refactoring
Oleh Krehel [Thu, 19 Feb 2015 14:02:11 +0000 (15:02 +0100)]
Minor refactoring

* hydra.el (hydra--head-color): Rename from `hydra--color'.
(hydra--body-color): New defun.
(hydra--message): First arg isn't pre-processed by `hydra--hint'.
(defhydra): Update call to `hydra-message'.

9 years agoAllow for Ruby-style Hydra docstrings
Oleh Krehel [Thu, 19 Feb 2015 13:19:18 +0000 (14:19 +0100)]
Allow for Ruby-style Hydra docstrings

* hydra.el (hydra--unalias-var): New defun.
(hydra--format): New defun.
(hydra--message): Use `hydra-format' instead of a static string.
Update signature.
(defhydra): Add a warning the pink Hydras can't yet handle unbound
prefix, e.g. "C-x". Update arguments given to `hydra--message'.

* hydra-test.el: Update tests, only hint functions were slightly
  affected.

Example of using the newfound functionality:

    (defhydra hydra-toggle (:color pink)
      "
    _a_ abbrev-mode:       %`abbrev-mode
    _d_ debug-on-error:    %`debug-on-error
    _f_ auto-fill-mode:    %`auto-fill-function
    _g_ golden-ratio-mode: %`golden-ratio-mode
    _t_ truncate-lines:    %`truncate-lines
    _w_ whitespace-mode:   %`whitespace-mode

    "
      ("a" abbrev-mode nil)
      ("d" toggle-debug-on-error nil)
      ("f" auto-fill-mode nil)
      ("g" golden-ratio-mode nil)
      ("t" toggle-truncate-lines nil)
      ("w" whitespace-mode nil)
      ("q" nil "cancel"))

    (global-set-key (kbd "C-c C-v") 'hydra-toggle/body)

Here, "Foo %`abbrev-mode" becomes equivelent to:
    (format "Foo %S" abbrev-mode).

And "_a_" becomes equivalent to:
    (propertize "a" 'face 'hydra-face-pink).

The hints for all heads except "q" have been set to nil, since their
equivalent is already displayed in the docstring.

9 years agoAdd pink body color
Oleh Krehel [Thu, 19 Feb 2015 08:34:29 +0000 (09:34 +0100)]
Add pink body color

* hydra.el (hydra-face-pink): New face.
(hydra--face): Update.
(defhydra): Pink is a variation on amaranth. It still intercepts all
bindings, but will call the intercepted bindings if they're valid.

Re #38.

9 years agohydra.el (defhydra): Update doc
Oleh Krehel [Wed, 18 Feb 2015 17:28:59 +0000 (18:28 +0100)]
hydra.el (defhydra): Update doc

9 years agolv.el (lv-message): Don't deactivate mark
Oleh Krehel [Wed, 18 Feb 2015 16:35:36 +0000 (17:35 +0100)]
lv.el (lv-message): Don't deactivate mark

Fixes #37

9 years agohydra.el (hydra-cleanup): reorder
Oleh Krehel [Tue, 17 Feb 2015 23:22:46 +0000 (00:22 +0100)]
hydra.el (hydra-cleanup): reorder

Re #36

9 years agoFix unintentional recursion in Emacs 25
Oleh Krehel [Tue, 17 Feb 2015 19:08:06 +0000 (20:08 +0100)]
Fix unintentional recursion in Emacs 25

* hydra.el (hydra-cleanup): New function.
(hydra-disable): Restore to previous version.
(hydra--make-defun): Don't call `hydra-disable' in `set-transient-map' -
call `hydra-cleanup' instead.

* hydra-test.el: Update.

Fixes #35.

9 years agohydra.el (defhydradio): New macro
Oleh Krehel [Tue, 17 Feb 2015 17:42:19 +0000 (18:42 +0100)]
hydra.el (defhydradio): New macro

* hydra.el (hydra--radio): New defun.
(hydra--quote-maybe): New defun.
(hydra--cycle-radio): New defun.

* hydra-test.el (defhydradio): New test.

9 years agoDon't clutter Echo Area
Oleh Krehel [Tue, 17 Feb 2015 14:30:09 +0000 (15:30 +0100)]
Don't clutter Echo Area

* lv.el (lv-wnd): New variable.
(lv-window): New defun to get a window similar in properties to Echo Area.
(lv-message): New defun, a replacement for `message', that writes to `lv-window'.

* hydra.el (hydra-lv): New defcustom. If nil, use the Echo Area,
  otherwise, use LV.
(hydra-disable): Add optional arg KILL-LV.
(hydra--message): New defun to dispatch on `hydra-lv'.
(hydra--make-defun): Prematurely disable with LV only for blue heads,
since regenerating LV window would cause screen tearing. No need for
timeouts between `message' when using LV.  HINT argument is now a
function symbol that returns a string, instead of a plain string.
(defhydra): Generate a new defun with name `NAME/hint'.

* Makefile: Load lv.

* hydra-test.el: Update all tests.

* README.md: Update.

9 years agoRemove obsoletes
Oleh Krehel [Tue, 17 Feb 2015 14:12:40 +0000 (15:12 +0100)]
Remove obsoletes

* hydra.el (hydra-create): Remove

* hydra-examples.el (hydra-example-text-scale): Remove.
(hydra-example-move-window-splitter): Remove.
(hydra-example-goto-error): Remove.
(hydra-example-windmove): Remove

9 years ago`defhydra' should be indented as `defun'
Oleh Krehel [Sun, 15 Feb 2015 15:23:03 +0000 (16:23 +0100)]
`defhydra' should be indented as `defun'

9 years agoAdd option to font-lock `defhydra'
Oleh Krehel [Sat, 14 Feb 2015 20:03:03 +0000 (21:03 +0100)]
Add option to font-lock `defhydra'

* hydra.el (hydra-add-font-lock): New function.

Fixes #32.

9 years agohydra.el (hydra--make-defun): simplify
Oleh Krehel [Sat, 14 Feb 2015 20:02:23 +0000 (21:02 +0100)]
hydra.el (hydra--make-defun): simplify

9 years agoWarn about explict red heads on amaranth body
Oleh Krehel [Fri, 13 Feb 2015 16:10:14 +0000 (17:10 +0100)]
Warn about explict red heads on amaranth body

* hydra.el (defhydra): With amaranth body, all heads that aren't blue
become amaranth. Specifying red explicitly does nothing. Add a check and
warn when this happens.

re #29

9 years agoFix head color for heads with nil as HINT
Oleh Krehel [Mon, 9 Feb 2015 17:53:58 +0000 (18:53 +0100)]
Fix head color for heads with nil as HINT

hydra.el (hydra--head-property): Fix.

This head should work now:

    ("1" (text-scale-set 0) nil :bind nil :color blue)

9 years agohydra.el (hydra--hint): allow duplicate functions in heads
Oleh Krehel [Mon, 9 Feb 2015 17:33:13 +0000 (18:33 +0100)]
hydra.el (hydra--hint): allow duplicate functions in heads

* hydra.el (hydra--hint): Duplicate functions will be concatenated.

Example:

    (defhydra hydra-zoom (global-map "<f2>")
      "zoom"
      ("g" text-scale-increase "in")
      ("l" text-scale-decrease "out")
      ("0" (text-scale-set 0) "reset")
      ("1" (text-scale-set 0) :bind nil)
      ("2" (text-scale-set 0) :bind nil :color blue))

Here, the hint will be: "zoom: [g]: in, [l]: out, [0 1 2]: reset."
And "2" will be colored blue.

Fixes #26

9 years agoAllow some heads with no hints
Oleh Krehel [Mon, 9 Feb 2015 16:14:41 +0000 (17:14 +0100)]
Allow some heads with no hints

* hydra.el (hydra--hint): If the HINT part of HEAD is explicitely nil,
  omit it from the compound hint.

Example:

    (global-set-key
     (kbd "C-M-o")
     (defhydra hydra-window (:color amaranth)
       "window"
       ("h" windmove-left nil)
       ("j" windmove-down nil)
       ("k" windmove-up nil)
       ("l" windmove-right nil)
       ("v" (lambda ()
              (interactive)
              (split-window-right)
              (windmove-right))
            "vert")
       ("x" (lambda ()
              (interactive)
              (split-window-below)
              (windmove-down))
            "horz")
       ("q" nil "cancel")))

Here, "h", "j", "k", "l" will not be in the echo area.

9 years agoREADME.md: update
Oleh Krehel [Sun, 8 Feb 2015 14:15:06 +0000 (15:15 +0100)]
README.md: update

9 years agoAllow a sexp as head's CMD paramater
Oleh Krehel [Sun, 8 Feb 2015 14:07:12 +0000 (15:07 +0100)]
Allow a sexp as head's CMD paramater

* hydra.el (hydra--make-callable): New function.
(defhydra): Use `hydra--make-callable'. Now, head's CMD is either:
command name, nil, a sexp. In case of a sexp, it will be wrapped
unevaluated in an interactive lambda. You can use a `progn' to have many
statements in the sexp.

Fixes #25.

Example:

    (defhydra hydra-launcher (:color blue)
       "Launch"
       ("h" man "man")
       ("r" (browse-url "http://www.reddit.com/r/emacs/") "reddit")
       ("w" (browse-url "http://www.emacswiki.org/") "emacswiki")
       ("s" shell "shell")
       ("q" nil "cancel"))
    (global-set-key (kbd "C-c r") 'hydra-launcher/body)

9 years agoUpdate comments and mark the old examples obsolete
Oleh Krehel [Sun, 8 Feb 2015 13:28:37 +0000 (14:28 +0100)]
Update comments and mark the old examples obsolete

9 years agoAllow lambda :bind property for body and heads
Oleh Krehel [Sat, 7 Feb 2015 21:00:56 +0000 (22:00 +0100)]
Allow lambda :bind property for body and heads

* hydra.el (hydra--head-property): Clean up doc.
(hydra--make-defun): Clean up doc.
(defhydra): Improve doc.
Both body and heads recognize :bind property in their plist.
It can be either nil or a lambda of `global-set-key' format.

Example:

    (defhydra hydra-goto (global-map "M-g"
                          :bind
                          (lambda (key cmd)
                            (bind-key key cmd)))
      ("g" goto-line "goto-line" :bind global-set-key)
      ("c" goto-char "goto-char"))

Here, `global-set-key' will be used to bind `goto-line' to "M-g g".
And `bind-key' will be used to bind `goto-char' to "M-g c".
Note that since `bind-key' is a macro, it was necessary to wrap it
in a lambda.

Since this commit, it's not possible to pass a lambda instead of
the whole BODY arg, as was advertised before. Just put it on
:bind now.

9 years agoREADME.md: update
Oleh Krehel [Sat, 7 Feb 2015 17:20:31 +0000 (18:20 +0100)]
README.md: update

9 years ago`hydra/body' will pass the initial `current-prefix-arg' along
Oleh Krehel [Fri, 6 Feb 2015 17:13:16 +0000 (18:13 +0100)]
`hydra/body' will pass the initial `current-prefix-arg' along

* hydra.el (hydra--make-defun): Take an additional arg to paste as the
  last statement.
(defhydra): Set `hydra-foo/body' last statement to
`(setq prefix-arg current-prefix-arg)'.

* hydra-test.el: Update tests.

Example:

    (global-set-key
     (kbd "C-z")
     (defhydra hydra-vi ()
       "vi"
       ("l" forward-char)
       ("q" nil "quit")))

Now, "C-u C-z l" will result in (forward-char 4). All the other "l" will
normally call (forward-char 1), unless an additional prefix is given.

The previous behavior allowed only for "C-z C-u l" to get
(forward-char 4).

Fixes #21.

9 years agofix typo - single not singe
Jason Lewis [Fri, 6 Feb 2015 11:55:24 +0000 (22:55 +1100)]
fix typo - single not singe

9 years agoFix "catch 'hydra-disable"
Oleh Krehel [Fri, 6 Feb 2015 09:31:33 +0000 (10:31 +0100)]
Fix "catch 'hydra-disable"

* hydra.el (hydra--make-defun): `(catch 'hydra-disable ...)' should
  extend thoughout the whole defun. The scope was reduced by mistake
  earlier, now restoring.

* hydra-test.el: Update tests.

9 years agoUpdate semantics for local heads to `:bind nil'
Oleh Krehel [Fri, 6 Feb 2015 09:04:54 +0000 (10:04 +0100)]
Update semantics for local heads to `:bind nil'

* hydra.el (hydra--head-property): Accept an optional DEFAULT arg.
(defhydra): A head will not be bound in the body map when it has `:bind
nil' in its plist.

Example:

    (defhydra hydra-next-error (c++-mode-map "C-x")
      "next-error"
      ("`" next-error "next")
      ("j" next-error "next" :bind nil)
      ("k" previous-error "previous" :bind nil))

Here, only "C-x `" will be bound in `c++-mode-map', "C-x j" and "C-x k"
will not be bound.  However, e.g. "C-x `jjk" will be possible.

9 years agoSupport local hydra heads
François Févotte [Thu, 5 Feb 2015 22:35:35 +0000 (23:35 +0100)]
Support local hydra heads

Local heads are not bound in the global keymap, only in the transient keymap.

9 years agohydra.el (defhydra): Declare indent 2
Oleh Krehel [Thu, 5 Feb 2015 18:32:00 +0000 (19:32 +0100)]
hydra.el (defhydra): Declare indent 2

9 years agoAllow :pre and :post to be function symbols
Oleh Krehel [Thu, 5 Feb 2015 18:24:50 +0000 (19:24 +0100)]
Allow :pre and :post to be function symbols

* hydra.el (defhydra): :pre and :post are eihter sexps or function
  symbols.

Re #16.

Example:

    (defun hydra-vi/pre ()
      (set-cursor-color "#e52b50"))

    (defun hydra-vi/post ()
      (set-cursor-color "#ffffff"))

    (global-set-key
     (kbd "C-z")
     (defhydra hydra-vi
         (:pre hydra-vi/pre
               :post hydra-vi/post
               :color amaranth)
       "vi"
       ("l" forward-char)
       ("h" backward-char)
       ("j" next-line)
       ("k" previous-line)
       ("m" set-mark-command "mark")
       ("a" move-beginning-of-line "beg")
       ("e" move-end-of-line "end")
       ("d" delete-region "del" :color blue)
       ("y" kill-ring-save "yank" :color blue)
       ("q" nil "quit")))

9 years agohydra.el (hydra-keyboard-quit): New custom var
Oleh Krehel [Thu, 5 Feb 2015 17:50:39 +0000 (18:50 +0100)]
hydra.el (hydra-keyboard-quit): New custom var

* hydra.el (hydra-keyboard-quit): New custom var.
(defhydra): Bind `hydra-keyboard-quit' to disable an amaranth Hydra.

* hydra-test.el (hydra-amaranth-vi): Update test.

9 years agoMove defun-creating code into a defun
Oleh Krehel [Thu, 5 Feb 2015 17:27:58 +0000 (18:27 +0100)]
Move defun-creating code into a defun

* hydra.el (hydra--doc): New function.
(defhydra): Simplify.

* hydra-test.el: Update tests.

9 years agoUpdate :post for amaranth Hydras
Oleh Krehel [Thu, 5 Feb 2015 14:19:17 +0000 (15:19 +0100)]
Update :post for amaranth Hydras

* hydra.el (defhydra): Since the transient map isn't technically going
  away when a foreign key binding is pressed, don't call :post in that
  case. This means that only blue heads will call :post for Hydras with
  amaranth body.

Fixes #17.

9 years agohydra-test.el: update the test to not fail for older Emacs
Oleh Krehel [Thu, 5 Feb 2015 13:33:15 +0000 (14:33 +0100)]
hydra-test.el: update the test to not fail for older Emacs

9 years agoBump version
Oleh Krehel [Thu, 5 Feb 2015 13:17:26 +0000 (14:17 +0100)]
Bump version

9 years agohydra-test.el: add test
Oleh Krehel [Thu, 5 Feb 2015 13:13:43 +0000 (14:13 +0100)]
hydra-test.el: add test

* README.md: update.

9 years agoAdd amaranth (immortal) Hydras
Oleh Krehel [Thu, 5 Feb 2015 12:09:05 +0000 (13:09 +0100)]
Add amaranth (immortal) Hydras

* hydra.el (hydra-face-amaranth): New face.
(hydra--face): Update.
(defhydra): If the body color is amaranth, it's only possible to exit
this Hydra through a blue head. None of the other key bindings, even
"C-g" will work. There's a check in place that the current Hydra should
have at least one blue head.

Re #17.

Example:

    (defhydra hydra-vi
         (:pre
          (set-cursor-color "#40e0d0")
          :post
          (set-cursor-color "#ffffff")
          :color amaranth)
       "vi"
       ("l" forward-char)
       ("h" backward-char)
       ("j" next-line)
       ("k" previous-line)
       ("q" nil "quit"))

    (global-set-key (kbd "C-z") 'hydra-vi/body)

9 years agoREADME.md: update for 0.7.0
Oleh Krehel [Wed, 4 Feb 2015 16:44:04 +0000 (17:44 +0100)]
README.md: update for 0.7.0

9 years agoAdd :pre and :post clauses to Hydra body
Oleh Krehel [Wed, 4 Feb 2015 15:28:40 +0000 (16:28 +0100)]
Add :pre and :post clauses to Hydra body

* hydra.el (defhydra): the PLIST part of BODY argument now recognizes
  :pre and :post keys. These should be single Elisp statements,
  wrappable in a lambda. When you need more than one statement, use a
  `progn'.

:pre will be called by `hydra-foo/body', as well as by all heads.
:post will be called by the blue heads, as well as on Hydra termination
by a command that isn't a head.

Fixes #16.

An Example:

    (global-set-key
     (kbd "C-z")
     (defhydra hydra-vi
         (:pre
          (set-cursor-color "#40e0d0")
          :post
          (set-cursor-color "#ffffff"))
       "vi"
       ("l" forward-char)
       ("h" backward-char)
       ("j" next-line)
       ("k" previous-line)
       ("q" nil "quit")))

9 years agoUpdate the call order and allow called functions to exit
Oleh Krehel [Tue, 3 Feb 2015 17:43:24 +0000 (18:43 +0100)]
Update the call order and allow called functions to exit

* hydra.el (defhydra): First disable the transient map, then call red
  head, allowing it to throw `hydra-disable' to break, then re-set
  transient map.

  If the called function raises an error, display this error for a
  while, but still set the transient map.

* hydra-test.el: Update test.

Re #15.

9 years agoImprove the names of functions generated from lambdas
Oleh Krehel [Tue, 3 Feb 2015 17:09:12 +0000 (18:09 +0100)]
Improve the names of functions generated from lambdas

* hydra.el (defhydra): Improve.

Here, `hydra-window/lambda-v' function will be defined.

    (defhydra hydra-window ()
      "window"
      ("v" (lambda ()
             (interactive)
             (split-window-right)
             (windmove-right))
           "vert"))

9 years agoBump version
Oleh Krehel [Tue, 3 Feb 2015 16:13:29 +0000 (17:13 +0100)]
Bump version

* README.md: Update.

9 years agohydra.el (hydra-disable): adapt to Emacs 24.4.1
Oleh Krehel [Tue, 3 Feb 2015 14:49:55 +0000 (15:49 +0100)]
hydra.el (hydra-disable): adapt to Emacs 24.4.1

The old thing should work for Emacs 25, and some versions older than
24.4.1.

Fixes #14.

9 years agohydra-examples.el: splitters take numeric argument
Oleh Krehel [Tue, 3 Feb 2015 13:38:44 +0000 (14:38 +0100)]
hydra-examples.el: splitters take numeric argument

* hydra-examples.el (hydra-move-splitter-left): Take ARG.
(hydra-move-splitter-right): Take ARG.
(hydra-move-splitter-up): Take ARG.
(hydra-move-splitter-down): Take ARG.

9 years agoAdd support for `universal-argument' and `digit-argument'
Oleh Krehel [Tue, 3 Feb 2015 12:27:37 +0000 (13:27 +0100)]
Add support for `universal-argument' and `digit-argument'

* hydra.el (hydra-base-map): Model after `universal-argument-map'; all
  Hydra keymaps will inherit from this one.
(hydra-curr-map): Current Hydra keymap. This is necessary for
e.g. `hydra--digit-argument' to return to the orignial keymap.
(hydra--universal-argument): New function.
(hydra--digit-argument): New function.
(hydra--negative-argument): New function.
(hydra--hint): Fix dangling `body-color'.
(defhydra): keymap will inherit `hydra-base-map'.
`hydra-current-map' will be set by red heads. In red heads, make the
function call after `set-transient-map' so that e.g. "Beginning of
buffer" error will not exit the Hydra.

* hydra-test.el: Update tests.

Fixes #13.

9 years agohydra-test.el: Add licence
Oleh Krehel [Mon, 2 Feb 2015 14:39:51 +0000 (15:39 +0100)]
hydra-test.el: Add licence

9 years agoDistinguish red and blue hydra heads
Oleh Krehel [Sun, 1 Feb 2015 17:43:44 +0000 (18:43 +0100)]
Distinguish red and blue hydra heads

* hydra.el (hydra-face-red): New face.
(hydra-face-blue): New face.

(hydra--color): Each head now has a color: red is persistent, blue is
single-use. Head color inherits body color if it's not explicitly
overridden. Body color is red unless explicitly stated.

(hydra--face): Return face that corresponds to color.
(hydra--hint): New function, moved out of `defhydra'.
(hydra-disable): New function, moved out of `defhydra'.
(hydra--doc): New function, moved out of `defhydra'.

(defhydra): Commands that will vanquish the Hydra should be colored with
`hydra-face-blue'. The ones that will make the Hydra persist should be
colored with `hydra-face-red'.
Add autoload, move some code outside, Test HEAD's second element with
`null' instead of `functionp'.

* hydra-test.el (defhydra-red-error): Rename from `defhydra'.
(hydra-blue-toggle): Add test.

* README.md: Update.

Example:

    (global-set-key
     (kbd "C-c C-v")
     (defhydra toggle ()
       "toggle"
       ("t" toggle-truncate-lines "truncate" :color blue)
       ("f" auto-fill-mode "fill" :color blue)
       ("a" abbrev-mode "abbrev" :color blue)
       ("q" nil "cancel")))

Alternatively, since heads inherit color from the body:

    (global-set-key
     (kbd "C-c C-v")
     (defhydra toggle (:color blue)
       "toggle"
       ("a" abbrev-mode "abbrev")
       ("d" toggle-debug-on-error "debug")
       ("f" auto-fill-mode "fill")
       ("t" toggle-truncate-lines "truncate")
       ("w" whitespace-mode "whitespace")
       ("q" nil "cancel")))

9 years agohydra.el (defhydra): fix a bug for old Emacs versions
Oleh Krehel [Fri, 30 Jan 2015 19:23:41 +0000 (20:23 +0100)]
hydra.el (defhydra): fix a bug for old Emacs versions

re #10

9 years agoBump version
Oleh Krehel [Fri, 30 Jan 2015 16:07:13 +0000 (17:07 +0100)]
Bump version

9 years agohydra.el (defhydra): Use `clear-temporary-overlay-map'
Oleh Krehel [Fri, 30 Jan 2015 10:35:19 +0000 (11:35 +0100)]
hydra.el (defhydra): Use `clear-temporary-overlay-map'

* hydra.el (defhydra): Add a fix for old Emacs versions that don't have
`set-transient-map'.

Fixes #10.

9 years agoWhen calling `prefix/nil', make sure there's something to disable
Oleh Krehel [Thu, 29 Jan 2015 22:05:10 +0000 (23:05 +0100)]
When calling `prefix/nil', make sure there's something to disable

* hydra.el (defhydra): Update.

Fixes #10.