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

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

Re: lisp lexical-let related


From: Daniel Jensen
Subject: Re: lisp lexical-let related
Date: Sat, 19 May 2007 12:35:26 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.99 (gnu/linux)

poppyer <poppyer@gmail.com> writes:

> I try to re-bind TAB key to call (tab) or (m-tab), according to weather
> it stops at the end of a word. But the following lisp code not working
> as expected. Any idea?
>
> ==========
>   (lexical-let ((tab (key-binding (kbd "TAB")))
>                 (mtab (key-binding (kbd "M-TAB"))))
>     (local-set-key (kbd "TAB") (lambda()
>                                  (interactive)
>                                  (if (looking-at "\\>")
>                                      mtab
>                                    tab))))  ; [adjusted to save space]

The first bug is that tab and mtab are never called, they are simply
returned. You can use (command-execute tab) and (command-execute mtab).

Now, I need to apologize. The code that I wrote to you earlier
(swap-indent-bindings) wasn't tested, and it has a bug that I should've
noticed. Your code also suffers from this bug. To see what I'm talking
about, read the documentation for local-set-key, and note:

    The binding goes in the current buffer's local map, which in most
    cases is shared with all other buffers in the same major mode.

If you stuff the code in a major mode hook (that's what I assume you
want to do), the second time it's run the TAB binding is your own
function, not the original binding. You need to prevent it from
executing more than once. Maybe like this:

(unless (get major-mode 'tab-enhanced)
  (lexical-let ...)
  (put major-mode 'tab-enhanced t))


reply via email to

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