emacselisp

Emacs, how to get directory of current buffer?


In emacs there is buffer-file-name that gives the full path to a file. But is there a way to get only the directory of the file loaded in the current buffer?


Solution

  • You can use the default-directory variable.

    Documentation: Name of default directory of current buffer. Should end with slash. To interactively change the default directory, use command `cd'.

    Note that expand-file-name will use default-directory by default, so sometimes you don't even need to mention it.