all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Klaus-Dieter Bauer <bauer.klaus.dieter@gmail.com>,
	emacs help <help-gnu-emacs@gnu.org>
Subject: RE: Customizing per-keymap key bindings through the customize interface?
Date: Thu, 27 Jun 2013 06:57:41 -0700 (PDT)	[thread overview]
Message-ID: <8c49d765-2115-4db3-8507-b6f2c991d547@default> (raw)
In-Reply-To: <CANtbJLFz=dxb7Xy45jpcUmZ1zMmWZNMfZLsSANHQce_nVncqcQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3658 bytes --]

> Is there currently some package available that allows managing custom
> key bindings on a per-keymap-basis through the `customize` interface?

Not really, AFAIK.  But there might be some related discussion on
emacs-devel or the Emacs bug list.

> I got a bit annoyed recently by losing track of all the custom
> keybindings I have made, so I wrote a function, that automatically
> adds an entry in a menu in global-map for every custom keybinding.
> Now I am intending to extend this to utilizing the custom interface for
> creating keybindings on a per-mode basis.
> 
> While relatively easy to do, I'd prefer a commonly used solution, if
> there is any.
> 
> PS: I'm still not sure whether such questions should go to emacs-help or
> emacs-devel.

Either is probably OK in this case.  emacs-devel might be a bit better,
since this would be a new development/feature.  But with help-gnu-emacs
you might get more info about existing 3rd-party features.  You can also
file Emacs enhancement requests, using `M-x report-emacs-bug'.


FWIW, I sometimes provide user options that have key-binding values.
Not a complete solution, but it can make things easier.

For example, option `icicle-top-level-key-bindings' is an alist whose
entries are of defcustom :type `icicle-key-definition', which means that
they have the form (KEY COMMAND CONDITION), where KEY is either a key
sequence (string or vector) to bind COMMAND to or a command to remap
to COMMAND.  COMMAND is bound according to the value of KEY, unless the
result of evaluating CONDITION is nil.

In Customize, to specify a key sequence, you choose `Key' in the `Value
Menu', then enter a key description such as that returned by `C-h k'.
For convenience, you can also insert a key in the key description by
hitting `C-q' then the key. For example, to enter the key description
`C-c M-k' you can use `C-q C-c C-q M-k'.

Attached is what key bindings look like in Customize.

In Lisp (e.g., to define the default value for a key-binding option),
an unconditional key binding looks like this:
  ("\C-c="  icicle-imenu  t)

A conditional key binding looks like this:
  ([f10]  lacarte-execute-menu-command
   (fboundp 'lacarte-execute-menu-command))

A conditional binding that remaps another command looks like this:
  (bmkp-tag-a-file  icicle-tag-a-file  (fboundp 'bmkp-tag-a-file))

KEY can also be expressed using `kbd', of course:
  `(,(kbd "C-c =")  icicle-imenu  t)
or
  (list (kbd "C-c =") 'icicle-imenu  t)


This is the code that defines custom type `icicle-key-definition':

(define-widget 'icicle-key-definition 'lazy
  "Key definition type for Icicle mode keys.
A list of three components: KEY, COMMAND, CONDITION, that represents
an `icicle-mode-map' binding of COMMAND according to KEY, if CONDITION
evaluates to non-nil.

KEY is either a key sequence (string or vector) or a command.
COMMAND is a command.
CONDITION is a sexp.

If KEY is a command, then the binding represented is its remapping to
COMMAND."
  :indent 1 :offset 0 :tag ""
  :type
  '(list
    (choice
     (key-sequence :tag "Key" :value [ignore])
     ;; Use `symbolp' instead of `commandp',
     ;; in case the library defining the command is not loaded.
     (restricted-sexp :tag "Command to remap"
                      :match-alternatives (symbolp) :value ignore))
     ;; Use `symbolp' instead of `commandp'...
    (restricted-sexp :tag "Command"
                     :match-alternatives (symbolp) :value ignore)
    (sexp :tag "Condition")))

The code is here:
http://www.emacswiki.org/emacs-en/download/icicles-opt.el

HTH.

[-- Attachment #2: throw-key-customize-2.png --]
[-- Type: image/png, Size: 4265 bytes --]

[-- Attachment #3: throw-key-customize-1.png --]
[-- Type: image/png, Size: 3147 bytes --]

  reply	other threads:[~2013-06-27 13:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27  8:02 Customizing per-keymap key bindings through the customize interface? Klaus-Dieter Bauer
2013-06-27 13:57 ` Drew Adams [this message]
2013-06-27 14:36   ` Klaus-Dieter Bauer

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

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

  git send-email \
    --in-reply-to=8c49d765-2115-4db3-8507-b6f2c991d547@default \
    --to=drew.adams@oracle.com \
    --cc=bauer.klaus.dieter@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
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.