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

Don't resolve symlinks in path #51

Closed
ghost opened this issue Nov 26, 2018 · 21 comments
Closed

Don't resolve symlinks in path #51

ghost opened this issue Nov 26, 2018 · 21 comments

Comments

@ghost
Copy link

ghost commented Nov 26, 2018

Resolving symlinks is causing doom-mode line to display a ridiculous path for a file that lives in my home directory.

2018-11-26-182317_1662x49_scrot

@seagle0128
Copy link
Owner

seagle0128 commented Nov 27, 2018

Well, I have to say it's as designed. You need this config.

(setq find-file-visit-truename t)

If the file is controlled by vc, refer to vc-follow-symlinks, please.

@ghost
Copy link
Author

ghost commented Nov 27, 2018

Thank you for the help!

@ghost ghost closed this as completed Nov 27, 2018
seagle0128 added a commit that referenced this issue Nov 27, 2018
@seagle0128 seagle0128 added the help wanted Extra attention is needed label Dec 3, 2018
@CeleritasCelery
Copy link

I realize that this issue was closed and that the solution find-file-vist-truename worked for OP, but I do not want to change the behavior of my editor to fix the path in the modeline. Nearly every file I use is a symlink to a NFS so my modeline has become very long and cluttered. I want to visit the symlink and not the true path. I have a hacked the code in my doom-modeline repo to fix this, but I was wondering if you would be open to making this an optional feature that could be disabled to restore a saner path. I could put together a PR if that would be helpful.

@seagle0128
Copy link
Owner

@CeleritasCelery Well, thank you for the comments. Can you please share your codes? PR is always welcome as long as it makes sense. I need to think over it and any ideas are also welcome.

@CeleritasCelery
Copy link

all my code does is swap buffer-file-name and buffer-file-truename this line.
it looks it would also require a conditional around this code. Does that seem like the best insertion points?

@seagle0128
Copy link
Owner

seagle0128 commented Jan 4, 2019

@CeleritasCelery Thanks for sharing!

But I don't think it's the solution. The change may impact other scenarios. If you just want to visit the symlink while not the true files, why should show file true name in modeline? It doesn't make sense. My suggestion is change find-file-visit-truename or use buffer-name style, or manage the file via vcs.

More thoughts?

@CeleritasCelery
Copy link

If you visit the true name it changes your default-directory. If I navigate to a file and chase it through a symlink with find-file-visit-true-name I can no longer go back up a directory to where I was before. I may visit a file that has other files in the same directory, but since it is a symlink, when I open dired or find-file all those files are gone and I have to try and get back to the original directory.

The whole point of symlinks is to have a pointer to a remote file but have it act as though is is integrated into your file system. visiting the true name breaks that utility.

@ghost
Copy link
Author

ghost commented Jan 5, 2019

I fully agree with what @CeleritasCelery has to say above. I marked this as resolved as it was partially resolved with the above. It shortened my path a little, but it's still a mess. Again the point of having symlinks for me is to shorten a long path. Not resolve it. Also using them with a NFS share.

@seagle0128
Copy link
Owner

Can you try this on your env?

