* how to reference the current *.el file in elisp
@ 2009-06-25 4:20 Harry Putnam
0 siblings, 0 replies; 14+ messages in thread
From: Harry Putnam @ 2009-06-25 4:20 UTC (permalink / raw)
To: help-gnu-emacs
How does elisp reference the current *.el file?... I mean like in the
way that the variable $0 carries the the value that is the full name
of the script its in.
What I'm really after is a say to to add that value to a message
('(message "hello")')
Like this message (wrapped for mail):
(message "hello world -- from
/cvsb/reader/home/reader/lisp/site-start.el")
(sit-for 1)
that I use sometimes when tracking down how things are loading.
How can I reference the name in a variable instead of writing it out?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
[not found] <mailman.1223.1245903674.2239.help-gnu-emacs@gnu.org>
@ 2009-06-25 5:49 ` Xah Lee
2009-06-25 7:23 ` Barry Margolin
1 sibling, 0 replies; 14+ messages in thread
From: Xah Lee @ 2009-06-25 5:49 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 24, 9:20 pm, Harry Putnam <rea...@newsguy.com> wrote:
> How does elisp reference the current *.el file?... I mean like in the
> way that the variable $0 carries the the value that is the full name
> of the script its in.
you can use this:
(or load-file-name buffer-file-name)
if you want the full path, call file-name-directory on the result.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
[not found] <mailman.1223.1245903674.2239.help-gnu-emacs@gnu.org>
2009-06-25 5:49 ` how to reference the current *.el file in elisp Xah Lee
@ 2009-06-25 7:23 ` Barry Margolin
2009-06-25 11:49 ` Harry Putnam
[not found] ` <mailman.1237.1245930608.2239.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 14+ messages in thread
From: Barry Margolin @ 2009-06-25 7:23 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.1223.1245903674.2239.help-gnu-emacs@gnu.org>,
Harry Putnam <reader@newsguy.com> wrote:
> How does elisp reference the current *.el file?... I mean like in the
> way that the variable $0 carries the the value that is the full name
> of the script its in.
> What I'm really after is a say to to add that value to a message
> ('(message "hello")')
>
> Like this message (wrapped for mail):
>
> (message "hello world -- from
> /cvsb/reader/home/reader/lisp/site-start.el")
> (sit-for 1)
>
> that I use sometimes when tracking down how things are loading.
>
> How can I reference the name in a variable instead of writing it out?
load-file-name
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-25 7:23 ` Barry Margolin
@ 2009-06-25 11:49 ` Harry Putnam
2009-06-25 12:30 ` Lennart Borgman
[not found] ` <mailman.1237.1245930608.2239.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 14+ messages in thread
From: Harry Putnam @ 2009-06-25 11:49 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin <barmar@alum.mit.edu> writes:
>> Like this message (wrapped for mail):
>>
>> (message "hello world -- from
>> /cvsb/reader/home/reader/lisp/site-start.el")
>> (sit-for 1)
>>
>> that I use sometimes when tracking down how things are loading.
>>
>> How can I reference the name in a variable instead of writing it out?
>
> load-file-name
I've tried everything but prayer... but not seeing how to reference
that in a message.
not:
(message "hello"(load-file-name))
not:
(message "hello" '(load-file-name))
not
(message "Hello" 'load-file-name)
not
(message "Hello" load-file-name)
A few others too ridiculous to print...
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
[not found] ` <mailman.1237.1245930608.2239.help-gnu-emacs@gnu.org>
@ 2009-06-25 12:18 ` Pascal J. Bourguignon
2009-06-26 2:24 ` Barry Margolin
1 sibling, 0 replies; 14+ messages in thread
From: Pascal J. Bourguignon @ 2009-06-25 12:18 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam <reader@newsguy.com> writes:
> I've tried everything but prayer... but not seeing how to reference
> that in a message.
>
> not
> (message "Hello" load-file-name)
>
> A few others too ridiculous to print...
What about reading the doc of message? C-h f message RET
\f
(message "Hello %S" load-file-name)
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-25 11:49 ` Harry Putnam
@ 2009-06-25 12:30 ` Lennart Borgman
2009-06-25 23:43 ` Harry Putnam
0 siblings, 1 reply; 14+ messages in thread
From: Lennart Borgman @ 2009-06-25 12:30 UTC (permalink / raw)
To: Harry Putnam; +Cc: help-gnu-emacs
On Thu, Jun 25, 2009 at 1:49 PM, Harry Putnam<reader@newsguy.com> wrote:
> Barry Margolin <barmar@alum.mit.edu> writes:
>
>>> Like this message (wrapped for mail):
>>>
>>> (message "hello world -- from
>>> /cvsb/reader/home/reader/lisp/site-start.el")
>>> (sit-for 1)
>>>
>>> that I use sometimes when tracking down how things are loading.
>>>
>>> How can I reference the name in a variable instead of writing it out?
>>
>> load-file-name
>
> I've tried everything but prayer... but not seeing how to reference
> that in a message.
Then maybe prayer is what you should try. After that you probably
realize that there are a lot of things you have not tried. (Is not
prayer for that?)
For example
C-h f message
Or did you try that?
> not:
> (message "hello"(load-file-name))
>
> not:
> (message "hello" '(load-file-name))
>
> not
> (message "Hello" 'load-file-name)
>
> not
> (message "Hello" load-file-name)
>
> A few others too ridiculous to print...
>
>
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-25 12:30 ` Lennart Borgman
@ 2009-06-25 23:43 ` Harry Putnam
0 siblings, 0 replies; 14+ messages in thread
From: Harry Putnam @ 2009-06-25 23:43 UTC (permalink / raw)
To: help-gnu-emacs
Lennart Borgman <lennart.borgman@gmail.com> writes:
[...]
> Then maybe prayer is what you should try. After that you probably
> realize that there are a lot of things you have not tried. (Is not
> prayer for that?)
>
> For example
>
> C-h f message
>
> Or did you try that?
Trying that... `C-h f message' (not prayer) is what brought me here.
The answer there just didn't soak in at all. Fortunately... I've
never claimed to be anything but seriously dense.
Once I saw that both you and Pascal, were saying that it answered my
question, I figured I had to be able to see it there.
And eventually I got it... Thanks... to all, starting with Barry.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
[not found] ` <mailman.1237.1245930608.2239.help-gnu-emacs@gnu.org>
2009-06-25 12:18 ` Pascal J. Bourguignon
@ 2009-06-26 2:24 ` Barry Margolin
2009-06-28 0:44 ` jidanni
1 sibling, 1 reply; 14+ messages in thread
From: Barry Margolin @ 2009-06-26 2:24 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.1237.1245930608.2239.help-gnu-emacs@gnu.org>,
Harry Putnam <reader@newsguy.com> wrote:
> Barry Margolin <barmar@alum.mit.edu> writes:
>
> >> Like this message (wrapped for mail):
> >>
> >> (message "hello world -- from
> >> /cvsb/reader/home/reader/lisp/site-start.el")
> >> (sit-for 1)
> >>
> >> that I use sometimes when tracking down how things are loading.
> >>
> >> How can I reference the name in a variable instead of writing it out?
> >
> > load-file-name
>
> I've tried everything but prayer... but not seeing how to reference
> that in a message.
>
> not:
> (message "hello"(load-file-name))
>
> not:
> (message "hello" '(load-file-name))
>
> not
> (message "Hello" 'load-file-name)
>
> not
> (message "Hello" load-file-name)
>
> A few others too ridiculous to print...
(message "Hello %s" load-file-name)
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-26 2:24 ` Barry Margolin
@ 2009-06-28 0:44 ` jidanni
2009-06-29 3:10 ` Barry Margolin
0 siblings, 1 reply; 14+ messages in thread
From: jidanni @ 2009-06-28 0:44 UTC (permalink / raw)
To: help-gnu-emacs
BM> (message "Hello %s" load-file-name)
How do I do things like
# Local Variables:
# mode: Shell-script
# compile-command: (concat "sh " buffer-file-name)
# End:
without being asked about risky variables, or hard wiring buffer-file-name?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-28 0:44 ` jidanni
@ 2009-06-29 3:10 ` Barry Margolin
2009-06-30 1:29 ` jidanni
0 siblings, 1 reply; 14+ messages in thread
From: Barry Margolin @ 2009-06-29 3:10 UTC (permalink / raw)
To: help-gnu-emacs
In article <878wjd1926.fsf@jidanni.org>, jidanni@jidanni.org wrote:
> BM> (message "Hello %s" load-file-name)
> How do I do things like
> # Local Variables:
> # mode: Shell-script
> # compile-command: (concat "sh " buffer-file-name)
> # End:
> without being asked about risky variables, or hard wiring buffer-file-name?
Why don't you just create a shell-script-mode hook that sets
compile-command? This seems like a mode-specific setting, not a
file-specific setting.
But if you want to customize risky local variables, see the
safe-local-variables-p function.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-29 3:10 ` Barry Margolin
@ 2009-06-30 1:29 ` jidanni
2009-06-30 3:30 ` Barry Margolin
0 siblings, 1 reply; 14+ messages in thread
From: jidanni @ 2009-06-30 1:29 UTC (permalink / raw)
To: help-gnu-emacs
> How do I do things like
> # Local Variables:
> # compile-command: (concat "blarfowitz --nizbotize" buffer-file-name)
> # End:
> without being asked about risky variables, or hard wiring buffer-file-name?
BM> if you want to customize risky local variables, see the
BM> safe-local-variables-p function.
OK, I read that, and (info "(emacs) Safe File Variables")
but I still don't get why buffer-file-name is so unsafe... OK, maybe one
can set it to /etc/passwd and cause one to zap that file... Anyway, in
perl or sh there is the handy
$PROGRAM_NAME
$0 Contains the name of the program being executed.
So why in "Local Variables" stanzas is there no way to refer to the
current file being edited, without setting off all kinds of fire alarms,
or being forced to whitelist something because it is dangerous, thus
exposing myself to danger elsewhere. See also
http://groups.google.com/groups/search?as_umsgid=mailman.597.1244940108.2239.help-gnu-emacs@gnu.org
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
2009-06-30 1:29 ` jidanni
@ 2009-06-30 3:30 ` Barry Margolin
0 siblings, 0 replies; 14+ messages in thread
From: Barry Margolin @ 2009-06-30 3:30 UTC (permalink / raw)
To: help-gnu-emacs
In article <87eit2zeyg.fsf@jidanni.org>, jidanni@jidanni.org wrote:
> > How do I do things like
> > # Local Variables:
> > # compile-command: (concat "blarfowitz --nizbotize" buffer-file-name)
> > # End:
> > without being asked about risky variables, or hard wiring buffer-file-name?
>
> BM> if you want to customize risky local variables, see the
> BM> safe-local-variables-p function.
>
> OK, I read that, and (info "(emacs) Safe File Variables")
> but I still don't get why buffer-file-name is so unsafe... OK, maybe one
The warning isn't about buffer-file-name, it's about compile-command.
It warns if you try to set it to something other than a string. In your
case, you're trying to set it to a list.
> can set it to /etc/passwd and cause one to zap that file... Anyway, in
> perl or sh there is the handy
> $PROGRAM_NAME
> $0 Contains the name of the program being executed.
> So why in "Local Variables" stanzas is there no way to refer to the
> current file being edited, without setting off all kinds of fire alarms,
> or being forced to whitelist something because it is dangerous, thus
> exposing myself to danger elsewhere. See also
> http://groups.google.com/groups/search?as_umsgid=mailman.597.1244940108.2239.h
> elp-gnu-emacs@gnu.org
Values in the local variables stanza aren't evaluated, they're treated
as literals. So there's no referring possible.
This is why hooks are usually more appropriate for complex things like
this. If you really do need a special compile-command just for one
specific file, you'll have to hard-code the file's name into it, e.g.
# compile-command: blarfowitz --nizbotize myscript.sh
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
@ 2009-07-02 12:48 jidanni
0 siblings, 0 replies; 14+ messages in thread
From: jidanni @ 2009-07-02 12:48 UTC (permalink / raw)
To: help-gnu-emacs
># compile-command: (concat "blarfowitz --nizbotize " buffer-file-name)
> without being asked about risky variables, or hard wiring buffer-file-name?
<The warning isn't about buffer-file-name, it's about compile-command.
<It warns if you try to set it to something other than a string. In your
<case, you're trying to set it to a list.
All I know is: concat is a built-in function in `C source code'.
Concatenate all the arguments and make the result a string.
<Values in the local variables stanza aren't evaluated, they're treated
<as literals. So there's no referring possible.
Is too. buffer-file-name does get evaluated. But it causes a y-or-n-p.
<This is why hooks are usually more appropriate for complex things like
<this. If you really do need a special compile-command just for one
<specific file, you'll have to hard-code the file's name into it, e.g.
<# compile-command: blarfowitz --nizbotize myscript.sh
No, I want to make a template, e.g.,
# Local Variables:
# compile-command: "php --syntax-check LocalSettings.php"
# End:
for some, but not all (hence hook no good) php files, without having to
hardwire the filename.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: how to reference the current *.el file in elisp
[not found] <mailman.1712.1246572015.2239.help-gnu-emacs@gnu.org>
@ 2009-07-08 9:30 ` Anselm Helbig
0 siblings, 0 replies; 14+ messages in thread
From: Anselm Helbig @ 2009-07-08 9:30 UTC (permalink / raw)
To: help-gnu-emacs
> No, I want to make a template, e.g.,
> # Local Variables:
> # compile-command: "php --syntax-check LocalSettings.php"
> # End:
> for some, but not all (hence hook no good) php files, without having to
> hardwire the filename.
Do you know about flymake?
http://www.blik.it/2007/02/21/syntax-checking-for-php-in-emacs/
Regards,
Anselm
--
Anselm Helbig
mailto:anselm.helbig+news2009@googlemail.com
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2009-07-08 9:30 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1223.1245903674.2239.help-gnu-emacs@gnu.org>
2009-06-25 5:49 ` how to reference the current *.el file in elisp Xah Lee
2009-06-25 7:23 ` Barry Margolin
2009-06-25 11:49 ` Harry Putnam
2009-06-25 12:30 ` Lennart Borgman
2009-06-25 23:43 ` Harry Putnam
[not found] ` <mailman.1237.1245930608.2239.help-gnu-emacs@gnu.org>
2009-06-25 12:18 ` Pascal J. Bourguignon
2009-06-26 2:24 ` Barry Margolin
2009-06-28 0:44 ` jidanni
2009-06-29 3:10 ` Barry Margolin
2009-06-30 1:29 ` jidanni
2009-06-30 3:30 ` Barry Margolin
[not found] <mailman.1712.1246572015.2239.help-gnu-emacs@gnu.org>
2009-07-08 9:30 ` Anselm Helbig
2009-07-02 12:48 jidanni
-- strict thread matches above, loose matches on Subject: below --
2009-06-25 4:20 Harry Putnam
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).