From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help 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 Message-ID: References: <871r99agku.fsf@telefonica.net> <87sg1p9198.fsf@telefonica.net> <87y2bh6w3h.fsf@telefonica.net> <87eed87bpy.fsf@telefonica.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11346"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: =?UTF-8?Q?=C3=93scar_Fuentes?= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 11 16:27:16 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lri7u-0002i7-Ul for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 11 Jun 2021 16:27:14 +0200 Original-Received: from localhost ([::1]:36954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lri7t-000230-Vx for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 11 Jun 2021 10:27:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lri7K-0001za-IT for help-gnu-emacs@gnu.org; Fri, 11 Jun 2021 10:26:38 -0400 Original-Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:35590) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lri7I-0000Uc-PC for help-gnu-emacs@gnu.org; Fri, 11 Jun 2021 10:26:38 -0400 Original-Received: by mail-lj1-x22d.google.com with SMTP id n17so9956453ljg.2 for ; Fri, 11 Jun 2021 07:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=KWG0Uq1v1qsIZqtsFAMfP6Nfqka4iBT6/fRRajhfTNA=; b=R6tlQ3eMjuMeEgVx5obFyQ3nYPe/rqGvJvtI3aZKMu2cmb7z0OTZ3j7iaHYZq+nSAc Dje2NzkHFVDqLP5l0On3NT2ov/5XhBUghUyNY/JaLz6Bu6Ukv9WgF730Vj+aoMS7Q3u1 i0cQVK4vIX0su80jCVoKifvhu0kK7C7Ge1aD6Uer6FQJNuNSuq2obm3KBglVbwyAhgot ktz42H8S9vnDZXr5vN+wuY5bMHnM2K4TC/2sllmETyd66GscLgZflILY0qGPAxa7B+p8 mDh/2hoIhtKmZ4umAKZxq56gT/NeXKSPnmrF9SYfRMfoXMFhiexXNHZJGmSGsYjNpU3F JNKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KWG0Uq1v1qsIZqtsFAMfP6Nfqka4iBT6/fRRajhfTNA=; b=uPDHxQzcSYXDkCjQN29nUuMZ69o3XDkqqsCaNbgP3T8ue+07DYrelJ8ruqAeC0911c SUN1Gw/dCKKp0TH7n/SJvKKnLxd03rL1onfwyHfog2dshAzXLmLtFsHujSS9+LACSJGG HoBSw86UGr5Qme/GaRBoKGNQdQHAZ3OBVTT8qCqYGux/7mgVDVFt1EIUqKdCWzAFRL2v hew2jEBzFmTk9FM/OFf6PSoxqA18xOq/APzRsouE5lOeDD3lQ743GAf+1BN55wReV6tY 6Tmrp8Cl6qKnSPditUPRkg+i/2n27U9zEPlQ9NpDnhuR6JjUFylAyx/O80BFljW7MjT9 LEQA== X-Gm-Message-State: AOAM5335Ob4cjTzyOGJQ7uFWXOU+F/8UDh/SbGP0cjh/B+sK1tdDunJr j1N2xorqrC05HQP2Lpos4S6TOCgp0ED8y7lcT1Q= X-Google-Smtp-Source: ABdhPJycJOvPpJbaImta4a9MHvc4upIeMEvBQl4r9eKH2XRv6xcFHB9iGjJSgYB9f5GWrPZ8QuFicvARlNXBW/bI2n8= X-Received: by 2002:a2e:b169:: with SMTP id a9mr3199552ljm.320.1623421594550; Fri, 11 Jun 2021 07:26:34 -0700 (PDT) In-Reply-To: <87eed87bpy.fsf@telefonica.net> Received-SPF: pass client-ip=2a00:1450:4864:20::22d; envelope-from=hongyi.zhao@gmail.com; helo=mail-lj1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:130758 Archived-At: On Fri, Jun 11, 2021 at 9:50 PM =C3=93scar Fuentes wrote: > > Hongyi Zhao writes: > > > It really does the trick. Thank you for pointing this out. BTW, It shou= ld be: > > > > (setq my-directory (file-name-directory load-file-name)) > > > > What about the following according to the tutorial at > > ?: > > > > (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 for more detailed info. Regards --=20 Assoc. Prof. Hongyi Zhao Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering NO. 552 North Gangtie Road, Xingtai, China