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

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

Re: Elisp - Store path only once


From: Omar Polo
Subject: Re: Elisp - Store path only once
Date: Sat, 09 Jan 2021 12:53:11 +0100
User-agent: K-9 Mail for Android

On 9 January 2021 12:30:57 CET, wael-zwaiter@gmx.com wrote:
>Am unsure whether I can  require on the elisp files I have written.
>
>(require 'g-eshell)
>(require 'g-utils)
>
>Aw getting confused, as I was simply doing
>
>(setq g-eshell
>   "/home/bard/Genadm/build/gadin-1.0/elisp/g-eshell.el")
>
>(setq g-utils
>   "/home/bard/Genadm/build/gadin-1.0/elisp/g-utils.el")
>
>(load 'g-eshell)
>(load 'g-utils)
>
>> Sent: Saturday, January 09, 2021 at 10:54 PM
>> From: "Omar Polo" <op@omarpolo.com>
>> To: wael-zwaiter@gmx.com
>> Cc: help-gnu-emacs@gnu.org
>> Subject: Re: Elisp - Store path only once
>>
>>
>> wael-zwaiter@gmx.com writes:
>>
>> > I have a lot of customisation files for emacs stored in the
>> > directory /home/bard/Genadm/build/gadin-1.0/elisp/.
>> >
>> > Would like to store the path so that I can define it only once.
>> > How can I do this in Emacs Lisp.
>> >
>> >
>> >   (setq g-eshell
>> >      "/home/bard/Genadm/build/gadin-1.0/elisp/g-eshell.el")
>> >
>> >   (setq g-utils
>> >      "/home/bard/Genadm/build/gadin-1.0/elisp/g-utils.el")
>>
>> Couldn't you just
>>
>>     (add-to-list 'load-path
>"/home/bard/Genadm/build/gadin-1.0/elisp")
>>
>> and then
>>
>>     (require 'g-eshell)
>>     (require 'g-utils)
>>
>> when needed?
>>
>>

you should definitely check the manual for more detailed information, but the 
gist of it is that when you

(require 'something)

emacs will search for something.el in all the directories listed in load-path.  
This is like the UNIX $PATH variable if you're familiar, only for elisp files 
instead.

Now, you can require any file, given that they contains a provide at the 
bottom.  i.e. your g-eshell.el should ends with

(provide 'g-shell)

this way you can avoid typing the full path every time, and is also easier to 
move those files without braking you configuration.

(Also, require is better than load because it won't evaluate the same file two 
times)
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.



reply via email to

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