[Top][All Lists]

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

Customize key bindings?

From: Simon Josefsson
Subject: Customize key bindings?
Date: Mon, 29 Dec 2003 23:28:22 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Any plans to support customization of key bindings?

I have an idea for a custom-key.el that would allow users to add
global key bindings via the customize interface.  I suspect this is
sufficient for many people. It would be sufficient for me.  See below.

Any further ideas?  My needs are satisfied by this, but I'm sure it
can be improved.

Perhaps custom can be extended with a new type 'kbd' that can read a
proper key sequence from the user directly.

Looking into why the :set functions need to do set-default for
customize-variable to pick up the currently set valued would be useful
as well.  (See comment about custom bug below.)

;;; custom-key.el --- Add global key bindings via custom interface.
;; Copyright (C) 2003 Free Software Foundation, Inc.

;; Author: Simon Josefsson <address@hidden>

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; Put this file in your load-path, and add (require 'custom-key) to
;; your .emacs.
;; Run M-x customize-variable RET custom-key-alist RET and add some
;; key bindings, for example:
;; custom-key-alist's value is
;; (("<f5>" . compile)
;;  ("<f6>" . next-error)
;;  ("<f7>" . previous-error)
;;  ("C-x 4h" . gtk-doc-insert))
;; Restart Emacs and enjoy the new global key bindings.

(defcustom custom-key-alist nil
  "Association list with key bindings and functions."
  :type '(alist :key-type (string :tag "Key") :value-type function)
  :set '(lambda (symbol keyalist)
          (set-default symbol keyalist) ;; work around custom bug
          (mapcar (lambda (key)
                    (global-set-key (read-kbd-macro (car key)) (cdr key)))

(provide 'custom-key)

;;; custom-key.el ends here

reply via email to

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