0

I am curious about the origin of certain files under ~/.emacs.d, such as: places, url/cookies, tramp, eshell/history, eshell/lastdir, auto-save-list/.saves-15234-mymachine~, request/curl-cookie-jar.

I'd like to know not only where they came from, but what variable I need to set in order to relocate them to other locations of my choosing.

To further my investigation of these files, I'd like to get a backtrace from Emacs when it opens any of them (or any other files of my choosing). Is there a way to do that?

8
  • Can you give examples (names) of such files? Are you talking about auto-save files (#...#)? backup files (...~, ...~999~)?
    – Drew
    Commented Nov 10, 2018 at 18:19
  • All of the following under ~/.emacs.d: places, url/cookies, tramp, eshell/history, eshell/lastdir, auto-save-list/.saves-15234-mymachine~, request/curl-cookie-jar. I can guess that tramp comes from using TRAMP, but what variable do I need to change to have it be created somewhere else instead? Same with the rest. I'd like to track these down in the general case by looking at backtraces when they're opened.
    – izkon
    Commented Nov 10, 2018 at 20:43
  • Please put all such relevant info in the question. Comments can be deleted at any time.
    – Drew
    Commented Nov 10, 2018 at 22:11
  • Can you elaborate on why you want to do this? The ~/.emacs.d directory is supposed to contain such things. Some are configurable, but you may not be able to relocate all such files without modifying the libraries in question. A few such cases may support "old" alternative filenames in the HOME directory, via the OLD-NAME argument to locate-user-emacs-file, in which cases you could move the file from its ~/.emacs.d location to its old name, and it would still be used; but the modern intention is that such files and directories live under ~/.emacs.d/.
    – phils
    Commented Nov 11, 2018 at 5:05
  • @phils: Many reasons. First, because it's an awful mess in there. Whenever I need to troubleshoot anything or figure out why something is where it is or change something I have no idea why these files are in there or how they affect Emacs or what package they belong to even. I like no-littering's suggestion of prefixing every filename with the respective package name, but even that alone is not enough for me. I want control over where every file lives... (continued in next comment)
    – izkon
    Commented Nov 11, 2018 at 9:01

1 Answer 1

1

The advice framework is good for this sort of thing. You could advise low-level functions like write-region and insert-file-contents (those probably offer good coverage). One way would be to use a function that logs both the filename and a stack trace. Something like the following:

(advice-add
 #'insert-file-contents :before
 (lambda (&rest args)
   (message "Interesting function called with args: %s" args)
   (backtrace)))

This will probably give you a /lot/ of output in your *Messages* buffer, so a more conservative function might be needed.

4
  • But I don't want to log on every file access, but only when certain specific files are opened (when they're first opened, ideally). Could I do that?
    – izkon
    Commented Nov 11, 2018 at 9:08
  • @izkon Sure. You could track filenames by adding them to a list or hashtable. You could also use a function like f-child-of-p (from the f package) to filter your logging as well. It sounds like you just want to explore though (a one-time thing?), so I personally would just search through the messages buffer.
    – ebpa
    Commented Nov 11, 2018 at 16:19
  • f-child-of-p check to see if one path is a child of another path. I'm not sure I understand how that helps.
    – izkon
    Commented Nov 11, 2018 at 19:11
  • 1
    @izkon I mention that since you said "certain files under ~/.emacs.d". A predicate like that might offer a useful constraint. If you advise insert-file-contents the first argument is the filename, so you could condition your advise logging on that filename meeting some criteria like (when (f-child-of-p filename "~/.emacs.d") ... to only log if it's a file immediately inside your init folder.
    – ebpa
    Commented Nov 11, 2018 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.