* elisp function to find pwd
@ 2008-11-13 9:13 Vijay Lakshminarayanan
2008-11-13 10:06 ` Shaun Johnson
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Vijay Lakshminarayanan @ 2008-11-13 9:13 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: elisp function to find pwd
2008-11-13 9:13 elisp function to find pwd Vijay Lakshminarayanan
@ 2008-11-13 10:06 ` Shaun Johnson
2008-11-13 19:38 ` Nikolaj Schumacher
2008-11-14 23:59 ` B. T. Raven
2 siblings, 0 replies; 5+ messages in thread
From: Shaun Johnson @ 2008-11-13 10:06 UTC (permalink / raw)
To: Vijay Lakshminarayanan; +Cc: help-gnu-emacs
Hi Vijay,
Not a function but the buffer local variable default-directory. This is what pwd uses.
S.
Vijay Lakshminarayanan wrote:
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: elisp function to find pwd
2008-11-13 9:13 elisp function to find pwd Vijay Lakshminarayanan
2008-11-13 10:06 ` Shaun Johnson
@ 2008-11-13 19:38 ` Nikolaj Schumacher
2008-11-14 23:59 ` B. T. Raven
2 siblings, 0 replies; 5+ messages in thread
From: Nikolaj Schumacher @ 2008-11-13 19:38 UTC (permalink / raw)
To: Vijay Lakshminarayanan; +Cc: help-gnu-emacs
Vijay Lakshminarayanan <liyer.vijay@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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: elisp function to find pwd
2008-11-13 9:13 elisp function to find pwd Vijay Lakshminarayanan
2008-11-13 10:06 ` Shaun Johnson
2008-11-13 19:38 ` Nikolaj Schumacher
@ 2008-11-14 23:59 ` B. T. Raven
2008-11-17 5:14 ` Vijay Lakshminarayanan
2 siblings, 1 reply; 5+ messages in thread
From: B. T. Raven @ 2008-11-14 23:59 UTC (permalink / raw)
To: help-gnu-emacs
Vijay Lakshminarayanan wrote:
> 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
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: elisp function to find pwd
2008-11-14 23:59 ` B. T. Raven
@ 2008-11-17 5:14 ` Vijay Lakshminarayanan
0 siblings, 0 replies; 5+ messages in thread
From: Vijay Lakshminarayanan @ 2008-11-17 5:14 UTC (permalink / raw)
To: help-gnu-emacs
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-11-17 5:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-13 9:13 elisp function to find pwd Vijay Lakshminarayanan
2008-11-13 10:06 ` Shaun Johnson
2008-11-13 19:38 ` Nikolaj Schumacher
2008-11-14 23:59 ` B. T. Raven
2008-11-17 5:14 ` Vijay Lakshminarayanan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).