emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: Oleh Krehel <oleh@oremacs.com>,
	emacs-org list <emacs-orgmode@gnu.org>, Rasmus <rasmus@gmx.us>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: Key binding popup interface
Date: Tue, 12 Dec 2017 20:33:38 +0000	[thread overview]
Message-ID: <CAFyQvY30trCsCP0gcpiKJ2WenSvfDuKDwpF2z3LaUcf-EymVMw@mail.gmail.com> (raw)
In-Reply-To: <87shcfpujg.fsf@ericabrahamsen.net>


[-- Attachment #1.1: Type: text/plain, Size: 4310 bytes --]

On Tue, Dec 12, 2017 at 3:20 PM Eric Abrahamsen <eric@ericabrahamsen.net>
wrote:

>
> Hydra definitely sounds nice, but unless I'm misunderstanding how it
> works, it can't be a replacement for either Org's export interface, or
> Magit's popups. Both of those can set various state variables before
> choosing an actual action -- Hydra can't do that, can it?
>

hydra can do anything you can do in elisp before/after the action.

For example, here's a hydra I use for rectangle actions:

(defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1)
                           :color pink
                           :post (deactivate-mark)
                           :hint nil)
  "
  Rectangle:
  ^_p_^        _d_   delete      _s_tring        _c_/_C_ (delete/kill) and
replace with space
_b_   _f_      _k_   cut         _r_eset         _o_pen (create blank
rectangle and push text in region to the right)
  ^_n_^        _w_   copy        e_x_change      _X_ delete whitespace
starting from the left edge of the rectangle
^^^^           _y_   paste       _e_xtend        Prefix rectangle lines
with _N_umbers
"
  ("b"   backward-char)
  ("f"   forward-char)
  ("p"   previous-line)
  ("n"   next-line)

  ("d"   delete-rectangle :color blue)
  ("k"   kill-rectangle :color blue)
  ("w"   copy-rectangle-as-kill :color blue)
  ("y"   yank-rectangle :color blue)
  ("s"   string-rectangle :color blue)
  ("t"   string-rectangle :color blue)
  ("r"   (if (region-active-p)
             (deactivate-mark)
           (rectangle-mark-mode 1)))
  ("x"   ora-ex-point-mark)
  ("e"   modi/extend-rectangle-to-end)
  ("c"   clear-rectangle)
  ("C"   modi/kill-rectangle-replace-with-space :color blue)
  ("o"   open-rectangle :color blue)
  ("X"   delete-whitespace-rectangle :color blue)
  ("N"   rectangle-number-lines :color blue)
  ("q"   nil "cancel" :color blue))

Note the use of :body-pre, :post in above example. More details here:
https://github.com/abo-abo/hydra/wiki/internals#body-pre

<https://github.com/abo-abo/hydra/wiki/internals#body-pre>
But this email wasn't to propose replace the matured popups like magit and
org export with hydra. The proposal is to integrate hydra into emacs, so
that many packages that self-implement these popups can do the same using
hydra more easily. Dired, ibuffer can make use of hydra and make all the
bindings more discoverable and memorable. In future, may be hydra can be
use for the org template insertion piece.

I can talk of verilog-mode as I use it everyday. In verilog-mode.el, there
is this code:

(defvar verilog-template-map
  (let ((map (make-sparse-keymap)))
    (define-key map "a" 'verilog-sk-always)
    (define-key map "b" 'verilog-sk-begin)
  ..
  (define-key map "D" 'verilog-sk-define-signal)
    map)
  "Keymap used in Verilog mode for smart template operations.")

In my config, I replace the same with hydra and it looks like this:

    (defhydra hydra-verilog-template (:color blue
                                      :hint nil)
      "
_i_nitial        _?_ if             _j_ fork
_A_ssign                _uc_ uvm-component
_b_egin          _:_ else-if        _m_odule
_I_nput                 _uo_ uvm-object
_a_lways         _f_or              _g_enerate         _O_utput
^^               _w_hile            _p_rimitive        _=_ inout
^^               _r_epeat           _s_pecify
_S_tate-machine         _h_eader
^^               _c_ase             _t_ask
_W_ire                  _/_ comment
^^               case_x_            _F_unction         _R_eg
^^               case_z_            ^^                 _D_efine-signal
"
      ("a"   verilog-sk-always)
      ("b"   verilog-sk-begin)
  ...
      ("D"   verilog-sk-define-signal)
      ("q"   nil nil :color blue)
      ("C-g" nil nil :color blue))

Which gives in these interface which makes the bindings much more memorable
and accessible:

[image: image.png]
There are so many places like this that can get a facelift from hydra.

Did I hear that Magit was breaking its popup interface out into a
> separate library? If so, that would also be a nice thing.
>

That would be great too. We are basically missing a configurable library to
bind temporary key maps, that can make the bindings present in a
discoverable way to the user. So far hydra.el fits the bill.
-- 

Kaushal Modi

[-- Attachment #1.2: Type: text/html, Size: 6539 bytes --]

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 20877 bytes --]

  reply	other threads:[~2017-12-12 20:33 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-10  0:23 Poll: new keybinding for org-insert-structure-template? Eric Abrahamsen
2017-12-10 11:26 ` Rasmus
2017-12-10 19:37   ` Eric Abrahamsen
2017-12-12  7:48     ` Rasmus
2017-12-12  7:55       ` Nicolas Goaziou
2017-12-12 13:49         ` Rasmus
2017-12-12 14:02           ` Key binding popup interface (Was: Re: Poll: new keybinding for org-insert-structure-template on org mode list) Kaushal Modi
2017-12-12 18:45             ` Key binding popup interface Eric S Fraga
2017-12-12 18:56               ` Kaushal Modi
2017-12-12 19:53                 ` Alan E. Davis
2017-12-12 20:20             ` Eric Abrahamsen
2017-12-12 20:33               ` Kaushal Modi [this message]
2017-12-12 20:44                 ` Eric Abrahamsen
2017-12-12 20:56                   ` Kaushal Modi
2017-12-12 21:01             ` Stefan Monnier
2017-12-12 21:19               ` Kaushal Modi
2017-12-12 21:48                 ` Stefan Monnier
2017-12-13 15:38                   ` Kaushal Modi
2017-12-13 16:18                     ` Stefan Monnier
2017-12-12 23:51               ` Robert Weiner
2017-12-13 15:40                 ` Kaushal Modi
2017-12-13 16:25                   ` Robert Weiner
2017-12-13  6:52               ` John Wiegley
2017-12-13 15:43                 ` Kaushal Modi
2017-12-13  0:45           ` Poll: new keybinding for org-insert-structure-template? Eric Abrahamsen
2017-12-14  9:06             ` Rasmus
2017-12-14 21:19               ` Eric Abrahamsen
2017-12-15 11:22                 ` Rasmus
2017-12-15 12:59                   ` Kaushal Modi
2017-12-15 13:15                     ` Rasmus
2017-12-15 17:40                       ` Eric Abrahamsen
2017-12-18 18:23                         ` Eric Abrahamsen
2017-12-19 11:40                           ` Rasmus
2017-12-20 16:36                             ` Eric Abrahamsen
2017-12-20 16:48                               ` Eric Abrahamsen
2017-12-21  9:16                                 ` Rasmus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFyQvY30trCsCP0gcpiKJ2WenSvfDuKDwpF2z3LaUcf-EymVMw@mail.gmail.com \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=eric@ericabrahamsen.net \
    --cc=oleh@oremacs.com \
    --cc=rasmus@gmx.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).