Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

elisp function to find pwd

943 views
Skip to first unread message

Vijay Lakshminarayanan

unread,
Nov 13, 2008, 4:13:04 AM11/13/08
to
Hi

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

Shaun Johnson

unread,
Nov 13, 2008, 5:06:23 AM11/13/08
to Vijay Lakshminarayanan, help-gn...@gnu.org
Hi Vijay,

Not a function but the buffer local variable default-directory. This is what pwd uses.

S.

Nikolaj Schumacher

unread,
Nov 13, 2008, 2:38:13 PM11/13/08
to Vijay Lakshminarayanan, help-gn...@gnu.org
Vijay Lakshminarayanan <liyer...@gmail.com> wrote:

> 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


B. T. Raven

unread,
Nov 14, 2008, 6:59:14 PM11/14/08
to

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

Vijay Lakshminarayanan

unread,
Nov 17, 2008, 12:14:16 AM11/17/08
to
> On Nov 15, 4:59 am, "B. T. Raven" <ni...@nihilo.net> wrote:
> 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?"

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

0 new messages