Feature request: show key-binding when calling execute-extended-command with ivy enabled #136

Closed
brabalan opened this Issue Jun 10, 2015 · 12 comments

Projects

None yet

3 participants

@brabalan

Ivy meets all my helm needs, while feeling faster, with one small exception: when I use M-x I don't see the binding of the command suggested. I have found this to be a great way to learn bindings … Would you consider adding this to ivy?

@abo-abo
Owner
abo-abo commented Jun 10, 2015

Would you consider adding this to ivy?

Sure, just need to write a separate function ivy-M-x, similar to helm-M-x. Right now, I'm using my fork of smex. I've sent the pull request ages ago, looks like it's not getting merged.

@brabalan

Having an ivy-M-x would be great, but in the meantime I'll give your fork of smex a try. (A bit later). It's very nice indeed. I like how one can look-up key bindings, but it would be nice to see them displayed by default.

@abo-abo abo-abo added a commit that referenced this issue Jun 10, 2015
@abo-abo counsel.el (counsel-M-x): New command
* counsel.el (counsel--format-function-M-x): New defun.

Re #136.
03e7e70
@abo-abo
Owner
abo-abo commented Jun 10, 2015

Have a look. Let me know what's missing.

@kaushalmodi
Contributor

Thanks for adding this.

Few comments from few minutes of trying it out:

  • Can you sort the entries by last used instead of sorting the commands alpha-numerically? Currently the first command I see is 2C-associate-buffer which I probably am never going to use. It would be nice to see commands in the order of most recently used to least recently used.
  • Is there a plan to enable fuzzy searching for certain commands using ivy/counsel? IMO counsel-M-x would be the first candidate to fit the bill for fuzzy searching. The reason is that many times the commands are long and it is faster to just ram in few letters from that whole command instead of remembering to hit a space after every few letters. Example: It is faster to type licdis instead of li c dis to get to list-colors-display.
@kaushalmodi
Contributor

It would be awesome to make C-. and C-, work in this command too (referring to your recent blog post: http://oremacs.com/2015/06/08/describe-variable-tip/).

@abo-abo abo-abo added a commit that referenced this issue Jun 10, 2015
@abo-abo counsel.el (counsel-M-x): Piggyback on smex for sorting
* counsel.el (counsel-M-x): When smex is present, use it for sorting the
  candidates. Also use `counsel-describe-map', so that "C-." and "C-,"
  work for commands.

Re #136
efa751b
@abo-abo
Owner
abo-abo commented Jun 10, 2015

Added smex sorting and extra bindings. I haven't looked to implementing own sorting so far, since it can be expensive to sort.

I'll look into fuzzy matching without a space soon.

@abo-abo abo-abo added a commit that referenced this issue Jun 10, 2015
@abo-abo Add fuzzy matching function
ivy.el (ivy--regex-fuzzy): New defun.

To enable fuzzy matching, set your `ivy-re-builders-alist' accordingly:

(setq ivy-re-builders-alist
      '((t . ivy--regex-fuzzy)))

Re #136
ebead12
@abo-abo
Owner
abo-abo commented Jun 10, 2015

Thanks, this fuzzy matcher isn't as slow as I thought it would be.
Actually it's as fast as the default for 8000 candidates.

@brabalan

This is great, thanks a lot!

@abo-abo
Owner
abo-abo commented Jun 12, 2015

You're welcome.

@abo-abo abo-abo closed this Jun 12, 2015
@kaushalmodi
Contributor

The "recently used commands" cache stays stale until smex is called. No matter which command I execute using counsel-M-x, the first option in the command list stays the same, until I execute smex. So we also need to update the smex cache with each execution of counsel-M-x.

@kaushalmodi
Contributor

It was simply missing an smex-rank call:

(defun counsel-M-x (&optional initial-input)
  "Ivy version of `execute-extended-command'.
Optional INITIAL-INPUT is the initial input in the minibuffer."
  (interactive)
  (unless initial-input
    (setq initial-input (cdr (assoc this-command
                                    ivy-initial-inputs-alist))))
  (let ((ivy-format-function #'counsel--format-function-M-x)
        (cands obarray)
        (pred 'commandp)
        (sort t))
    (when (or (featurep 'smex)
              (package-installed-p 'smex))
      (require 'smex)
      (unless smex-initialized-p
        (smex-initialize))
      (smex-detect-new-commands)
      (smex-update)
      (setq cands smex-ido-cache)
      (setq pred nil)
      (setq sort nil))
    (ivy-read "M-x " cands
              :predicate pred
              :require-match t
              :history 'extended-command-history
              :action (lambda (cmd)
                        (smex-rank (intern cmd)) ; <-- FIX
                        (execute-extended-command current-prefix-arg cmd))
              :sort sort
              :keymap counsel-describe-map
              :initial-input initial-input)))
@abo-abo
Owner
abo-abo commented Jun 16, 2015

@kaushalmodi, thanks. But I think intern isn't necessary.

@abo-abo abo-abo added a commit that referenced this issue Jun 16, 2015
@abo-abo counsel.el (counsel-M-x): Fixup
Re #136
1dbdcdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment