unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Per-directory customizations?
@ 2004-04-30 12:30 Roy Smith
  2004-04-30 15:38 ` Kin Cho
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Roy Smith @ 2004-04-30 12:30 UTC (permalink / raw)


Is there any way to do customizations on a per-directory basis?

For example, I've got java project which lives in ~/dev/foo.  Anytime I 
run M-X compile anywhere inside the ~/dev/foo hierarchy, I want the 
command run to be "cd ~/dev/foo; ant".  I don't want to just set 
compile-command in my .emacs file, because the right command varies 
depending on which project (i.e. directory subtree) I'm in.

Is there any way to do this?  I'm running GNU Emacs 21.2.1.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 12:30 Per-directory customizations? Roy Smith
@ 2004-04-30 15:38 ` Kin Cho
  2004-04-30 19:01   ` Kevin Rodgers
  2004-04-30 17:13 ` Vagn Johansen
  2004-04-30 21:14 ` Stefan Monnier
  2 siblings, 1 reply; 11+ messages in thread
From: Kin Cho @ 2004-04-30 15:38 UTC (permalink / raw)


I do something similar, with defadvice of compile-internal, and
setq compile-command depending on default-directory.

-kin

Roy Smith <roy@panix.com> writes:

> Is there any way to do customizations on a per-directory basis?
> 
> For example, I've got java project which lives in ~/dev/foo.  Anytime I 
> run M-X compile anywhere inside the ~/dev/foo hierarchy, I want the 
> command run to be "cd ~/dev/foo; ant".  I don't want to just set 
> compile-command in my .emacs file, because the right command varies 
> depending on which project (i.e. directory subtree) I'm in.
> 
> Is there any way to do this?  I'm running GNU Emacs 21.2.1.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 12:30 Per-directory customizations? Roy Smith
  2004-04-30 15:38 ` Kin Cho
@ 2004-04-30 17:13 ` Vagn Johansen
  2004-04-30 21:14 ` Stefan Monnier
  2 siblings, 0 replies; 11+ messages in thread
From: Vagn Johansen @ 2004-04-30 17:13 UTC (permalink / raw)


Roy Smith <roy@panix.com> writes:

> Is there any way to do customizations on a per-directory basis?
> For example, I've got java project which lives in ~/dev/foo.  Anytime I 
> run M-X compile anywhere inside the ~/dev/foo hierarchy, I want the 
> command run to be "cd ~/dev/foo; ant".  I don't want to just set 
> compile-command in my .emacs file, because the right command varies 
> depending on which project (i.e. directory subtree) I'm in.
>
> Is there any way to do this?  I'm running GNU Emacs 21.2.1.

http://www.emacswiki.org/cgi-bin/wiki.pl/DirVarsPackage

With the dirvars.el package you create a file called .emacs-dirvars in
the root directory containing

    compile-command: "cd ~/dev/foo; ant"

Then this setting is automatically used by the root directory and all
subdirectories.


I use the following to store the current compile-command in a
.emacs-dirvars file.

    (defun vjo-create-dirvars-file (cmd)
      (interactive)
      (if (file-exists-p ".emacs-dirvars")
          (progn
          (find-file ".emacs-dirvars")
          (goto-char (point-max)))
        ;; else
        (progn
          (find-file ".emacs-dirvars")
          (insert ";; -*- emacs-lisp -*- \n")
          (insert ";; VJ\n")
          (insert (concat "compile-command: <QUOTE>" cmd "<QUOTE>\n"))
          (replace-string "\"" "\\\"" nil (previous-line 1) (point))
          (replace-string "<QUOTE>" "\"" nil (previous-line 1) (point))
          (save-buffer))))

-- 
Vagn Johansen

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 15:38 ` Kin Cho
@ 2004-04-30 19:01   ` Kevin Rodgers
  2004-04-30 19:27     ` Roy Smith
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Rodgers @ 2004-04-30 19:01 UTC (permalink / raw)


[Please don't top-post.]

Kin Cho wrote:
 > Roy Smith <roy@panix.com> writes:
 >>Is there any way to do customizations on a per-directory basis?
 >>
 >>For example, I've got java project which lives in ~/dev/foo.  Anytime I
 >>run M-X compile anywhere inside the ~/dev/foo hierarchy, I want the
 >>command run to be "cd ~/dev/foo; ant".  I don't want to just set
 >>compile-command in my .emacs file, because the right command varies
 >>depending on which project (i.e. directory subtree) I'm in.
 >>
 >>Is there any way to do this?  I'm running GNU Emacs 21.2.1.
 >
 > I do something similar, with defadvice of compile-internal, and
 > setq compile-command depending on default-directory.

Why not set compile-command in the mode hook, as suggested in it's doc
string:

(add-hook 'java-mode-hook
	  (lambda ()
	    (when (string-match "\\`~/dev/foo/" default-directory)
	      (set (make-local-variable 'compile-command)
		   "cd ~/dev/foo; ant"))))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 19:01   ` Kevin Rodgers
@ 2004-04-30 19:27     ` Roy Smith
  2004-04-30 23:47       ` Kevin Rodgers
  0 siblings, 1 reply; 11+ messages in thread
From: Roy Smith @ 2004-04-30 19:27 UTC (permalink / raw)


In article <4092A276.8060505@yahoo.com>,
 Kevin Rodgers <ihs_4664@yahoo.com> wrote:

> [Please don't top-post.]
> 
> Kin Cho wrote:
>  > Roy Smith <roy@panix.com> writes:
>  >>Is there any way to do customizations on a per-directory basis?
>  >>
>  >>For example, I've got java project which lives in ~/dev/foo.  Anytime I
>  >>run M-X compile anywhere inside the ~/dev/foo hierarchy, I want the
>  >>command run to be "cd ~/dev/foo; ant".  I don't want to just set
>  >>compile-command in my .emacs file, because the right command varies
>  >>depending on which project (i.e. directory subtree) I'm in.
>  >>
>  >>Is there any way to do this?  I'm running GNU Emacs 21.2.1.
>  >
>  > I do something similar, with defadvice of compile-internal, and
>  > setq compile-command depending on default-directory.
> 
> Why not set compile-command in the mode hook, as suggested in it's doc
> string:
> 
> (add-hook 'java-mode-hook
> 	  (lambda ()
> 	    (when (string-match "\\`~/dev/foo/" default-directory)
> 	      (set (make-local-variable 'compile-command)
> 		   "cd ~/dev/foo; ant"))))

The problem there, is it only works for java files.  I've got all sorts 
of files in my project directory tree (html, css, jsp, etc, etc).  I 
want the compile command tied to the directory tree, not the file type.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 12:30 Per-directory customizations? Roy Smith
  2004-04-30 15:38 ` Kin Cho
  2004-04-30 17:13 ` Vagn Johansen
@ 2004-04-30 21:14 ` Stefan Monnier
  2 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2004-04-30 21:14 UTC (permalink / raw)


> Is there any way to do customizations on a per-directory basis?
> For example, I've got java project which lives in ~/dev/foo.  Anytime I
> run M-X compile anywhere inside the ~/dev/foo hierarchy, I want the
> command run to be "cd ~/dev/foo; ant".  I don't want to just set
> compile-command in my .emacs file, because the right command varies
> depending on which project (i.e. directory subtree) I'm in.

In sml-mode.el, I made the sml-compile command walk up the directory tree
until it finds the Makefile-equivalent.  Maybe M-x compile RET should do
the same: walk up the tree until it finds a Makefile and then use
"cd ../..; make".


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 19:27     ` Roy Smith
@ 2004-04-30 23:47       ` Kevin Rodgers
  2004-04-30 23:54         ` Johan Bockgård
  2004-05-01  0:11         ` Kin Cho
  0 siblings, 2 replies; 11+ messages in thread
From: Kevin Rodgers @ 2004-04-30 23:47 UTC (permalink / raw)


Roy Smith wrote:
 > In article <4092A276.8060505@yahoo.com>,
 >  Kevin Rodgers <ihs_4664@yahoo.com> wrote:
 >>Why not set compile-command in the mode hook, as suggested in it's doc
 >>string:
 >>
 >>(add-hook 'java-mode-hook
 >>	  (lambda ()
 >>	    (when (string-match "\\`~/dev/foo/" default-directory)
 >>	      (set (make-local-variable 'compile-command)
 >> 
	   "cd ~/dev/foo; ant"))))
 >
 > The problem there, is it only works for java files.  I've got all
 > sorts of files in my project directory tree (html, css, jsp, etc,
 > etc).  I want the compile command tied to the directory tree, not the
 > file type.

