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

Feature request: search symlinked file, but make the file path in "*rg*" buffer the path of the symlink #156

Closed
QiangF opened this issue Jun 9, 2023 · 6 comments

Comments

@QiangF
Copy link

QiangF commented Jun 9, 2023

People use symlinks to organize text documents, a file may have links in different dirs. For example, if we use dirs as catalogues, when a file is opened following the search result in a "rg" buffer, it would be convenient to jump to the catalogue by just M-x "dired". However, the current behavior is to jump to the dir that has the symlink destination file. For people using git-annex, the symlink destination dir could be a database dir, and it is not supposed to be accessed directly.

This request is to change the "default-directory" based on the search dir, not based on where the symlink destination dir.

@dajva
Copy link
Owner

dajva commented Jun 15, 2023

Not sure I understand fully what you mean here. Could you give a more explicit example how a real directory structure with symlinks and all, what search you do in what dir and what you would expect to come out of it.

@QiangF
Copy link
Author

QiangF commented Jun 16, 2023

Here is an example, the annex dir is managed with git-annex, and in the android dir I have several symlinks:

q@desktop:android$ pwd
/home/q/my_lib/annex/android
q@desktop:android$ ls -la
total 20
drwxr-xr-x  3 q wheel 4096 2023-04-11 16:55 ./
drwxr-xr-x 21 q  1000 4096 2023-04-20 21:40 ../
lrwxrwxrwx  1 q wheel  197 2023-03-09 08:45 antennapod-feeds-2023-03-08.opml -> ../.git/annex/objects/xv/KJ/SHA256E-s4940--902506c74d2775e2e244b5cabc35df59f521356033740162b2d181703cadffbc.opml/SHA256E-s4940--902506c74d2775e2e244b5cabc35df59f521356033740162b2d181703cadffbc.opml
lrwxrwxrwx  1 q wheel  199 2023-03-09 08:45 contacts.vcf -> ../.git/annex/objects/zq/9w/SHA256E-s122001--82077ded2603a512e7b60b55ee4d968b42a23b5808993d97972f1f1224e15ce8.vcf/SHA256E-s122001--82077ded2603a512e7b60b55ee4d968b42a23b5808993d97972f1f1224e15ce8.vcf
drwxr-xr-x  4 q wheel 4096 2023-04-17 08:54 okaypad_okaybook/

Now I search for "english" with emacs rg in the android dir:

-*- mode: rg; default-directory: "~/my_lib/annex/android/" -*-
rg started at Fri Jun 16 09:25:04

/usr/bin/rg --color=always --colors=match:fg:red --colors=path:fg:magenta --colors=line:fg:green --colors=column:none -n --column -z --pcre2 -L -i --heading --no-config --type-add=custom\:\* --type=custom -e english

File: antennapod-feeds-2023-03-08.opml
  15  60     <outline text="Science &amp; Technology - VOA Learning English" title="Science &amp; Technology - VOA Learning English" type="rss" xmlUrl="https://learningenglish.voanews.com/podcast/?count=50&amp;zoneId=1579" htmlUrl="https://learningenglish.voanews.com/z/1579" />
  22  33     <outline text="VOA Learning English Podcast - VOA Learning English" title="VOA Learning English Podcast - VOA Learning English" type="rss" xmlUrl="https://learningenglish.voanews.com/podcast/?count=20&amp;zoneId=1689" htmlUrl="https://learningenglish.voanews.com/z/1689" />

rg finished (10 matches found) at Fri Jun 16 09:25:04

Now I move point to the first match line (line with 15 60), and press enter. The file is opend, but the file path is:

~/my_lib/annex/.git/annex/objects/xv/KJ/SHA256E-s4940--902506c74d2775e2e244b5cabc35df59f521356033740162b2d181703cadffbc.opml/SHA256E-s4940--902506c74d2775e2e244b5cabc35df59f521356033740162b2d181703cadffbc.opml

The path above (let me call it path1) is not the symlink path "~/my_lib/annex/android/antennapod-feeds-2023-03-08.opml". From path1 you can not jump to the dir that contains the symlink.

@QiangF
Copy link
Author

QiangF commented Jun 16, 2023

I have tried this:

(remove-hook 'find-file-hook #'vc-refresh-state)

@dajva
Copy link
Owner

dajva commented Jun 16, 2023

Ok, now I understand. So you essentially don't want symlinks to be resolved when jumping to a file.
This is handled by the upstream compile package in emacs, more specifically compilation-find-file seems to do the job here. I suggest you dig into that and see what's going on. I think I have seen the opposite from emacs xref buffers, iow that symlinks are not resolved so might be something that may be tweakable.

@QiangF QiangF closed this as completed Jun 17, 2023
@QiangF
Copy link
Author

QiangF commented Jun 17, 2023

One possible way to disable the symlink resolving is to open the file before compile-find-file. I just removed the file-truename function from compile-find-file, works for me now.

@dajva
Copy link
Owner

dajva commented Jun 17, 2023

This should probably be exposed as a customization of the compilation package. But that would be an emacs bug to report.

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