all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* lisp lexical-let related
@ 2007-05-19  4:06 poppyer
  2007-05-19 10:35 ` Daniel Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: poppyer @ 2007-05-19  4:06 UTC (permalink / raw)
  To: help-gnu-emacs

Hi, all,

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
                                   )
                                 )
                   )
    )
==========

-- 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: lisp lexical-let related
  2007-05-19  4:06 lisp lexical-let related poppyer
@ 2007-05-19 10:35 ` Daniel Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jensen @ 2007-05-19 10:35 UTC (permalink / raw)
  To: help-gnu-emacs

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))

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-05-19 10:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-19  4:06 lisp lexical-let related poppyer
2007-05-19 10:35 ` Daniel Jensen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.