The use find-file-hooks instead of jave-mode-hook.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 23:47       ` Kevin Rodgers
@ 2004-04-30 23:54         ` Johan Bockgård
  2004-05-01  0:11         ` Kin Cho
  1 sibling, 0 replies; 11+ messages in thread
From: Johan Bockgård @ 2004-04-30 23:54 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Roy Smith wrote:
>> Kevin Rodgers <ihs_4664@yahoo.com> wrote:
>>> Why not set compile-command in the mode hook, as suggested in it's doc
>>> string:
>>>
>>> (add-hook 'java-mode-hook
>>>       (lambda ()
>>>         (when (string-match "\\`~/dev/foo/" default-directory)
>>>           (set (make-local-variable 'compile-command)
>>>        "cd ~/dev/foo; ant"))))
>>
>> The problem there, is it only works for java files. I've got all
>> sorts of files in my project directory tree (html, css, jsp, etc,
>> etc). I want the compile command tied to the directory tree, not
>> the file type.
>
> The use find-file-hooks instead of jave-mode-hook.

There is another way, using

(setq compile-command
      '<lisp expression that evaluates to a string>)

like

(setq compile-command
      '(cond ((string-match "\\`~/dev/foo/" default-directory)
	      "cd ~/dev/foo; ant")
	     (...)
	     ...
	     (t "make -k")))

etc.

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-04-30 23:47       ` Kevin Rodgers
  2004-04-30 23:54         ` Johan Bockgård
@ 2004-05-01  0:11         ` Kin Cho
  2004-05-03 14:12           ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Kin Cho @ 2004-05-01  0:11 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Roy Smith wrote:
>  > In article <4092A276.8060505@yahoo.com>,
>  >  Kevin Rodgers <ihs_4664@yahoo.com> wrote:
>  >>Why not set compile-command in the mode hook, as suggested in it's doc
>  >>string:
>  >>
>  >>(add-hook 'java-mode-hook
>  >>	  (lambda ()
>  >>	    (when (string-match "\\`~/dev/foo/" default-directory)
>  >>	      (set (make-local-variable 'compile-command)
>  >> 	   "cd ~/dev/foo; ant"))))
>  >
>  > The problem there, is it only works for java files.  I've got all
>  > sorts of files in my project directory tree (html, css, jsp, etc,
>  > etc).  I want the compile command tied to the directory tree, not the
>  > file type.
> 
> The use find-file-hooks instead of jave-mode-hook.

This won't work if he uses dired, gnus, man, etc... while in
~/dev/foo/.

-kin

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-05-01  0:11         ` Kin Cho
@ 2004-05-03 14:12           ` Stefan Monnier
  2004-05-03 16:19             ` Kin Cho
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2004-05-03 14:12 UTC (permalink / raw)


>> The use find-file-hooks instead of jave-mode-hook.
> This won't work if he uses dired, gnus, man, etc... while in
> ~/dev/foo/.

I don't see any reason why not.  Care to explain?


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Per-directory customizations?
  2004-05-03 14:12           ` Stefan Monnier
@ 2004-05-03 16:19             ` Kin Cho
  0 siblings, 0 replies; 11+ messages in thread
From: Kin Cho @ 2004-05-03 16:19 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

> >> The use find-file-hooks instead of jave-mode-hook.
> > This won't work if he uses dired, gnus, man, etc... while in
> > ~/dev/foo/.
> 
> I don't see any reason why not.  Care to explain?

find-file-hooks isn't called for a (dired "~/dev/foo/") buffer,
so compile-command won't be customized for the dired buffer, and
so M-x compile in that buffer won't do what he wants.

-kin

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-05-03 16:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-30 12:30 Per-directory customizations? Roy Smith
2004-04-30 15:38 ` Kin Cho
2004-04-30 19:01   ` Kevin Rodgers
2004-04-30 19:27     ` Roy Smith
2004-04-30 23:47       ` Kevin Rodgers
2004-04-30 23:54         ` Johan Bockgård
2004-05-01  0:11         ` Kin Cho
2004-05-03 14:12           ` Stefan Monnier
2004-05-03 16:19             ` Kin Cho
2004-04-30 17:13 ` Vagn Johansen
2004-04-30 21:14 ` Stefan Monnier

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).