help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading a file vs evaluating its buffer


From: Pascal J. Bourguignon
Subject: Re: Loading a file vs evaluating its buffer
Date: Mon, 06 Oct 2014 10:15:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Thorsten Jolitz <tjolitz@gmail.com> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]