unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Eval elisp file automatically
@ 2011-01-30 11:17 Andrea Crotti
  0 siblings, 0 replies; 7+ messages in thread
From: Andrea Crotti @ 2011-01-30 11:17 UTC (permalink / raw)
  To: help-gnu-emacs

I have some functions and variables which I only need in one particular
directory.

Now it would be nice that the first time that I visit a file in that
subdirectory the file "elisp.el" gets evaluated.

Using find-file-hook might be easy, but How can I make it evaluate only
once?

Another cool thing would be to reset to the defaut value the variables
when I'm not, but it's not really necessary...




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

* Re: Eval elisp file automatically
       [not found] <mailman.4.1296386344.21090.help-gnu-emacs@gnu.org>
@ 2011-01-30 11:42 ` Tim X
  2011-02-08 14:54   ` Andrea Crotti
  2011-01-31  9:35 ` José A. Romero L.
  2011-01-31 16:20 ` Stefan Monnier
  2 siblings, 1 reply; 7+ messages in thread
From: Tim X @ 2011-01-30 11:42 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> I have some functions and variables which I only need in one particular
> directory.
>
> Now it would be nice that the first time that I visit a file in that
> subdirectory the file "elisp.el" gets evaluated.
>
> Using find-file-hook might be easy, but How can I make it evaluate only
> once?
>
> Another cool thing would be to reset to the defaut value the variables
> when I'm not, but it's not really necessary...
>

Emacs does support .dir-locals, which provides functionality similar to
file variables, but at the directory level. See the section on
Per-Directory local variables in the manual. However, your request seems
slightly misguided to me. I'm not trying to be rude, but do wonder what
you feel this will achieve or what problem will it address?

My suspicion is there is a either a better solution or you are concerned
about a non-problem for elisp or I'm just not understanding what you are
trying to do. 

The standard ways to address the function issue is to use autoloads or
provide/require, which you either put in a file or possibly a load hook
so that the functions are only loaded when you load some other mode etc. 

Your reference to restoring default values sounds like you may be
talking about buffer local variables, but I'm not sure. These variables
are like other variables, except when you modify them, thos
modifications are local to the buffer in which it occured. IN this way,
the variables sort of have a default 'global' value and a local value.
Any reference made to the variable outside the buffer that has set it as
a local variable will see the global (default) value. Once you set that
variable to a new value, that new value will be seen by code running in
that buffer, but other buffers (who have not set their own local copy)
will see the global value.

Normally, you just don't bother undefining functions or variables. The
effort it takes is not worth the resources saved. 


Tim


-- 
tcross (at) rapttech dot com dot au


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

* Re: Eval elisp file automatically
       [not found] <mailman.4.1296386344.21090.help-gnu-emacs@gnu.org>
  2011-01-30 11:42 ` Eval elisp file automatically Tim X
@ 2011-01-31  9:35 ` José A. Romero L.
  2011-01-31 16:20 ` Stefan Monnier
  2 siblings, 0 replies; 7+ messages in thread
From: José A. Romero L. @ 2011-01-31  9:35 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 30, 12:17 pm, Andrea Crotti <andrea.crott...@gmail.com> wrote:
> I have some functions and variables which I only need in one particular
> directory.
>
> Now it would be nice that the first time that I visit a file in that
> subdirectory the file "elisp.el" gets evaluated.
>
> Using find-file-hook might be easy, but How can I make it evaluate only
> once?
(...)

Make your "elisp.el" (provide 'the-stuff-as-an-elisp-feature), then
in find-file-hook if you find you're about to visit a file in that
directory (require 'the-stuff-as-an-elisp-feature).

The (require) mechanism will take care of loading your code only
once.

Cheers,
--
José A. Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)



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

* Re: Eval elisp file automatically
       [not found] <mailman.4.1296386344.21090.help-gnu-emacs@gnu.org>
  2011-01-30 11:42 ` Eval elisp file automatically Tim X
  2011-01-31  9:35 ` José A. Romero L.
@ 2011-01-31 16:20 ` Stefan Monnier
  2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2011-01-31 16:20 UTC (permalink / raw)
  To: help-gnu-emacs

> I have some functions and variables which I only need in one particular
> directory.

We have .dir-locals.el for that.  Not sure if it'll be sufficient, since
you don't give much details.

> Another cool thing would be to reset to the defaut value the variables
> when I'm not, but it's not really necessary...

I have no idea what you mean by "when I'm not": Emacs has many buffers
(and windows) so you may have some buffers visiting files in that
directory and others visiting files in other directories.  In that case
would you want your functions to be loaded?

Also you talk about restting variables, which implies you're talking not
about new variables but about changing the value of existing variables,
in which case you probably don't ant to set them globally (which would
affect all buffers, including the ones that are visiting files in
other directories), but instead you want to set them buffer-locally,
i.e. have different values in the buffers that visit this directory than
in other buffers (which is what would happen with .dir-locals.el, for
example).


        Stefan


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

