unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* directory specific configuration
@ 2009-07-21 10:30 giampi
  2009-07-21 15:02 ` Thierry Volpiatto
  0 siblings, 1 reply; 7+ messages in thread
From: giampi @ 2009-07-21 10:30 UTC (permalink / raw)
  To: Help-gnu-emacs


Hi all,
short version of the question: is there a way to make emacs read (besides
the local ~/.emacs file) also a directory specific .emacs file, in case that
file exists?

long version: I use emacs to write latex files. I often use different
languages and therefore would like to use different dictionaries in ispell.
I also often split the document in several tex files, so, every time I have
to set the dictionary manually for each file. Each document is in a
different directory, so it would be practical for me to have an automatic
way to always start emacs with the right dictionary depending on the
directory I run from (or, better, depending on the location of the file I
open).

I bet this would require just a few lines of lisp in ~/.emacs that do:
1) get directory of the file I'm opening
2) check if a .emacs file exists for that directory
3) source the .emacs file
Unfortunately I'm no lisp programmer, so any help would be appreciated.

Thank you!
Giampiero

If it is relevant, I'm using GNU Emacs 23.0.91.1 on an Ubuntu 9.04 machine
-- 
View this message in context: http://www.nabble.com/directory-specific-configuration-tp24585256p24585256.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





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

* Re: directory specific configuration
  2009-07-21 10:30 giampi
@ 2009-07-21 15:02 ` Thierry Volpiatto
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Volpiatto @ 2009-07-21 15:02 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

giampi <giampisalvi@gmail.com> writes:

> Hi all,
> short version of the question: is there a way to make emacs read (besides
> the local ~/.emacs file) also a directory specific .emacs file, in case that
> file exists?
>
> long version: I use emacs to write latex files. I often use different
> languages and therefore would like to use different dictionaries in ispell.
> I also often split the document in several tex files, so, every time I have
> to set the dictionary manually for each file. Each document is in a
> different directory, so it would be practical for me to have an automatic
> way to always start emacs with the right dictionary depending on the
> directory I run from (or, better, depending on the location of the file I
> open).
>
> I bet this would require just a few lines of lisp in ~/.emacs that do:
> 1) get directory of the file I'm opening
> 2) check if a .emacs file exists for that directory
> 3) source the .emacs file
> Unfortunately I'm no lisp programmer, so any help would be appreciated.
>
> Thank you!
> Giampiero
>
> If it is relevant, I'm using GNU Emacs 23.0.91.1 on an Ubuntu 9.04 machine

An other approach is to set by file the dictionnary you want to use by
adding these lines at end of your files: (change the comments strings,
depending the mode you use e.g latex)

,----
| # Local Variables:
| # ispell-local-dictionary: "english"
| # End:
`----

With this example when you launch flyspell-mode in this buffer, you will
have the english dictionnary.


-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





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

* Re: directory specific configuration
       [not found] <mailman.2911.1248187239.2239.help-gnu-emacs@gnu.org>
@ 2009-07-21 15:16 ` Pascal J. Bourguignon
  2009-07-21 15:27 ` Dmitry Dzhus
       [not found] ` <mailman.2916.1248190162.2239.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2009-07-21 15:16 UTC (permalink / raw)
  To: help-gnu-emacs

giampi <giampisalvi@gmail.com> writes:

> Hi all,
> short version of the question: is there a way to make emacs read (besides
> the local ~/.emacs file) also a directory specific .emacs file, in case that
> file exists?
>
> long version: I use emacs to write latex files. I often use different
> languages and therefore would like to use different dictionaries in ispell.
> I also often split the document in several tex files, so, every time I have
> to set the dictionary manually for each file. Each document is in a
> different directory, so it would be practical for me to have an automatic
> way to always start emacs with the right dictionary depending on the
> directory I run from (or, better, depending on the location of the file I
> open).
>
> I bet this would require just a few lines of lisp in ~/.emacs that do:
> 1) get directory of the file I'm opening
> 2) check if a .emacs file exists for that directory
> 3) source the .emacs file
> Unfortunately I'm no lisp programmer, so any help would be appreciated.


It would be better to name those files without a prefix dot.  It would
avoid bad surprises.   So assuming that you call those files: config.el
you can easily load these files easily:

   M-x load-file RET ~/some/dir/config.el RET


Actually, if you have a latex file open in that directory, then the
default directory is already that of the latex file where you have
your config.el, so you can just type:

   M-x load-file RET config.el RET


If you only want to change the dictionnary for each latex document,
you could do that with File Variables. (info "(emacs)File Variables")

Put in a comment at the end of the file:

Local Variables:
eval: (ispell-change-dictionary "your-specific-dictionary")
End:

and then when loading again that file, the expression will be
evaluated, and you'll be set.

-- 
__Pascal Bourguignon__


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

* Re: directory specific configuration
       [not found] <mailman.2911.1248187239.2239.help-gnu-emacs@gnu.org>
  2009-07-21 15:16 ` directory specific configuration Pascal J. Bourguignon
@ 2009-07-21 15:27 ` Dmitry Dzhus
  2009-07-21 15:48   ` giampi
       [not found]   ` <mailman.2919.1248191311.2239.help-gnu-emacs@gnu.org>
       [not found] ` <mailman.2916.1248190162.2239.help-gnu-emacs@gnu.org>
  2 siblings, 2 replies; 7+ messages in thread
From: Dmitry Dzhus @ 2009-07-21 15:27 UTC (permalink / raw)
  To: giampi; +Cc: Help-gnu-emacs, dima

giampi wrote:
> directory specific .emacs file

You need directory local variables.

"(emacs)Directory Variables"
-- 
Happy Hacking.

http://sphinx.net.ru^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: directory specific configuration
  2009-07-21 15:27 ` Dmitry Dzhus
@ 2009-07-21 15:48   ` giampi
       [not found]   ` <mailman.2919.1248191311.2239.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: giampi @ 2009-07-21 15:48 UTC (permalink / raw)
  To: Help-gnu-emacs


Hi,
thanks Thierry and Dmitry for your fast answers.

To Thierry: I'll probably use you solution for the time being, but I would
prefer not to add emacs specific lines in the files. I co-author them with
colleagues using other editors (I know they are comment lines that do not
cause problems for others, but it would be cleaner to avoid them).

To Dmitry: directory variables seem to do exactly what I need. A drawback is
that I need to change my "global local" ~/.emacs for each directory I add.
The scenario I'm thinking about is checking out the .tex files from an svn
repository and get the configuration I need with them (regardless of the
computer I'm sitting at). In this scenario it is not easy to automatically
change the ~/.emacs file, and even if I change it manually, it is not
possible to include the changes in svn.

In a perfect world, at least IMHO, emacs would read by default a local
.emacs file, if existent, on opening any file. All the configurations would
therefore be local to that directory. I'm not sure if this would slow down
opening a file.

Is there anything like that?
Thanks again,
Giampiero
-- 
View this message in context: http://www.nabble.com/directory-specific-configuration-tp24585256p24590342.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





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

* Re: directory specific configuration
       [not found]   ` <mailman.2919.1248191311.2239.help-gnu-emacs@gnu.org>
@ 2009-07-22  7:13     ` Peter Brett
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Brett @ 2009-07-22  7:13 UTC (permalink / raw)
  To: help-gnu-emacs

giampi <giampisalvi@gmail.com> writes:

> In a perfect world, at least IMHO, emacs would read by default a local
> .emacs file, if existent, on opening any file. All the configurations would
> therefore be local to that directory. I'm not sure if this would slow down
> opening a file.

Would something like this work (in your main .emacs file)?

(add-hook 'find-file-hook
          (function (lambda ()
                            ; Logic for loading directory-specific
                            ; .emacs file goes here
                            )))

You'd probably need to define a directory-local variable in order to
check if you've already loaded the current directory's config this
session.  Also, don't forget that there is a security risk associated
with blindly running elisp code from anywhere on your disk; consider
putting a y-or-n-p in there somewhere.

                               Peter

-- 
Peter Brett <peter@peter-b.co.uk>
Remote Sensing Research Group
Surrey Space Centre


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

* Re: directory specific configuration
       [not found] ` <mailman.2916.1248190162.2239.help-gnu-emacs@gnu.org>
@ 2009-07-22  8:58   ` Pascal J. Bourguignon
  0 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2009-07-22  8:58 UTC (permalink / raw)
  To: help-gnu-emacs

Dmitry Dzhus <dima@sphinx.net.ru> writes:

> giampi wrote:
>> directory specific .emacs file
>
> You need directory local variables.
>
> "(emacs)Directory Variables"

Which doesn't seem to exist in emacs 22.2.1.

-- 
__Pascal Bourguignon__


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

end of thread, other threads:[~2009-07-22  8:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.2911.1248187239.2239.help-gnu-emacs@gnu.org>
2009-07-21 15:16 ` directory specific configuration Pascal J. Bourguignon
2009-07-21 15:27 ` Dmitry Dzhus
2009-07-21 15:48   ` giampi
     [not found]   ` <mailman.2919.1248191311.2239.help-gnu-emacs@gnu.org>
2009-07-22  7:13     ` Peter Brett
     [not found] ` <mailman.2916.1248190162.2239.help-gnu-emacs@gnu.org>
2009-07-22  8:58   ` Pascal J. Bourguignon
2009-07-21 10:30 giampi
2009-07-21 15:02 ` Thierry Volpiatto

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