reddit / emacs

abbreviate-file-name and abbrev-file-alist not working?

kkrrp1 · 2022-08-26 22:52
I'm having trouble getting this function to work right (or properly set the alist). I have Onedrive who's main directory is a symlink and I'd like to keep /Library/CloudStorage urls from being shown throughout Emacs.(macos) The default-dirctory is showing how I want it to. ​ As I understand buffer-file-truename should be using abbrev-file-alist via abbreviate-file-name function to do this. I've narrowed my issue down to this function not abbreviating urls. ​ abbrev-file-alist value: (("\\\\\`'/Users/username/Library/CloudStorage/OneDrive" . "/Users/username/OneDrive")) Function: (abbreviate-file-name "/Users/username/Library/CloudStorage/OneDrive") Returns: "\~/Library/CloudStorage/OneDrive" Function: (abbreviate-file-name "\~/Library/CloudStorage/OneDrive") Returns: "\~/Library/CloudStorage/OneDrive" ​ Does anyone know what may be wrong with my list? EDIT: The fix to make my Onedrive dirs always show symlinked/abbreviated paths: (setq-default abbrev-mode t) (setq find-file-visit-truename nil) (setq directory-abbrev-alist (cons '("\\`/Users/username/Library/CloudStorage/OneDrive/" . "/Users/username/OneDrive") directory-abbrev-alist)) ; Figured I'd add that the below addition to the alist wasn't necessary. ;(setq directory-abbrev-alist (cons '("\\`~/Library/CloudStorage/OneDrive/" . "~/OneDrive/") directory-abbrev-alist))
akirakom · 2022-08-27 21:01
Isn't it directory-abbrev-alist? EDIT: I think the variable name should be `directory-abbrev-alist`. I also noticed that the directory names should be suffixed with `/`.
[deleted] · 2022-08-29 16:18
[deleted]
[deleted] · 2022-08-29 16:58
[deleted]
kkrrp1 · 2022-08-29 17:28
Thanks for the help! Sorry I think having the function in my head mixed me up. It was directory-abbrev-alist that was set I just typed it wrong here. I removed the single quote after the back tick in the regexp, added "/" suffix, and the function abbreviate-file-name is now returning properly. I then used unabbreviated home-dir for the alist which seems to have my buffer-file-truename showing correctly for files.