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-ag--do-ag-up-one-level not work when run after helm-do-ag-this-file #381

Open
zw963 opened this issue Aug 15, 2021 · 1 comment
Open

Comments

@zw963
Copy link

zw963 commented Aug 15, 2021

  • Emacs version
    27.2
  • Operating system
    arch ilnux
  • Search command(ag, pt, ack etc) and version
    rg
  • Last value of 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

  1. Run helm-do-ag-this-file
  2. Pressing Ctrl+l(helm-ag--do-ag-up-one-level) again and again.
  3. folder is up one level, but search result keep no changes.

Expected behavior

search result should be update when up one level from current file to current folder.

More detail, please check this issue.

@zw963
Copy link
Author

zw963 commented Aug 15, 2021

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.

  1. C-r first time, invoke helm-do-ag-this-file, search keyboard on current file.
    image

  2. C-r again, it invoke helm-quit-and-helm-do-ag-current-directory because helm-do-ag-on-current-directory-p is nil

image

  1. C-r again, because 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.

image

  1. repeat step 3.
    image

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.

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

No branches or pull requests

1 participant