Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action the # candidate directly [1-9] ? #1257

Closed
xuchunyang opened this issue Nov 5, 2015 · 15 comments
Closed

Action the # candidate directly [1-9] ? #1257

xuchunyang opened this issue Nov 5, 2015 · 15 comments

Comments

@xuchunyang
Copy link
Member

Number the first 9 visible candidates and assign M-1 ~ M-9 for them, for example, M-5 to select client.c and execute its default action, this way a little more convenient than enter "client" into minibuffer to continue to filter or run C-n for 4 times.

2015-11-05 2 00 46


(I've tried to implemented for several times but have always ended in failure.)

@thierryvolpiatto
Copy link
Member

Chunyang Xu notifications@github.com writes:

Number the first 9 visible candidates and assign M-1 ~ M-9 for them,
for example, M-5 to select client.c and execute its default action,
this way a little more convenient than enter "client" into minibuffer
to continue to filter or run C-n for 4 times.

This was existing in original version of "anything".
I removed it when I started cleaning "anything" which was a mess.
Perhaps we can reenable it now, (you will find it in early versions of
anything.el in our git history) but perhaps using a new code not
limiting us to first 9 by taking advantage of linum-relative.el.
(actually with linum-relative-mode enabled, you can do C-u 5 C-n RET to
execute default action on the nth 5 candidates starting from selection)

Thierry
https://emacs-helm.github.io/helm/

@xuchunyang
Copy link
Member Author

Perhaps we can reenable it now

Yes, I'd like to have it.

you will find it in early versions of anything.el in our git history

I've found it (controlled by variable anything-enable-shortcuts).

but perhaps using a new code not
limiting us to first 9 by taking advantage of linum-relative.el.

9 is just a reasonable default since its display-width is one and corresponding key bindings can be very straightforward, e.g., use M-1 ~ M-9 or C-1 ~ C-9.

(actually with linum-relative-mode enabled, you can do C-u 5 C-n RET to
execute default action on the nth 5 candidates starting from selection)

This is a different way, though it might be handy as well. I want to count candidate from the beginning of helm-window (in other word, the first visible candidate to the user).

@thierryvolpiatto
Copy link
Member

Chunyang Xu notifications@github.com writes:

9 is just a reasonable default since its display-width is one and
corresponding key bindings can be very straightforward, e.g., use M-1
~ M-9 or C-1 ~ C-9.

Agree.

(actually with linum-relative-mode enabled, you can do C-u 5 C-n RET to
execute default action on the nth 5 candidates starting from selection)

This is a different way, though it might be handy as well. I want to
count candidate from the beginning of helm-window (in other word, the
first visible candidate to the user).

Yes but with the linum-relative-mode it is exactly the same when
selection is on top and when the selection is lower you could count from
there ;-)

Thierry
https://emacs-helm.github.io/helm/

@issue-dispenser
Copy link
Contributor

Would this be disabled in helm-M-x where M-# would give a prefix argument to the candidate? Otherwise this sounds nice.

@thierryvolpiatto
Copy link
Member

issue-dispenser notifications@github.com writes:

Would this be disabled in helm-M-x where M-# would give a prefix
argument to the candidate?

Why ?

The new function should accept prefix arg (just like helm-next-line
does), so C-u M-4 would pass '(4) to the 4th command after selection.

Thierry
https://emacs-helm.github.io/helm/

@thierryvolpiatto
Copy link
Member

Thierry Volpiatto thierry.volpiatto@gmail.com writes:

issue-dispenser notifications@github.com writes:

Would this be disabled in helm-M-x where M-# would give a prefix
argument to the candidate?

Why ?

The new function should accept prefix arg (just like helm-next-line
does), so C-u M-4 would pass '(4) to the 4th command after selection.

Of course M-n is not a good example for a key because it is itself a
prefix arg, perhaps it is what you mean ?

Thierry
https://emacs-helm.github.io/helm/

@thierryvolpiatto
Copy link
Member

Here a sample code:

(defun helm-execute-selection-action-at-nth (linum)
(let ((prefarg current-prefix-arg))
(if (>= linum 0)
(helm-next-line linum)
(helm-previous-line (lognot (1- linum))))
(setq current-prefix-arg prefarg)
(helm-exit-minibuffer)))

(dotimes (n 9)
(let* ((key (format "C-c %d" n))
(key- (format "C-x %d" n))
(fn (lambda () (interactive) (helm-execute-selection-action-at-nth n)))
(fn- (lambda () (interactive) (helm-execute-selection-action-at-nth (- n)))))
(define-key helm-map (kbd key) fn)
(define-key helm-map (kbd key-) fn-)))

With this you can do C-x 5 which execute default action on the 5th
candidate BEFORE selection, and C-c 5 which execute default action on
the 5th candidate AFTER selection.

