From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: "Óscar Fuentes" <ofv@wanadoo.es>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Refer to the directory of the currently being loaded elisp script from within the Emacs lisp file itself.
Date: Fri, 11 Jun 2021 22:26:22 +0800 [thread overview]
Message-ID: <CAGP6POJ7BBR86mGFRMr8OMM7m1YGqO4Vn9juLLcmmwaquv9XBg@mail.gmail.com> (raw)
In-Reply-To: <87eed87bpy.fsf@telefonica.net>
On Fri, Jun 11, 2021 at 9:50 PM Óscar Fuentes <ofv@wanadoo.es> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > It really does the trick. Thank you for pointing this out. BTW, It should be:
> >
> > (setq my-directory (file-name-directory load-file-name))
> >
> > What about the following according to the tutorial at
> > <http://ergoemacs.org/emacs/elisp_relative_path.html>?:
> >
> > (setq my-directory (file-name-directory (or load-file-name buffer-file-name)))
>
> In general, that's incorrect. See the docsstring of buffer-file-name,
> where it is explained that the value of that variable depends on the
> current buffer, it is not related at all to the file that contains the
> Lisp code being executed.
>
Considering that the current execution method is loading the lisp code
for the script file, so it's not applicable to this scenario. But the
original explanation given by By Xah Lee [1] still seems reasonable:
To know the current file's full path, emacs has 2 ways:
`load-file-name' and `buffer-file-name'. If the file is loaded by
`load', then `load-file-name' works but `buffer-file-name' doesn't. If
the file is called by `eval-buffer', then `load-file-name' is nil. You
want to be able to get the current file's full path regardless the
file is run by `load' or interactively by `eval-buffer'."
[1] Refer <http://ergoemacs.org/emacs/elisp_relative_path.html> for
more detailed info.
Regards
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China
next prev parent reply other threads:[~2021-06-11 14:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-10 15:02 Refer to the directory of the currently being loaded elisp script from within the Emacs lisp file itself Hongyi Zhao
2021-06-10 15:24 ` Óscar Fuentes
2021-06-10 15:31 ` Hongyi Zhao
2021-06-10 15:40 ` Óscar Fuentes
2021-06-10 23:55 ` Hongyi Zhao
2021-06-11 1:14 ` Óscar Fuentes
2021-06-11 3:47 ` Hongyi Zhao
2021-06-11 13:49 ` Óscar Fuentes
2021-06-11 14:26 ` Hongyi Zhao [this message]
2021-06-10 15:31 ` Eli Zaretskii
2021-06-10 15:38 ` Hongyi Zhao
2021-06-10 15:42 ` Óscar Fuentes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGP6POJ7BBR86mGFRMr8OMM7m1YGqO4Vn9juLLcmmwaquv9XBg@mail.gmail.com \
--to=hongyi.zhao@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=ofv@wanadoo.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).