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

CD to home on ~/ not just ~ #687

Closed
wants to merge 1 commit into from
Closed

CD to home on ~/ not just ~ #687

wants to merge 1 commit into from

Conversation

UnwashedMeme
Copy link

Previously when using counsel-find-file, to find a file relative to
the home directory one needed to type ~$FILENAME. This is counter to
lots of training/convention in using shells.

If you had typed ~/$FILENAME it would be relative the root as ~
would jump to home and then / would jump to root.

With this change it doesn't trigger the jump to home just on typing
the tilde, it waits for tilde-slash.

Previously when using counsel-find-file, to find a file relative to
the home directory one needed to type `~$FILENAME`. This is counter to
lots of training/convention in using shells.

If you had typed `~/$FILENAME` it would be relative the root as `~`
would jump to home and then `/` would jump to root.

With this change it doesn't trigger the jump to home just on typing
the tilde, it waits for tilde-slash.
@abo-abo
Copy link
Owner

abo-abo commented Sep 23, 2016

I don't agree with this implementation. You're preventing the users that have no preference for ~/ over ~ from using the more efficient solution.

I would prefer the following solution:

  1. ~ moves to home as it does now.
  2. / from home doesn't influence selection, i.e. input /em is translated to regex em.
  3. The solution should not interfere with // or /ssh: or /sudo:.

A simpler solution that's even more preferable is you putting this in your personal config:

(define-key ivy-mode-map (kbd "~/")
  (lambda ()
    (interactive)
    (ivy--cd "~/")))

@UnwashedMeme
Copy link
Author

I tried to tell myself that ~ is more efficient and I should just learn that, but it has been months now and it still infuriates me every time: this is behavior that is contradictory to everywhere else. Sure cd ~ takes you to home but cd ~.ssh does not and emacsclient ~.ssh isn't going to work either (at least in bash, zsh, and expand-file-name). Without a slash after it, it has an entirely different meaning.

I don't think that one character efficiency is worth being different than every other system. I get that I'm proposing a change to existing behavior though... If that change is unacceptable (even to bring it semantically inline with other systems) then I suspect there is no good solution here that doesn't involve keeping a lot of back history and making the code much more complex.

I tried the define-key solution; I think it works much less well. With that key chord in place tilde becomes a prefix and nothing at all happens when you type ~. The first time I tried it I thought I must not have hit the key and so I pressed another tilde and emacs reports that "~ ~ is undefined". That's not good behavior.

In the above desired behavior I would say that point two is incorrect. E.g. the input /et<tab> from $HOME should complete to /etc/. A slightly better formulation is / should only not touch selection if the immediately preceeding key is a tilde. Even that is not a great solution b/c I could be trying to find the path .../foo~/bar; granted not a common occurence but reasonable to expect this to work.

Point 1 is suboptimal for completing ~user/ paths, we can extend the original pretty easily:

(if (string-match "\\`~\\(.*\\)/\\'" ivy-text)
    (ivy--cd (expand-file-name ivy-text))
    (if (string-match "/\\'" ivy-text)
         (ivy--magic-file-slash)))

Running the patch for a couple days now on my machine hasn't cause problems with tramp paths.

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

Successfully merging this pull request may close these issues.

2 participants