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

counsel-find-file and dired doesn't use current directory? #2274

Closed
mohkale opened this issue Oct 13, 2019 · 2 comments
Closed

counsel-find-file and dired doesn't use current directory? #2274

mohkale opened this issue Oct 13, 2019 · 2 comments

Comments

@mohkale
Copy link
Contributor

mohkale commented Oct 13, 2019

sorry for the weird title, I couldn't really think of a nice way to word it.

In dired, you have the ability to insert directories into the same dired buffer dired-maybe-insert-subdir. I do this quite often. When you do this, the default-directory doesn't change, so if you're at one of these inserted directories, counsel-find-file will use the default-directory of the entire buffer, instead of the dired directory you're (point) is currently at. I'd prefer if in this case, counsel-find-file was smart enough to detect which directory you mean to be at and work from there. This is how helm works in dired buffers and having to navigate down to a directory first in dired and then again in counsel-find-file is inconvenient.

For example:

say I'm in a dired directory like this:

|   .gitignore
|   LICENSE
|   README.md
|   requirements.txt
|   setup.py
|
\---my_module
    |   decorators.py
    |   __main__.py
    |   __init__.py

I insert the my_module directory into my dired buffer. Now I decide I want to create a new file at my_module/foo.py. I navigate down to where I inserted that directory (assuming I'm not already there) and then counsel-find-file. counsel-find-file begins not at my_module, it begins at the parent directory of my_module, now I have to navigate to my_module again and then type out foo.py to create it.

In the mean time, you can use this to get around this issue, but I'd prefer a built in solution:

  (defun counsel-find-file--adjust-for-dired (func &rest args)
    (if (not (provided-mode-derived-p major-mode 'dired-mode))
        (apply func args)
      (let ((default-directory (dired-current-directory)))
        (apply func args))))

  (advice-add 'counsel-find-file :around #'counsel-find-file--adjust-for-dired)
@abo-abo
Copy link
Owner

abo-abo commented Oct 13, 2019

Thanks, please test.

@mohkale
Copy link
Contributor Author

mohkale commented Oct 13, 2019

seems to be working fine. Thnx for the prompt response. 😄.

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

No branches or pull requests

2 participants