How can I find the directory where a function is being called from?
For example, if I call the line
(defconst dir default-directory)
The value of dir is the directory where the fine containing the above line is, not the directory I am calling it from.
Thanks in advance
The default behaviour in Emacs is to use the directory associated with the file being "visited" in the current buffer. So,
(file-name-directory (buffer-file-name))
should give you the directory name of the file of the current buffer (i.e., the one you are currently working with at the time, your custom Lisp function is called).
If you are not sure, whether your custom function is called in the context of a buffer, which already has a file name associated with it, you should test for this:
(let ((file (buffer-file-name)))
(if (not file)
(progn ... no file name here ...)
... ok, file name available ...))