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 11:47:04 +0800 Message-ID: References: <871r99agku.fsf@telefonica.net> <87sg1p9198.fsf@telefonica.net> <87y2bh6w3h.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="30187"; 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 05:48:07 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 1lrY9P-0007gF-BT for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 11 Jun 2021 05:48:07 +0200 Original-Received: from localhost ([::1]:58234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lrY9N-0007Va-AJ for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Jun 2021 23:48:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lrY8c-0007VM-A4 for help-gnu-emacs@gnu.org; Thu, 10 Jun 2021 23:47:18 -0400 Original-Received: from mail-yb1-xb2d.google.com ([2607:f8b0:4864:20::b2d]:44965) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lrY8a-0001KT-FR for help-gnu-emacs@gnu.org; Thu, 10 Jun 2021 23:47:18 -0400 Original-Received: by mail-yb1-xb2d.google.com with SMTP id p184so2363349yba.11 for ; Thu, 10 Jun 2021 20:47:16 -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=lKPhXBK4KC++qzFcTBp+ZqV0e1jzzfuB1QpVz6fV7z4=; b=fkPcGQAgreajXjxdhAVNJ4OML/8m6aT2S95NeMaIPLqMt7cKh7kEGyyPvrpX6ylOeP B5ZVkhzPy9+5xOMonbCXEXhQfTiINcf9nC6KhTxZKbNKGgFJmrbwFTS8tKiC/GY8YwWR r2mZJvon7pUvDdwS3rGCvt3Eo5fXH+5JUcwn95Kh5SaJDXWil2uy010KRwlNdq/4orcb zLvJ00zBGVaDfuuJmFTM37hJvAX9BnO3tk5IhdRmVVxHpWGV54mWlcm9VcDDZFOnfk67 Lb3zprtYLFLJCQDn731tA0gaglDBcPEfmk/sC+kVwipPcspzEMMBROwDsnYrTQEoJT65 glnA== 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=lKPhXBK4KC++qzFcTBp+ZqV0e1jzzfuB1QpVz6fV7z4=; b=uobDKkLIyzVjj61SVYwFuWfPO4Y8TMeiXkQCt5Mly/1QnqDOsyWHFPrJOfkPuOU5XM kYPUUDI+HYNg2q/K3F1nySiXQX5LGNhP/sxbIhA6Fn+nkiUhnkYVa53YFXFT4k10nQTm nLy4oB+QAA+C2NsrI5rdzTqgBJdFRiHwywBpnimErdyud639ytTm03fGJnI+PVcd+k0T MGURVA4ZiorBxKyKOQaOMujJalsOCml3+mf1rvnvPEPFwZnAjEvpHsVMA+YME8ve7A4O Qi6G8/Tst5QHTm02YrSVSQL0VEQzReRq6gvUeEmRPT/ZuaLW0Eoj3gkxIt2pEC5TaJNJ pTlg== X-Gm-Message-State: AOAM530vpn09V+Sl7H+em7wWDYTfjiRgBxH2OEmBokcEFk2iZ4Ho8lOA eDojc7n0XVN1ePSPNtmk2vVBohPO1r9cp6kGO2I= X-Google-Smtp-Source: ABdhPJx6bYNu2YIwKzxNJATsfZ1cqvE4VdBNJZUtSemexrKSY5UV5If9Vxb9wsggcsRziDaHnNOremUcz9eJg9Ajuks= X-Received: by 2002:a05:6902:4d3:: with SMTP id v19mr2958528ybs.183.1623383235433; Thu, 10 Jun 2021 20:47:15 -0700 (PDT) In-Reply-To: <87y2bh6w3h.fsf@telefonica.net> Received-SPF: pass client-ip=2607:f8b0:4864:20::b2d; envelope-from=hongyi.zhao@gmail.com; helo=mail-yb1-xb2d.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:130748 Archived-At: On Fri, Jun 11, 2021 at 9:15 AM =C3=93scar Fuentes wrote: > > Hongyi Zhao writes: > > > On Thu, Jun 10, 2021 at 11:40 PM =C3=93scar Fuentes wr= ote: > >> > >> Hongyi Zhao writes: > >> > >> >> BTW, the correct method for concatenating a directory and a file na= me is > >> >> > >> >> (load-file > >> >> (concat > >> >> (file-name-as-directory (file-name-directory load-file-name)) > >> >> "auth.el.gpg")) > >> > > >> > I tried you above code, it still doesn't work with the following inf= o: > >> > > >> > file-name-as-directory: Wrong type argument: stringp, nil [2 times] > >> > Mark set > >> > >> load-file-name is defined while the file is being loaded, after that i= t > >> is nil. So if you tried with `C-x C-e' or some other interactive comma= nd > >> it wont work. > >> > >> Once the code above is in the correct file, save it, start Emacs and > >> report back what happens. > > > > See my current usage on > > > > according to the instructions here. > > > > After I start Emacs and tried with `M-x screenlatex RET', I will see > > the following info in *Messages* buffer: > > > > expand-file-name: Wrong type argument: stringp, nil > > As explained previously, load-file-name is only defined when the file is > being loaded, otherwise it is nil. > > You can put the directory name on a variable at load time and use that > variable on your command: > > (setq my-directory (file-name-directory load-file-name) It really does the trick. Thank you for pointing this out. BTW, It should b= e: (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= ))) > > (defun screen2latex () > ... > (load-file (expand-file-name "auth.el.gpg" my-directory)) > > 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