I'd like to know if there exists a simple elisp function that I can
call and just get the present working directory.
I tried (pwd) but it gives a prefix. For example:
(pwd)
"Directory C:\\emacs-22.2\\bin/"
Which prefixes "Directory" to the result. I could just strip that bit
out but I'd like to know if there's an easier way.
Another hack I tried is:
(defun get-pwd-hack ()
(let* ((buffer-name (buffer-name))
(buffer-file-name (buffer-file-name))
(bnl (length buffer-name))
(bfnl (length buffer-file-name)))
(substring buffer-file-name 0 (- bfnl (1+ bnl)))))
Which will fail if I'm in, say, the *scratch* buffer.
Thanks
Vijay
Not a function but the buffer local variable default-directory. This is what pwd uses.
S.
> Which prefixes "Directory" to the result. I could just strip that bit
> out but I'd like to know if there's an easier way.
With Emacs, you can find out yourself very easily. Do
C-h f pwd
then click on the link.
It will take you to the function's source code and you can see what it
uses.
regards,
Nikolaj Schumacher
Why not just:
(substring (pwd) 10)
which happens to yield
"C:\\mydocu~1/"
on my system (i.e. (pwd) without the prefix). Also works in *scratch*.
Why is this not "easier?"
Ed
I also have a GNU/Linux machine and it might have a different prefix.
Also, if you need to discard a prefix to get at the original there /
has/ to be an easier way. If I hadn't found one, I would have used
either the first solution or extracting the substring. But Shaun's
answer is exactly what I had been looking for.
On Nov 13, 3:06 pm, Shaun Johnson <sh...@slugfest.demon.co.uk> wrote:
> Not a function but the buffer local variable default-directory. This is what pwd uses.
Thanks Shaun. This is exactly what I needed.
Cheers
~Vijay