* window local var?
@ 2010-09-06 11:39 Marc Weber
2010-09-06 18:43 ` Andrea Crotti
0 siblings, 1 reply; 5+ messages in thread
From: Marc Weber @ 2010-09-06 11:39 UTC (permalink / raw)
To: help-gnu-emacs
Hi list,
I used Vim in the past heavily - meaning I'm still learning about the
"Emacs" way of doing things. Vimpulse is doing a great job for me :)
I've learned about emacsclient.
However one of the most used actions I run is
- grep
- gnu id utils
- kind of compiler (eg make)
And they all depend on a current directory (most of the time)
So when starting Emacs, can I create a window local var keeping the
directory in mind I started this Emacs window from?
Then I could create custom functions switching current directory before
running grep, make, etc.
If there are no window local vars - Is there a kind of window id (for
both X and terminal) I could use to associate a directory with?
Marc Weber
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: window local var?
2010-09-06 11:39 window local var? Marc Weber
@ 2010-09-06 18:43 ` Andrea Crotti
2010-09-06 19:00 ` Marc Weber
0 siblings, 1 reply; 5+ messages in thread
From: Andrea Crotti @ 2010-09-06 18:43 UTC (permalink / raw)
To: help-gnu-emacs
Marc Weber <marco-oweber@gmx.de> writes:
> Hi list,
>
> I used Vim in the past heavily - meaning I'm still learning about the
> "Emacs" way of doing things. Vimpulse is doing a great job for me :)
>
> I've learned about emacsclient.
>
> However one of the most used actions I run is
> - grep
> - gnu id utils
> - kind of compiler (eg make)
>
> And they all depend on a current directory (most of the time)
>
> So when starting Emacs, can I create a window local var keeping the
> directory in mind I started this Emacs window from?
>
> Then I could create custom functions switching current directory before
> running grep, make, etc.
>
> If there are no window local vars - Is there a kind of window id (for
> both X and terminal) I could use to associate a directory with?
>
> Marc Weber
When running those things in the current buffer directory is what you
normally want..
A fast way to use your own path could also be just doing
M-x grep -nH -e "string" /path/
where also the /path/ has the smart completion.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: window local var?
2010-09-06 18:43 ` Andrea Crotti
@ 2010-09-06 19:00 ` Marc Weber
2010-09-07 0:34 ` PJ Weisberg
0 siblings, 1 reply; 5+ messages in thread
From: Marc Weber @ 2010-09-06 19:00 UTC (permalink / raw)
To: help-gnu-emacs
Hi Andrea,
I know how to use grep.
I don't want to use the buffer directory.
I want to use the directory from which I started Emacs (or emacs-client)
In order to do so I have to remember the directory when
a) launching Emacs
b) launching Emacs-client
However b) must not override the setting set in a)
a) and b) have different windows / frames (however you call them).
That's why I was asking for such a frame local var.
Thanks
Marc Weber
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: window local var?
2010-09-06 19:00 ` Marc Weber
@ 2010-09-07 0:34 ` PJ Weisberg
2010-09-07 16:12 ` PJ Weisberg
0 siblings, 1 reply; 5+ messages in thread
From: PJ Weisberg @ 2010-09-07 0:34 UTC (permalink / raw)
To: Marc Weber; +Cc: help-gnu-emacs
Note that I'm sort of am Emacs/Lisp newbie myself, so I'd appreciate
it if anyone on the list who thinks there's a better way to do this
would share.
Frames have "parameters". You can set them with
"(modify-frame-parameters frame '((var . value)))" and get them with
"(frame-parameter frame var)". The current frame is
"(selected-frame)".
Use modify-all-frame-parameters instead of modify-frame-parameters to
change the value for all existing frames and all frames created in the
future.
One of the properties that frames start out with is 'environment,
which contains all the client's environment variables, including PWD.
So, to find the current directory, you could use:
(let ((env (frame-parameter (selected-frame) 'environment))
(current nil)
(dir nil))
(while (and (not dir) t)
(setq current (pop env))
(if (string-equal "PWD=" (subseq current 0 4))
(setq dir (subseq current 4))))
dir)
There's a buffer-local variable called default-directory that you can
set to control where grep gets run, like this: "(push (lambda() (setq
default-directory some-directory)) grep-setup-hook)".
On Mon, Sep 6, 2010 at 12:00 PM, Marc Weber <marco-oweber@gmx.de> wrote:
> Hi Andrea,
>
> I know how to use grep.
>
> I don't want to use the buffer directory.
> I want to use the directory from which I started Emacs (or emacs-client)
>
> In order to do so I have to remember the directory when
>
> a) launching Emacs
>
> b) launching Emacs-client
>
> However b) must not override the setting set in a)
> a) and b) have different windows / frames (however you call them).
> That's why I was asking for such a frame local var.
>
> Thanks
> Marc Weber
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: window local var?
2010-09-07 0:34 ` PJ Weisberg
@ 2010-09-07 16:12 ` PJ Weisberg
0 siblings, 0 replies; 5+ messages in thread
From: PJ Weisberg @ 2010-09-07 16:12 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, Sep 6, 2010 at 5:34 PM, PJ Weisberg <pj@irregularexpressions.net> wrote:
> (let ((env (frame-parameter (selected-frame) 'environment))
> (current nil)
> (dir nil))
> (while (and (not dir) t)
> (setq current (pop env))
> (if (string-equal "PWD=" (subseq current 0 4))
> (setq dir (subseq current 4))))
> dir)
Um, that "t" in the conditional was supposed to be "env". I wanted to
see what error I would get if I let it fall off the end of the list
without finding anything, and I forgot to put the check back in before
I pasted it into the mail. :-/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-09-07 16:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-06 11:39 window local var? Marc Weber
2010-09-06 18:43 ` Andrea Crotti
2010-09-06 19:00 ` Marc Weber
2010-09-07 0:34 ` PJ Weisberg
2010-09-07 16:12 ` PJ Weisberg
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).