unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Keybindings and minor modes
Date: Thu, 29 Dec 2005 12:23:52 -0700	[thread overview]
Message-ID: <dp1d4c$3h4$1@sea.gmane.org> (raw)
In-Reply-To: <1135822695.537535.182680@f14g2000cwb.googlegroups.com>

batkins57@gmail.com wrote:
 > I'd like to bind a command to tab in a minor mode I'm writing, but I'd
 > also like to preserve any command that might have been attached to that
 > key before making my binding (such as indentation).  In other words,
 > I'd like to add functionality to an existing keybinding without
 > completely overwriting the binding.
 >
 > The solution I came up with was to simply store the currently bound
 > command in a buffer-local variable whenever the minor mode is invoked.
 > Then the keys are bound to functions that provide my additional
 > functionality and then funcall the old bindings.  This works, but I
 > wonder if there isn't a cleaner way to pass a keychord event on to the
 > next handler.  The code I have now is pretty ugly, since a key bound to
 > self-insert-command has to be handled separately so that
 > self-insert-command will get an argument of 0.

I think you could avoid storing the command in a local variable by
accessing the local binding (defined by the major mode) or global
binding dynamically.  That would simplify things a little.

I'll admit, I don't understand the point of calling
(self-insert-command 0).

Perhaps a better approach altogether would be to add a pre-command-hook
that would check the key that was used to invoke it:

(defun ehinter-pre-command-hook ()
   "Run `ehinter-hint' in Ehinter Minor Mode, when invoked via SPC, TAB, 
or RET."
   (when (and ehinter-mode
              (let ((key (this-single-command-keys)))
                (and (= (length key 1))
                     (member (aref key 0) '(?  ?\t ?\r))))) ; SPC, TAB, 
or RET
     (ehinter-hint)))

(add-hook 'pre-command-hook 'ehinter-pre-command-hook)

Then the ehinter-mode function just needs to set or unset the
buffer-local ehinter-mode variable.

You could tweak that to have the ehinter-mode function add or remove
ehinter-pre-command-hook from the buffer-local pre-command-hook, to
avoid affecting other buffers.

-- 
Kevin Rodgers

  reply	other threads:[~2005-12-29 19:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-29  2:18 Keybindings and minor modes batkins57
2005-12-29 19:23 ` Kevin Rodgers [this message]
     [not found] ` <mailman.20813.1135884349.20277.help-gnu-emacs@gnu.org>
2005-12-29 22:02   ` batkins57
2006-01-01 16:26     ` albrns
2006-01-01 16:27 ` albrns

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='dp1d4c$3h4$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).