helm-run-after-exit not passing the previous match keyword into next helm session, only if previous match is not result.
zw963 opened this issue · 9 comments
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
sorry, it not work, please let me use a concrete example for describe my issue.
- open a file
- move cursor into a non-text blank place
M-r
to runhelm-grep-do-git-grep-hacked
- 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)
- next, i try
M-r
again, want to matchlocal-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
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)
And, when i pressing M-r again, just a blank pattern here. (see screenshot)
I even set the timer to 1s, this has severely impacted the helm-grep use experience. but, still bank there.
Thanks.
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?
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.
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.
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!