* Re: Eval elisp file automatically
  2011-01-30 11:42 ` Eval elisp file automatically Tim X
@ 2011-02-08 14:54   ` Andrea Crotti
  2011-02-08 15:38     ` Andrea Crotti
  0 siblings, 1 reply; 7+ messages in thread
From: Andrea Crotti @ 2011-02-08 14:54 UTC (permalink / raw)
  To: help-gnu-emacs

Tim X <timx@nospam.dev.null> writes:
>
> Emacs does support .dir-locals, which provides functionality similar to
> file variables, but at the directory level. See the section on
> Per-Directory local variables in the manual. However, your request seems
> slightly misguided to me. I'm not trying to be rude, but do wonder what
> you feel this will achieve or what problem will it address?
>
> My suspicion is there is a either a better solution or you are concerned
> about a non-problem for elisp or I'm just not understanding what you are
> trying to do. 
>
> The standard ways to address the function issue is to use autoloads or
> provide/require, which you either put in a file or possibly a load hook
> so that the functions are only loaded when you load some other mode etc. 
>
> Your reference to restoring default values sounds like you may be
> talking about buffer local variables, but I'm not sure. These variables
> are like other variables, except when you modify them, thos
> modifications are local to the buffer in which it occured. IN this way,
> the variables sort of have a default 'global' value and a local value.
> Any reference made to the variable outside the buffer that has set it as
> a local variable will see the global (default) value. Once you set that
> variable to a new value, that new value will be seen by code running in
> that buffer, but other buffers (who have not set their own local copy)
> will see the global value.
>
> Normally, you just don't bother undefining functions or variables. The
> effort it takes is not worth the resources saved. 
>
>
> Tim

After some time I came back and saw how dir local variables work,
verynice.

So I have this
((nil . 
      ((compile-command . "cd $PAD_DIR && make -j")))
 (c++-mode . (( flymake-mode . t))))

BUT flymake doens't really get activated even if the variable is set to
t.
Isn't there a way to run elisp code somehow, or to modify a hook?

About what I originally asked, well the idea was just that I don't want
to define some functions in case I'm not working on a project.

Now I just load the file with the functions defined and I'm fine.
To make it more neat it would be good to load the file ONLY the first
time that I visit a buffer in that directory, but that's not such a big
deal..




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

* Re: Eval elisp file automatically
  2011-02-08 14:54   ` Andrea Crotti
@ 2011-02-08 15:38     ` Andrea Crotti
  2011-02-08 17:54       ` Kevin Rodgers
  0 siblings, 1 reply; 7+ messages in thread
From: Andrea Crotti @ 2011-02-08 15:38 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
> After some time I came back and saw how dir local variables work,
> verynice.
>
> So I have this
> ((nil . 
>       ((compile-command . "cd $PAD_DIR && make -j")))
>  (c++-mode . (( flymake-mode . t))))
>
> BUT flymake doens't really get activated even if the variable is set to
> t.
> Isn't there a way to run elisp code somehow, or to modify a hook?
>
> About what I originally asked, well the idea was just that I don't want
> to define some functions in case I'm not working on a project.
>
> Now I just load the file with the functions defined and I'm fine.
> To make it more neat it would be good to load the file ONLY the first
> time that I visit a buffer in that directory, but that's not such a big
> deal..

I think I got it, I have to set "eval" as a variable.
I found out by chance using the interactive system to add variables, but
didn't see it documented anywhere.. is that possible?




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

* Re: Eval elisp file automatically
  2011-02-08 15:38     ` Andrea Crotti
@ 2011-02-08 17:54       ` Kevin Rodgers
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2011-02-08 17:54 UTC (permalink / raw)
  To: help-gnu-emacs

On 2/8/11 8:38 AM, Andrea Crotti wrote:
> I think I got it, I have to set "eval" as a variable.
> I found out by chance using the interactive system to add variables, but
> didn't see it documented anywhere.. is that possible?

Under "Specifying File Variables" in the Emacs manual:

    Some "variable names" have special meanings in a local variables
list:

    * `mode' enables the specified major or minor mode.

    * `eval' evaluates the specified Lisp expression (the value returned
      by that expression is ignored).

    * `coding' specifies the coding system for character code conversion
      of this file.  *Note Coding Systems::.

    * `unibyte' says to visit the file in a unibyte buffer, if the value
      is `t'.  *Note Enabling Multibyte::.

These four "variables" are not really variables; setting them in any
other context has no special meaning.

-- 
Kevin Rodgers
Denver, Colorado, USA




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

end of thread, other threads:[~2011-02-08 17:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.4.1296386344.21090.help-gnu-emacs@gnu.org>
2011-01-30 11:42 ` Eval elisp file automatically Tim X
2011-02-08 14:54   ` Andrea Crotti
2011-02-08 15:38     ` Andrea Crotti
2011-02-08 17:54       ` Kevin Rodgers
2011-01-31  9:35 ` José A. Romero L.
2011-01-31 16:20 ` Stefan Monnier
2011-01-30 11:17 Andrea Crotti

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