(defun doom-modeline-buffer-file-name ()
  "Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
  (let* ((buffer-file-name (file-local-name (or (buffer-file-name (buffer-base-buffer)) "")))
         (buffer-file-truename (file-local-name (or buffer-file-truename (file-truename buffer-file-name) "")))
         (buffer-file-name (expand-file-name buffer-file-truename)))
    (propertize
     (pcase doom-modeline-buffer-file-name-style
       (`truncate-upto-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
       (`truncate-from-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename nil 'shrink))
       (`truncate-with-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink 'shink 'hide))
       (`truncate-except-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink 'shink))
       (`truncate-upto-root
        (doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
       (`truncate-all
        (doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename t))
       (`relative-to-project
        (doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
       (`relative-from-project
        (doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
       (style
        (propertize
         (pcase style
           (`file-name (file-name-nondirectory buffer-file-name))
           (`buffer-name (buffer-name)))
         'face
         (let ((face (or (and (buffer-modified-p)
                              'doom-modeline-buffer-modified)
                         (and (doom-modeline--active)
                              'doom-modeline-buffer-file))))
           (when face `(:inherit ,face))))))
     'help-echo (concat buffer-file-truename
                        (unless (string= (file-name-nondirectory buffer-file-truename)
                                         (buffer-name))
                          (concat "\n" (buffer-name)))
                        "\nmouse-1: Previous buffer\nmouse-3: Next buffer")
     'local-map mode-line-buffer-identification-keymap)))

@CeleritasCelery
Copy link

That did not make any difference for me. However this code worked

(defun doom-modeline-buffer-file-name ()
  "Propertized variable `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
  (let* ((buffer-file-name (file-local-name (or (buffer-file-name (buffer-base-buffer)) "")))
         (buffer-file-truename buffer-file-name))
    (propertize
     (pcase doom-modeline-buffer-file-name-style
       (`truncate-upto-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink))
       (`truncate-from-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename nil 'shrink))
       (`truncate-with-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink 'shink 'hide))
       (`truncate-except-project
        (doom-modeline--buffer-file-name buffer-file-name buffer-file-truename 'shrink 'shink))
       (`truncate-upto-root
        (doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename))
       (`truncate-all
        (doom-modeline--buffer-file-name-truncate buffer-file-name buffer-file-truename t))
       (`relative-to-project
        (doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename))
       (`relative-from-project
        (doom-modeline--buffer-file-name-relative buffer-file-name buffer-file-truename 'include-project))
       (style
        (propertize
         (pcase style
           (`file-name (file-name-nondirectory buffer-file-name))
           (`buffer-name (buffer-name)))
         'face
         (let ((face (or (and (buffer-modified-p)
                              'doom-modeline-buffer-modified)
                         (and (doom-modeline--active)
                              'doom-modeline-buffer-file))))
           (when face `(:inherit ,face))))))
     'help-echo (concat buffer-file-truename
                        (unless (string= (file-name-nondirectory buffer-file-truename)
                                         (buffer-name))
                          (concat "\n" (buffer-name)))
                        "\nmouse-1: Previous buffer\nmouse-3: Next buffer")
     'local-map mode-line-buffer-identification-keymap)))

@seagle0128
Copy link
Owner

seagle0128 commented Jan 7, 2019

Hmm, but that codes do not make sense to me 😢
I'm curious whether the issue exists for the local symlinks? In my env, it looks right.

image

Which style are you using? Can you try truncate-upto-project style with the latest version?

@ghost
Copy link
Author

ghost commented Jan 7, 2019

I put @seagle0128 's code into my config.org after I loaded doom-mode line in my config and this is what my bar looks like currently.

2019-01-07-142236_474x42_scrot

config.org is in in ~/org/config.org and the ~org dir is a symlink to ~/dev/active/dotfiles/emacs/.emacs.d/ which I manage with gnu stow.

I'm also on Freebsd which has /home sym linked to /usr/home in the base system. So theirs a lot going on there.

@seagle0128
Copy link
Owner

@gregf how about using the latest version without any changes? what does it look like?

@ghost
Copy link
Author

ghost commented Jan 7, 2019

2019-01-07-151125_844x48_scrot

On doom-modeline-20190107.1829 form melpa

@ghost
Copy link
Author

ghost commented Jan 7, 2019

This is how I have doom-modeline configured btw.

(use-package doom-modeline
:ensure t
:defer t
:config
(setq column-number-mode t)
(setq doom-modeline-major-mode-icon t)
:hook (after-init . doom-modeline-init))

@CeleritasCelery
Copy link

I realize that I did not start emacs, so perhaps the reason mine did change would be because the cached root value was unchanged.

@CeleritasCelery
Copy link

@seagle0128 one thing I want to point out about the code snippet you provided, is that although it makes the path look much cleaner, it is still using the truename, which does not match the default-directory or buffer-file-name and is therefore less useful.

@seagle0128
Copy link
Owner

@CeleritasCelery Can you provide the detailed steps to reproduce your issue? I could't reproduce in my env. I need more info, e.g. which style of doom-modeline-buffer-file-name-style, version of doom-modeline, directory and symlinks information, etc.

In #51 (comment), you can see all look fine in my env.

@CeleritasCelery
Copy link

Is that a symlink in your example?

@seagle0128
Copy link
Owner

Of course. test.txt is a Sumlin. I also tried with directory symlinks.

@seagle0128 seagle0128 removed the help wanted Extra attention is needed label Jul 20, 2019
seagle0128 added a commit that referenced this issue Aug 19, 2019
@seagle0128
Copy link
Owner

I think this issue has been resolved.

This issue was closed.
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