From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sebastian Tennant Newsgroups: gmane.emacs.help Subject: Re: Evaluation of hooks Date: Mon, 26 Dec 2005 22:07:16 +0000 Message-ID: <87slsf4inf.fsf@smolny.plus.com> References: <87zmmoreyj.fsf@smolny.plus.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1135634878 15813 80.91.229.2 (26 Dec 2005 22:07:58 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 26 Dec 2005 22:07:58 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 26 23:07:57 2005 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Er0VZ-0003SQ-08 for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Dec 2005 23:07:57 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Er0Wm-0004Cq-Nh for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Dec 2005 17:09:12 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Er0WV-0004Cg-7D for help-gnu-emacs@gnu.org; Mon, 26 Dec 2005 17:08:55 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Er0WT-0004CS-Im for help-gnu-emacs@gnu.org; Mon, 26 Dec 2005 17:08:54 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Er0WT-0004CP-Dv for help-gnu-emacs@gnu.org; Mon, 26 Dec 2005 17:08:53 -0500 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtp (TLS-1.0:RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1Er0WM-0007EE-AA for help-gnu-emacs@gnu.org; Mon, 26 Dec 2005 17:08:46 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Er0V4-0003JA-Sz for help-gnu-emacs@gnu.org; Mon, 26 Dec 2005 23:07:27 +0100 Original-Received: from 82.155.147.48 ([82.155.147.48]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 26 Dec 2005 23:07:26 +0100 Original-Received: from sebyte by 82.155.147.48 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 26 Dec 2005 23:07:26 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 55 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 82.155.147.48 User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:KvNg6vp4DmCXxDA3YHActqU7IJM= 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:32241 Archived-At: Sebastian Tennant wrote: > Tom Breton wrote: > >> Sebastian Tennant wrote: >> >>> Hi all, >>> >>> I would like to add a function to my emacs-lisp-mode-hook so that whenever >>> I visit emacs source files, view-mode minor mode is enabled. >>> >>> (add-hook 'emacs-lisp-mode-hook >>> (lambda () >>> (when (>= (compare-strings >>> (buffer-file-name) 1 nil "/usr/share/emacs/" 1 nil) 17) >>> (view-mode-enable)))) >>> >>> With the above code in my ~/.emacs, I get the following message at startup: >>> >>> >=: Wrong type argument: stringp, nil >> >> I doubt that has anything to do with hooks. > > It's odd though, don't you think? I'm wondering if I should fie a bug report. > >>> but apart from this the startup process is unaffected, and the function is >>> successfully added to my emacs-lisp-mode-hook, as you can see: >>> >>> ((lambda nil >>> (when >>> (> >>> (compare-strings >>> (buffer-file-name) >>> 0 nil "/usr/share/emacs/" 0 nil) >>> 18) >>> (view-mode-enable)))) >> >> Nope, that doesn't work either ... sometimes. > > I've got it working (despite the aforementioned error at startup). The problem > was that (view-mode-enable) is only defined as a function *after* view-mode is > loaded. The fix was to replace this with (view-mode 1). And I've now realised why I'm getting the error at startup. As we all know, a *scratch* buffer is created by default at startup and is by definition not visitng a file. This is what was causing the problem. Adding the following line before the (when ...) condition fixes this and the hook is now functioning perfectly. (unless (not (buffer-file-name)) ...) sdt