From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: elisp: isn't default-directory always the dir of current file?? Date: Mon, 2 Mar 2009 12:32:58 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <19d2e227-6275-4b23-90f3-98c914a95156@o8g2000pre.googlegroups.com> <015bc5de-e438-4f92-b647-717776e51dc7@e1g2000pra.googlegroups.com> <070cfb3c-7d5c-444f-91fa-2948024b1ef7@n33g2000pri.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1236030380 11453 80.91.229.12 (2 Mar 2009 21:46:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Mar 2009 21:46:20 +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 Mar 02 22:47:37 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LeFyn-00026V-NB for geh-help-gnu-emacs@m.gmane.org; Mon, 02 Mar 2009 22:47:18 +0100 Original-Received: from localhost ([127.0.0.1]:48335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LeFxS-0000cL-Gi for geh-help-gnu-emacs@m.gmane.org; Mon, 02 Mar 2009 16:45:54 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!p6g2000pre.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 119 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1236025978 906 127.0.0.1 (2 Mar 2009 20:32:58 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 2 Mar 2009 20:32:58 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p6g2000pre.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167230 comp.emacs:97902 X-Mailman-Approved-At: Mon, 02 Mar 2009 16:45:06 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62530 Archived-At: On Mar 2, 2:32 am, Lennart Borgman wrote: > On Mon, Mar 2, 2009 at 8:46 AM,XahLee wrote: > >> but that didn't. The following works though: > >> (add-to-list 'load-path (file-name-directory load-file-name)) > > > Ugh, this is quite painful. Spend 2+ hours on this. > > > If i use this: > > (add-to-list 'load-path (file-name-directory load-file-name)) > > > it works if the file is loaded by elisp. But doesn't work if the file > > is run with eval-buffer. > > Use buffer-file-name if load-file-name is nil. Thanks. --------------- For completeness or whoever may be reading this later, here's the code to put the dir into load path: (add-to-list 'load-path (file-name-directory (if load-file-name load-file-name buffer-file- name))) This is useful, because suppose you have a elisp library of many files in a dir named xyz. And in that dir there's one file that init them all, named =E2=80=9Cinit.el=E2=80=9D. In your install instruction, you can tell user to open init.el and eval-buffer and everything is installed. And if user wants it automatically loaded when emacs starts, just put a single line such as: (load-file "/Users/xah/web/emacs/emacs2/init.el") in =E2=80=9C.emacs=E2=80=9D. The advantage of this is that: =E2=80=A2 user can just put a single load-file line to init your library. T= hey don't need to put extra line to add path to load-path. =E2=80=A2 user can install your library in a very simple way of opening the file and M-x eval-buffer. (which is simple and especially when user want to see what your lib do first). ... there are probably other easy alternatives for installation approach... For example, 2 installation instruction from existing package i find very good are: ; from nxml (load-file "~/Documents/emacs/nxml-mode-20041004/rng-auto.el") ; from js2 (autoload 'js2-mode "js2" nil t) Very excellent! Often, emacs packages does not have good install instruction. Some, simply say =E2=80=9Cput dir in your load path=E2=80=9D, assuming that the u= ser knows about elisp. Many users have no idea about load path or the concept particular to elisp. some rambling thoughts about emacs library system below. ---------------------------------- Also, emacs itself doesn't have a simple, mechanical, uniform installation system. It would be nice if it does. Something enforced by elisp... so that all packages are forced to have one single installation method, such as say =E2=80=9C(install filename)=E2=80=9D. ... elisp's concept of module, lib, package etc are also sucky. Here's something i wrote in my tutorial: What's Library, Package, Feature? Here's a bit technical detail about some elisp issues related to library. Knowing it helps you a bit. Emacs lisp the language does not have name spaces. Everything is global. Also, emacs has a concept of =E2=80=9Cpackage=E2=80=9D, =E2=80=9Cli= brary=E2=80=9D, but these terms are used losely in the documentation. They do not have technical meaning in emacs lisp. Emacs also has a concepts of =E2=80=9Cfeature=E2=80= =9D. A =E2=80=9Cfeature=E2=80=9D does have technical meaning in elisp. It is basic= ally a elisp symbol, that can be added to the list variable =E2=80=9Cfeatures=E2= =80=9D. The sole purpose is for emacs to know which =E2=80=9Cfeature=E2=80=9D has been = loaded already. A emacs =E2=80=9Cfeature=E2=80=9D has no relation to the file name= the lisp symbol is in. In general, the terms used by emacs: =E2=80=9Cpackage=E2=80=9D, =E2=80=9Cli= brary=E2=80=9D, =E2=80=9Cfeature=E2=80=9D, are all fuzzily defined and confusing, and none enforces a relation to a file's name. This means, you could have a file named =E2=80=9Cxyz.el=E2= =80=9D, which provides a feature named =E2=80=9Cabc=E2=80=9D, while it really just provid= e a mode to user with the command name =E2=80=9Copq-mode=E2=80=9D, and =E2=80=9Copq-mod= e=E2=80=9D might have display name =E2=80=9Copq=E2=80=9D or =E2=80=9COPQ=E2=80=9D, =E2=80=9COPQ m= ode=E2=80=9D, or =E2=80=9Cyoyo=E2=80=9D. And, this file can be considered as a package as well as library Xah =E2=88=91 http://xahlee.org/ =E2=98=84