From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Loading a file vs evaluating its buffer Date: Mon, 06 Oct 2014 10:15:36 +0200 Organization: Informatimago Message-ID: <87bnpplil3.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1412583625 25909 80.91.229.3 (6 Oct 2014 08:20:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Oct 2014 08:20:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 06 10:20:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xb3Wk-0002DP-Qo for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Oct 2014 10:20:18 +0200 Original-Received: from localhost ([::1]:50688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xb3Wk-0003Wf-4v for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Oct 2014 04:20:18 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-X-Trace: individual.net mcwRi9Xt5WoGHN8znLU/DA0hnXiRJLQy7V/2bkUJtIthB96Zke Cancel-Lock: sha1:YzU2YjcxZTY4MmNhMzUyMTNhY2I1NDlhMWM2NjNlMmM5MjY1OGU2MQ== sha1:kRrr6UHCH64+AYAENIar9QWbvUk= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:208025 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:100301 Archived-At: Thorsten Jolitz writes: > Hi List, > > when I try to store the installation directory of an app while loading > its init file "A.el" with this code > > #+BEGIN_SRC emacs-lisp > (defvar my-installation-directory "" > "My installation directory.") > > (setq my-installation-directory > (file-name-directory > (directory-file-name > (file-name-directory > (buffer-file-name))))) > #+END_SRC > > I get > > ,---- > | Load error for /home/tj/junk/el/A.el: > | (wrong-type-argument stringp nil) > `---- > > but doing M-x eval-buffer in buffer "A.el" works as expected: > > ,----[ C-h v my-installation-directory RET ] > | my-installation-directory is a variable defined in `A.el'. > | Its value is "/home/tj/junk/" > | > | Documentation: > | My installation directory. > `---- > > How can I get the same result when loading the file? (defvar my-installation-directory "" "My installation directory.") (eval-when (load eval) ;; This sets my-installation-directory to the directory containing ;; the directory containing this file. (setq my-installation-directory (file-name-directory (directory-file-name (file-name-directory (or load-file-name (buffer-file-name))))))) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk