From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Hansen Newsgroups: gmane.emacs.help Subject: Re: How to use elisp's closure Date: Mon, 16 Jun 2008 17:42:02 +0200 Organization: disorganized Message-ID: <87wskp9yk5.fsf@localhorst.mine.nu> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1213631639 19397 80.91.229.12 (16 Jun 2008 15:53:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Jun 2008 15:53:59 +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 Jun 16 17:54:43 2008 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 1K8H2W-0001XL-ED for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Jun 2008 17:54:40 +0200 Original-Received: from localhost ([127.0.0.1]:59029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K8H1i-0002RG-7L for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Jun 2008 11:53:50 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K8H1M-0002QX-Ey for help-gnu-emacs@gnu.org; Mon, 16 Jun 2008 11:53:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K8H1K-0002Ng-V0 for help-gnu-emacs@gnu.org; Mon, 16 Jun 2008 11:53:27 -0400 Original-Received: from [199.232.76.173] (port=60794 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K8H1K-0002NO-KR for help-gnu-emacs@gnu.org; Mon, 16 Jun 2008 11:53:26 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:43173 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K8H1K-0004pd-3L for help-gnu-emacs@gnu.org; Mon, 16 Jun 2008 11:53:26 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1K8H1D-00037l-Pr for help-gnu-emacs@gnu.org; Mon, 16 Jun 2008 15:53:19 +0000 Original-Received: from e178007226.adsl.alicedsl.de ([85.178.7.226]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 16 Jun 2008 15:53:19 +0000 Original-Received: from david.hansen by e178007226.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 16 Jun 2008 15:53:19 +0000 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 54 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: e178007226.adsl.alicedsl.de Mail-Copies-To: nobody User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:u+xdXle834Guj/7C0QGskvILkz4= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:54896 Archived-At: On Mon, 16 Jun 2008 22:15:21 +0800 netawater wrote: > In most usual modes, TAB key is bound to an indent function and > M-TAB key is bound to a complete symbol function. > I want to write a function if cursor is at the end of word then > try to complete symbol, else indent. It is my function. > > (defun my-indent-or-complete (M-TAB-func TAB-func) > ;; "If cursor is at the end of word then current mode;s M-TAB > function, else TAB" > (lambda () > (interactive) > (if (looking-at "\\>") > (apply M-TAB-func '()) > (apply TAB-func '()) > )) > ) > > Then I try to bound it to \t key: > > (add-hook > 'find-file-hook > '(lambda () > (let ((M-TAB-func (key-binding "\M-\t")) > (TAB-func (key-binding "\t")) > ) > (local-set-key > "\t" > (my-indent-or-complete M-TAB-func TAB-func))) > ) > ) > > However it does not work, it says Symbol's value as variable > is void: TAB-func. I think it is because my function is not > a closure, but how can I resolve it? > Elisp is a pretty old lisp dialect... There are no closures. The `lexical-let' macro from the `cl' package emulates them. But in your case just make `M-TAB-fun' and `TAB-fun' buffer local: (defvar foo-var default-val) (make-variable-buffer-local 'foo-var) or (defvar foo-var default-val) (add-hook 'my-mode-hook #'(lambda () (set (make-local-variable 'foo-var) val) ;; ... )) David