Open zw963 opened 3 years ago
Okay, i resolve this issue finally use a device, let me show me code for a more clear describe.
(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, let me describe how to use it.
C-r first time, invoke helm-do-ag-this-file
, search keyboard on current file.
C-r again, it invoke helm-quit-and-helm-do-ag-current-directory
because helm-do-ag-on-current-directory-p
is nil
helm-do-ag-on-current-directory-p
is true, invoke advicedagain, this time, it run original helm-ag--do-ag-up-one-level
command, just up one level
as expected.My solution is dirty, the reason is, when invoking helm-do-ag-this-file
, it not support helm-ag--do-ag-up-one-level
to up one level from current file
to default directory
, if anyone can fix this from helm-ag directly, all above code can be eliminate to only one line.
(define-key helm-do-ag-map [(control r)] 'helm-ag--do-ag-up-one-level)
Or even zero config, if use default C-l
to up one level instead.
Thank you.
helm-ag--last-command
("rg" "--no-config" "--no-heading" "--hidden" "--smart-case" "--glob=!~" "--glob=!##" "--glob=!.min." "--glob=!TAGS" "--glob=!tags" "helm-ag-.*comma" "server.rb")Actual behavior
Expected behavior
search result should be update when up one level from current file to current folder.
More detail, please check this issue.