From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Fabrice Niessen" Newsgroups: gmane.emacs.help Subject: Re: require a package only if present Date: Mon, 13 Jul 2009 11:12:55 +0200 Organization: My Googlest Message-ID: <87vdlxeyjs.fsf@mundaneum.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1247496413 20545 80.91.229.12 (13 Jul 2009 14:46:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 13 Jul 2009 14:46:53 +0000 (UTC) To: help-gnu-emacs-mXXj517/zsQ@public.gmane.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org-mXXj517/zsQ@public.gmane.org Mon Jul 13 16:46:45 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 1MQMnd-0003SU-Vn for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Jul 2009 16:46:38 +0200 Original-Received: from localhost ([127.0.0.1]:33276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MQMnd-0003EG-Ah for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Jul 2009 10:46:37 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news-2.dfn.de!news.dfn.de!feeder.erje.net!feeder.eternal-september.org!eternal-september.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 62 Original-X-Trace: news.eternal-september.org U2FsdGVkX19cP9ug58zLwz6+8jWO6ieJjwrZAp2oxwqRCX++q+HBss+EqJRTg7LoNuRnUoUDXECI1yQ9u8qXbX9lqv7KXClVf+yz/5yVwiO4hw6TNT6jFKIR/UcCtuxZjMlcGj/fDlrt4RtGBR0XgQ== Original-X-Complaints-To: abuse-VVbKFVtnif8H+i2N2EyTrmui9UKz+5OX@public.gmane.org Original-NNTP-Posting-Date: Mon, 13 Jul 2009 09:18:17 +0000 (UTC) X-Auth-Sender: U2FsdGVkX19xolDlEVS49rrvrFcmGhE3rH+87Y6B4xo= X-Archive: encrypt Face: iVBORw0KGgoAAAANSUhEUgAAACgAAAAoBAMAAAB+0KVeAAAAElBMVEUAAAAAAP+LRRP0pGC+vr7///+7mT1iAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9cBBwMODhglKe4AAAEsSURBVCjPbZNBboQwDEV/Cd4X9QJRThApmn0XYW+Jyf2v0m+HhqDBgiAe9rcTG7QHw/1Vn2Ar8gBb/ocywSN3qK9T3z4eFDB4eApocBpeBs1RSykoJd8gQcm8pGmHXFso3ajnmsqV0TnYDQkOfXUfN5NwaI7AWTVOyEhcu1aHmdWItHddUVUcUgUBCkitu8V6ditHVOVdqzl2EQ1ZVGTbdK0V7cqn8vWzoU5Q/bF9Y/Y0cRU1xwkys5dJ+Dt6pBDWifcNQml8Gh2JVmPSoQzo7en0grswkxrUGYJ70hSxxAGr7ZMwYcHIzprpi7TENEE1xtiYxixRlCfPBsUUrwHD7uGIwATrbnODJcVrPpVn3hxiGloem/S+z3CtuzUSMo83N4DPH+F0evwR3P4A2k+75838OKQAAAAASUVORK5CYII= X-Www-site: http://www.MyGooglest.com/fni Cancel-Lock: sha1:NqodjtJsjIzexrMhtmSWNwlpDhA= sha1:jv8ETN1qqEXm+VhIpT5kZLCg9sQ= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:170815 X-Mailman-Approved-At: Mon, 13 Jul 2009 10:46:16 -0400 X-BeenThere: help-gnu-emacs-mXXj517/zsQ@public.gmane.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-mXXj517/zsQ@public.gmane.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org-mXXj517/zsQ@public.gmane.org Xref: news.gmane.org gmane.emacs.help:66027 Archived-At: Hello, Will Parsons wrote: > Edward O'Connor wrote: >>> I am trying to use the same copy of .emacs across various machines. Some, >>> however, don't have certain packages. So I need to replace lines like: >>> >>> (require 'tex-site) >>> >>> with code that checks whether tex-site is present and only loads it if >>> there. How can I do that? Any pointers welcome. >> >> (require 'tex-site nil t) > > I don't believe that works for XEmacs (which may be irrelevant for the OP), > so I use instead: > > (when (locate-library "lib-name") > (require 'lib-name)) I'm using the following code, both compatible with GNU Emacs and XEmacs: --8<---------------cut here---------------start------------->8--- (defvar missing-packages-list nil "List of packages that `try-require' can't find.") ;; attempt to load a feature/library, failing silently (defun try-require (feature) "Attempt to load a library or module. Return true if the library given as argument is successfully loaded. If not, instead of an error, just add the package to a list of missing packages." (condition-case err ;; protected form (progn (message "Checking for library `%s'..." feature) (if (stringp feature) (load-library feature) (require feature)) (message "Checking for library `%s'... Found" feature)) ;; error handler (file-error ; condition (progn (message "Checking for library `%s'... Missing" feature) (add-to-list 'missing-packages-list feature)) nil))) --8<---------------cut here---------------end--------------->8--- and, for every package I wanna load if present: --8<---------------cut here---------------start------------->8--- (try-require 'tex-site) --8<---------------cut here---------------end--------------->8--- (for example). See http://www.mygooglest.com/fni/dot-emacs.html for more examples. Fabrice _________________________________________________________________________ Fabrice Niessen Search the Web with "My Google Search Tools" on http://www.MyGooglest.com