Thierry
https://emacs-helm.github.io/helm/

@issue-dispenser
Copy link
Contributor

Of course M-n is not a good example for a key because it is itself a
prefix arg, perhaps it is what you mean ?

Yes, I think it's too commonly used as a prefix to be used as a special key here. Perhaps C-M-# (which also is globally bound to digit-argument) would be better than just M-# as it's probably used less commonly as a prefix arg.

Your code seems to work nicely (I believe it has to be (dotimes (n 10)...).
Though I would think that C-x 0 or C-c 0 would just select the current candidate (currently it selects the next).

@thierryvolpiatto
Copy link
Member

issue-dispenser notifications@github.com writes:

Of course M-n is not a good example for a key because it is itself a
prefix arg, perhaps it is what you mean ?

Yes, I think it's too commonly used as a prefix to be used as a
special key here.

Yes of course and it would fail in helm-M-x (it will understand it as a
prefix arg).

Perhaps C-M-# (which also is globally bound to digit-argument) would
be better than just M-# as it's probably used less commonly as a
prefix arg.

Hmm, no, in addition it is very difficult to type on non US keyboards
(on my keyboard I have to press Ctrl Shift Alt and num simultaneously!).

Your code seems to work nicely (I believe it has to be (dotimes (n
10)...). Though I would think that C-x 0 or C-c 0 would just select
the current candidate (currently it selects the next).

Yeah, I quickly wrote it as example, need to be polished.

Thierry
https://emacs-helm.github.io/helm/

@cute-jumper
Copy link

This feature would be nice. IIRC, anything.el can use either number or letter to select a candidate. I wrote ace-jump-helm-line which does a similar thing, but its implementation is too simple, and using avy is kind of too heavy for this simple task. A helm built-in function would be much better.

@manuel-uberti
Copy link
Member

I agree with @cute-jumper, this one would be a nice add.

@thierryvolpiatto
Copy link
Member

This would not be very helpful as some source popup with a preselection very far from the first 9 cands.
What is needed is a function that allow jumping to candidates from selection (not from top).
If you use linum-relative-mode + the code I provided above (slighly modified) you can already do this.
What I want now is overlay displaying the first and previous 9 candidates from selection (similar to linum-relative but only for 9 first and previous).

thierryvolpiatto pushed a commit that referenced this issue Nov 17, 2015
…1257).

* helm.el (helm-map): Bind keys from 1 to 9.
(helm-execute-selection-action-at-nth): The function to jump to nth cand
and execute action.
@thierryvolpiatto
Copy link
Member

I have merged the code above (slighly modified), so one can now use it with linum-relative to visualize first and previous nine candidates.

C-x => execute default action on number candidate before selection.
C-c => execute default action on number candidate after selection.

@thierryvolpiatto
Copy link
Member

Now linum-relative have a minor-mode (not global) and a global-minor-mode, so one can enable linum-relative only for helm with something like this:

(defun helm--turn-on-linum-relative ()
  (with-helm-buffer (linum-relative-mode 1)))

(define-minor-mode helm-linum-relative-mode
    "Turn on linum-relative in helm.
Allow to execute default action on nth candidate.
Commands prefixed with C-x will use nth candidate before selection
the ones prefixed with C-c will use nth candidate after selection."
  :group 'helm
  (if helm-linum-relative-mode
      (progn
        (add-hook 'helm-after-initialize-hook 'helm--turn-on-linum-relative)
        (add-hook 'helm-after-preselection-hook 'linum-relative-for-helm))
      (remove-hook 'helm-after-initialize-hook 'helm--turn-on-linum-relative)
      (remove-hook 'helm-after-preselection-hook 'linum-relative-for-helm)))

Don't know yet if I have to integrate such code in helm, will see.

coldnew added a commit to coldnew/linum-relative that referenced this issue Jan 18, 2016
Once the mode enabled with (helm-linum-relative-mode 1) you will see
the relative candidates numbers in your helm buffers, you can jump to
the nine numbered candidates before or after current selection (the line
highlighted in your helm buffer) by using C-x <n> for the ones before
selection and C-c <n> for the ones after.

see also: emacs-helm/helm#1257
coldnew added a commit to coldnew/linum-relative that referenced this issue Jan 18, 2016
Once the mode enabled with (helm-linum-relative-mode 1) you will see
the relative candidates numbers in your helm buffers, you can jump to
the nine numbered candidates before or after current selection (the line
highlighted in your helm buffer) by using C-x <n> for the ones before
selection and C-c <n> for the ones after.

see also: emacs-helm/helm#1257

Signed-off-by: Yen-Chin Lee <coldnew.tw@gmail.com>
@thierryvolpiatto
Copy link
Member

Closing now as helm-linum-relative-mode is now part of linum-relative, thanks @coldnew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants