-
-
Notifications
You must be signed in to change notification settings - Fork 391
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 exit current process and run a new helm process with same pattern as before #2437
Comments
After test, it seem like when following code is executing, current keyword will expand to match a symbol instead of original. (with-helm-alive-p e.g. when i search |
"Billy.Zheng" ***@***.***> writes:
Following is part of config helm.
(defun helm-quit-and-helm-do-ag-current-directory ()
"Drop into `helm-do-ag-current-directory' from `helm'."
(interactive)
(with-helm-alive-p
(helm-run-after-exit (lambda () (helm-do-ag default-directory)))
))
(global-set-key [(control r)] 'helm-do-ag-this-file)
(define-key helm-ag-map [(control r)] 'helm-quit-and-helm-do-ag-current-directory)
This seems related to helm-ag which is not part of helm.
Please use `M-x helm-do-grep-ag`.
Thanks.
…--
Thierry
|
@thierryvolpiatto , sorry for late reply. I consider this is a issue about as the code here, https://github.com/emacsorphanage/helm-ag/blob/master/helm-ag.el#L1320-L1321, because so, could you please help on how to pass original marked input into helm-ag when run with Thank you. |
"Billy.Zheng" ***@***.***> writes:
@thierryvolpiatto , sorry for late reply.
I consider this is a issue about helm-run-after-exit
No issue only bad usage.
not pass default marked input into helm-do-ag function, so, helm-ag
select a default fallback behavior, which is set by
helm-ag-insert-at-point variable, it can set values same as
thing-at-point.
as the code here,
https://github.com/emacsorphanage/helm-ag/blob/master/helm-ag.el#L1320-L1321, because helm-ag--marked-input not result, it select to use helm-ag--insert-thing-at-point.
so, could you please help on how to pass original marked input into
helm-ag when run with helm-run-after-exit ?
helm-run-after-exit execute the function passed as argument with ARGS
which are passed to this function. You are passing only one arg to your
function so your function is behaving as expected, it uses only the
argument specified.
That said you are trying to implement with convoluted code + external
package usage what is already implemented in Helm.
…--
Thierry
|
BTW, in fact, i try several solution, but both not work ... include |
In fact, i consider when i this is not a helm issue, but, instead of, it should be a helm feature request? anyway, i search |
"Billy.Zheng" ***@***.***> writes:
That said you are trying to implement with convoluted code + external package usage what is already implemented in Helm.
Yes, maybe, sorry, followign is some feature i don't know helm if provided by offical helm-do-grep-ag
1. helm-ag--do-ag-up-one-level, if i can't search result with in current folder, i can search it from upper level folder instead use Ctrl+l, then continue Ctrl+l ...
2. helm-do-ag can use follow mode, when selection is moving, the opened buffer in another window is moving.
3. Ctrl+c Ctrl+e switch to edit-mode is useful for replace matched result selectively, as following, i can change content in a individual buffer directly, then Ctrl+c Ctrl+c to apply it
to original buffer.
image
No issue only bad usage.
Yes, i think so too. : ) but, i am no clue about how to pass current
keyword into new helm-run-after-exit as &rest ARGS
(helm-run-after-exit FUNCTION &rest ARGS)
Here your original code:
(defun helm-quit-and-helm-do-ag-current-directory ()
"Drop into `helm-do-ag-current-directory' from `helm'."
(interactive)
(with-helm-alive-p
(helm-run-after-exit (lambda () (helm-do-ag default-directory)))
))
As you can see you are passing an anonymous function with no arguments
to helm-run-after-exit.
I downloaded helm-ag to see the code.
Here the helm-do-ag signature:
(defun helm-do-ag (&optional basedir targets default-input)
As expected, helm-do-ag have a DEFAULT-INPUT argument that you can use,
I guess you want to use something like this:
(defun helm-quit-and-helm-do-ag-current-directory ()
"Drop into `helm-do-ag-current-directory' from `helm'."
(interactive)
(with-helm-alive-p
(helm-run-after-exit #'helm-do-ag
default-directory nil
(with-helm-current-buffer
(if (region-active-p)
(buffer-substring-no-properties
(region-beginning) (region-end))
(thing-at-point 'symbol))))))
Up to you to modify it, it is fully not tested as I do not use helm-ag
package (I use the one provided with Helm).
…--
Thierry
|
Oops! i am forget to add args to anonymous functions ... i change your's code to this, becuse helm-do-ag if last args is nil, it will use
But, this solution still not work, because region never active. please see screenshot. |
Current the issue is, Is there exist a way to extract the |
"Billy.Zheng" ***@***.***> writes:
As you can see you are passing an anonymous function with no arguments to helm-run-after-exit.
Oops! i am forget to add args to anonymous functions ...
i change your's code to this, becuse helm-do-ag if last args is nil, it will helm-ag-insert-at-point instead.
(defun helm-quit-and-helm-do-ag-current-directory ()
"Drop into `helm-do-ag-current-directory' from `helm'."
(interactive)
(with-helm-alive-p
(helm-run-after-exit #'helm-do-ag
default-directory nil
(with-helm-current-buffer
(if (region-active-p)
(buffer-substring-no-properties
(region-beginning) (region-end)))))))
But, this solution still not work, because region never active. please see screenshot.
So I didn't understand what you want to pass as DEFAULT-INPUT, anyway
you know now how to pass args to your function, feel free to modify the
above code for your needs.
…--
Thierry
|
sorry, let me explain. What i want to pass as DEFAULT-INPUT is the pattern when i first time run |
AFAIK, i guess https://github.com/emacs-helm/helm/blob/master/helm.el#L2363-L2365 as above code, it not pass current pattern(keyword i said before) to the function |
"Billy.Zheng" ***@***.***> writes:
So I didn't understand what you want to pass as DEFAULT-INPUT
sorry, let me explain.
What i want to pass as DEFAULT-INPUT is the pattern when i first time
run helm-ag,
It is `helm-pattern`.
…--
Thierry
|
It works, thank you very much. Following is the working solution: (defun helm-quit-and-helm-do-ag-current-directory ()
"Drop into `helm-do-ag-current-directory' from `helm'."
(interactive)
(with-helm-alive-p
(helm-run-after-exit #'helm-do-ag
default-directory nil
(with-helm-current-buffer
helm-pattern
))))
(global-set-key [(control r)] 'helm-do-ag-this-file)
(define-key helm-ag-map [(control r)] 'helm-quit-and-helm-do-ag-current-directory)
|
Following is the complete code for resolve my issue, please check here. emacsorphanage/helm-ag#381 (comment) Perhaps someone interested in this. |
"Billy.Zheng" ***@***.***> writes:
It is helm-pattern.
It works, thank you very much.
Glad you could do what you want.
Following is the working solution:
(defun helm-quit-and-helm-do-ag-current-directory ()
"Drop into `helm-do-ag-current-directory' from `helm'."
(interactive)
(with-helm-alive-p
(helm-run-after-exit #'helm-do-ag
default-directory nil
(with-helm-current-buffer
You don't need `with-helm-current-buffer` in this case.
helm-pattern
))))
cheers,
…--
Thierry
|
Oops, previous solution still have bug .... for decide if still on first time run helm-do-ag buffer, i use (eq 'last-command helm-do-ag-this-file), but it not work if i moving up/down, because last-command change to so, i have to set a toggle variable to decide current if still on first time C-r helm buffer, it is dirty, but works! (setq helm-do-ag-on-current-directory-p nil)
(defun helm-quit-and-helm-do-ag-on-current-directory ()
"Drop into `helm-do-ag' on DEFAULT-DIRECTORY from `helm'."
(interactive)
(setq helm-do-ag-on-current-directory-p t)
(with-helm-alive-p
(helm-run-after-exit #'helm-do-ag default-directory nil helm-pattern)))
(defun advice-up-on-level-corretly-when-run-helm-do-ag-this-file (orig-fun &rest command)
"If start helm-ag with `helm-do-ag-this-file', `helm-ag--do-ag-up-one-level' not work,
we have to run `helm-do-ag' on DEFAULT-DIRECTORY first, then up one level function start to work."
(if helm-do-ag-on-current-directory-p
(apply orig-fun command)
(helm-quit-and-helm-do-ag-on-current-directory)))
(advice-add #'helm-ag--do-ag-up-one-level :around #'advice-up-on-level-corretly-when-run-helm-do-ag-this-file)
(global-set-key [(control r)] 'helm-do-ag-this-file)
(define-key helm-do-ag-map [(control r)] 'helm-ag--do-ag-up-one-level)
(add-hook 'helm-quit-hook (lambda () (setq helm-do-ag-on-current-directory-p nil))) Now, this new solution works well for now.
|
Following is part of config helm.
We assume current in enh-ruby-mode, cursor on following
@dist
, and set mark region on it.Then i press
Ctrl+r
, i get expected behavior like this:But, i want to search
@dist
on current folder instead of only current file, so i pressCtrl+r
again(will invoke'helm-quit-and-helm-do-ag-current-directory
i defined on above)Expected behavior
expect to search
@dist
in current folder.Actual behavior (from
emacs-helm.sh
if possible, see note above)search
dist
(without @ prefix) in current folderDescribe versions of Helm, Emacs, operating system, etc.
Compiled emacs 27.2, Helm lastest (08e95db), Arch linux
Are you using
emacs-helm.sh
to reproduce this bug? (yes/no):no
The text was updated successfully, but these errors were encountered: