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

helm-run-after-exit not passing the previous match keyword into next helm session, only if previous match is not result. #2663

Closed
1 task done
zw963 opened this issue Apr 12, 2024 · 9 comments
Labels

Comments

@zw963
Copy link
Contributor

zw963 commented Apr 12, 2024

What happened?

this issue is a follow-up to the previous issue.

It work as you said, but only partly.

anyway, just describe issue here, not need check old one.

I wrote some function like following:

(defun helm-git-grep-get-input-symbol ()
  "Get input symbol."
  (if (not mark-active)
      (thing-at-point 'symbol)
    (when (use-region-p)
      (buffer-substring (region-beginning) (region-end)))))

(defun helm-grep-do-git-grep-hacked (arg)
  "Preconfigured `helm' for git-grepping `default-directory'.
With a prefix arg ARG git-grep the whole repository."
  (interactive "P")
  (require 'helm-files)
  (helm-grep-git-1 default-directory arg nil (helm-git-grep-get-input-symbol)))

(defun helm-quit-and-do-git-grep-on-project ()
  "Drop into `helm-grep-do-git-grep' on entire project from `helm'."
  (interactive)
  (with-helm-alive-p
    (helm-run-after-exit #'helm-grep-do-git-grep-hacked t)))

(global-set-key (kbd "M-r") 'helm-grep-do-git-grep-hacked)
(define-key helm-grep-map (kbd "M-r") 'helm-quit-and-do-git-grep-on-project)

The function is simple

(1) when i run M-r the first time, it use helm-grep-git on default-directory only,

(2) if i could not found the expected result, i will pressing M-r again, i will fallback do git-grep on project instead, use same match as (1).

It works well there was matched result when run (1).

But, if there is no matched result when run (1), try again use (2), i have to re typing the match keyword again.

So, i consider there is something need improve for helm-run-after-exit , thanks!

How to reproduce?

As above

Helm Version

Master branch

Emacs Version

Emacs-29.1

OS

GNU/Linux

Relevant backtrace (if possible)

No response

Minimal configuration

  • I agree using a minimal configuration
@zw963 zw963 added the bug label Apr 12, 2024
@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Apr 12, 2024 via email

@zw963
Copy link
Contributor Author

zw963 commented Apr 13, 2024

sorry, it not work, please let me use a concrete example for describe my issue.

  1. open a file
  2. move cursor into a non-text blank place
  3. M-r to run helm-grep-do-git-grep-hacked
  4. typing "local-set-key", i assume there is no matched result in current file. (this is the key difference, if there is even only one match, this function work as expect)
  5. next, i try M-r again, want to match local-set-key on the project

the issue here is, i have to retyping local-set-key to start, but i typing it once before.

above issue is not exists if there is match result when the first time typing 'M-r'.

Thanks

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Apr 13, 2024 via email

@zw963
Copy link
Contributor Author

zw963 commented Apr 14, 2024

Sorry, still not work as expected.

When the is no matched result the first time, git grep exit with code 1 like this. (see screenshot)

image

And, when i pressing M-r again, just a blank pattern here. (see screenshot)

image

I even set the timer to 1s, this has severely impacted the helm-grep use experience. but, still bank there.

Thanks.

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Apr 14, 2024 via email

@zw963
Copy link
Contributor Author

zw963 commented Apr 14, 2024

Try this instead: (defun helm-grep-do-git-grep-hacked (arg) "Preconfigured helm' for git-grepping default-directory'. With a prefix arg ARG git-grep the whole repository." (interactive "P") (require 'helm-files) (run-at-time 0.1 nil #'helm-grep-git-1 default-directory arg nil (or helm-pattern (helm-git-grep-get-input-symbol))))

works like a charm! thank you very much!

NOTE: I am still wondering why you regularly insist to use the INPUT argument when what we have actually in Helm works perfectly i.e. starting from helm-find-files.

I probably rely on a small number of (not so correct) helm usages heavily, if i don't understood wrong, what you mean is, prefer to start from helm-find-files, right?

@zw963 zw963 closed this as completed Apr 14, 2024
@zw963
Copy link
Contributor Author

zw963 commented Apr 14, 2024

BTW, one of reason i don't like use helm-find-files is, the keybinding of helm-toggle-visible-mark-forward is not so easy to use for a (Chinese) user like me, because after installed IM(e.g. fcitx5), this process live forever, and intercept the Ctrl + Space always.

@zw963
Copy link
Contributor Author

zw963 commented Apr 14, 2024

Wired, after use the last config, it could found the matching result even my cursor is under a symbol which should always matched because it exists on current file.

image

But, anyway, i understood the key, following is the complete work solution:

(defun helm-git-grep-get-input-symbol ()
  "Get input symbol."
  (if (not mark-active)
      (thing-at-point 'symbol)
    (when (use-region-p)
      (buffer-substring (region-beginning) (region-end)))))

(defun helm-grep-do-git-grep-on-symbol (arg)
  "Preconfigured `helm' for git-grepping `default-directory'.
With a prefix arg ARG git-grep the whole repository."
  (interactive "P")
  (require 'helm-files)
  (helm-grep-git-1 default-directory arg nil (helm-git-grep-get-input-symbol)))

(defun helm-grep-do-git-grep-on-previous-pattern (arg)
  "Preconfigured `helm' for git-grepping `default-directory'.
    With a prefix arg ARG git-grep the whole repository."
  (interactive "P")
  (run-at-time 0.1 nil #'helm-grep-git-1
               default-directory arg nil
               helm-pattern))

(defun helm-quit-and-do-git-grep-on-project ()
  "Drop into `helm-grep-do-git-grep' on entire project from `helm'."
  (interactive)
  (with-helm-alive-p
    (helm-run-after-exit #'helm-grep-do-git-grep-on-previous-pattern t)))

(global-set-key (kbd "M-r") 'helm-grep-do-git-grep-on-symbol)
(define-key helm-grep-map (kbd "M-r") 'helm-quit-and-do-git-grep-on-project)

Thank thierry alot!

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Apr 14, 2024 via email

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

No branches or pull requests

2 participants