unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Customize key bindings?
@ 2003-12-29 22:28 Simon Josefsson
  2003-12-30  2:17 ` Luc Teirlinck
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Simon Josefsson @ 2003-12-29 22:28 UTC (permalink / raw)


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 <simon@josefsson.org>

;; 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
;; 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)))
		  keyalist)))

(provide 'custom-key)

;;; custom-key.el ends here

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

* Re: Customize key bindings?
  2003-12-29 22:28 Customize key bindings? Simon Josefsson
@ 2003-12-30  2:17 ` Luc Teirlinck
  2003-12-30 10:56   ` Simon Josefsson
  2003-12-30 14:38 ` Alex Schroeder
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Luc Teirlinck @ 2003-12-30  2:17 UTC (permalink / raw)
  Cc: emacs-devel

Simon Josefsson wrote:

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

Why is this a bug?  Custom sets default values, so it has to use
set-default.  (What else would you have wanted to use?)

Sincerely,

Luc.

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

* Re: Customize key bindings?
  2003-12-30  2:17 ` Luc Teirlinck
@ 2003-12-30 10:56   ` Simon Josefsson
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Josefsson @ 2003-12-30 10:56 UTC (permalink / raw)
  Cc: emacs-devel

Luc Teirlinck <teirllm@dms.auburn.edu> writes:

> Simon Josefsson wrote:
>
>    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.)
>
> Why is this a bug?  Custom sets default values, so it has to use
> set-default.  (What else would you have wanted to use?)

It might not be a bug, but without set-default you get a rather
surprising result:

start emacs
M-x customize-variable RET custom-key-alist RET
add some settings
click on set + save
quit emacs

<<the variable the user selected is stored in .emacs>>
<<the variable itself in the running emacs was still nil>>

start emacs
M-x customize-variable RET custom-key-alist RET
the list is now empty?
clicking on set + save loses the settings made previously?

I think I understand why it behave like this now -- customize only
customizes real variable values, and the :set should be responsible
for setting the variable as well.  I removed the comment about a
custom bug in my second release of custom-key.el to gnu.emacs.sources,
after realizing this, last night.

(Perhaps the "save" step in part 1 above really shouldn't have stored
the values the user selected?  It should have saved the contents of
the variable, the value after calling :set?)

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

* Re: Customize key bindings?
  2003-12-29 22:28 Customize key bindings? Simon Josefsson
  2003-12-30  2:17 ` Luc Teirlinck
@ 2003-12-30 14:38 ` Alex Schroeder
  2003-12-30 20:21   ` Simon Josefsson
  2003-12-30 19:43 ` Richard Stallman
  2004-01-03 23:25 ` Simon Josefsson
  3 siblings, 1 reply; 9+ messages in thread
From: Alex Schroeder @ 2003-12-30 14:38 UTC (permalink / raw)
  Cc: emacs-devel

Simon Josefsson <jas@extundo.com> writes:

> Any plans to support customization of key bindings?
>
> Any further ideas?  My needs are satisfied by this, but I'm sure it
> can be improved.

There was some effort by me and Per some time ago on a custom widget
for keymaps.  It worked quite well, but neither me nor Per ever
installed it, if I remember correctly.

Would you be interested in it?  I'd dig through my mail archives and
see whether I can find something.

Alex.
-- 
.O.  http://www.emacswiki.org/alex/
..O  Schroeder's first law:
OOO  The coffee at the office shall taste terrible.

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

* Re: Customize key bindings?
  2003-12-29 22:28 Customize key bindings? Simon Josefsson
  2003-12-30  2:17 ` Luc Teirlinck
  2003-12-30 14:38 ` Alex Schroeder
@ 2003-12-30 19:43 ` Richard Stallman
  2003-12-30 20:34   ` Simon Josefsson
  2004-01-03 23:25 ` Simon Josefsson
  3 siblings, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2003-12-30 19:43 UTC (permalink / raw)
  Cc: emacs-devel

    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.

That is a feature I would definitely like to have added.
I agree that global bindings are enough to make a very useful feature.

However, I would expect that the `string' type is not very convenient
for specifying a key sequence.  The right way is to let the user
actually type the key sequene to bind, as global-set-key already does.
Can someone define a type for that?

I think that our current interface for adding to an alist
is rather inconvenient too.

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

* Re: Customize key bindings?
  2003-12-30 14:38 ` Alex Schroeder
@ 2003-12-30 20:21   ` Simon Josefsson
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Josefsson @ 2003-12-30 20:21 UTC (permalink / raw)
  Cc: emacs-devel

Alex Schroeder <alex@emacswiki.org> writes:

> Simon Josefsson <jas@extundo.com> writes:
>
>> Any plans to support customization of key bindings?
>>
>> Any further ideas?  My needs are satisfied by this, but I'm sure it
>> can be improved.
>
> There was some effort by me and Per some time ago on a custom widget
> for keymaps.  It worked quite well, but neither me nor Per ever
> installed it, if I remember correctly.
>
> Would you be interested in it?  I'd dig through my mail archives and
> see whether I can find something.

Did it work by modifying *-keymap?  I thought about that approach as
well, to support key customization in non-global modes as well, but
later changed my mind because it sounded like work, with possible
robustness issues, and the gains were unclear.  Adding global key
bindings solved my needs.  I'll try to look through old archives.
Although there is nothing that prevents installing both yours and mine
solutions, I think they would complement rather than compete.

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

* Re: Customize key bindings?
  2003-12-30 19:43 ` Richard Stallman
@ 2003-12-30 20:34   ` Simon Josefsson
  2004-01-02 16:11     ` Kai Grossjohann
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Josefsson @ 2003-12-30 20:34 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     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.
>
> That is a feature I would definitely like to have added.
> I agree that global bindings are enough to make a very useful feature.

Good.

> However, I would expect that the `string' type is not very convenient
> for specifying a key sequence.  The right way is to let the user
> actually type the key sequene to bind, as global-set-key already does.
> Can someone define a type for that?

Yes, this would be better.  I'm not really familiar with custom enough
to add a new type, but some ideas on the GUI:

The custom buffer could look like:

[INS] [DEL] Key: <f5>...           [READ KEY]
            Function: compile...

Where the '<f5>...' and 'compile...' are the current string input
fields, [INS]/[DEL] are the alist buttons, and [READ KEY] is a new
button users can press that read a key interactively, much like C-h k
or similar.  Advanced users can still enter the key binding using the
string input field.

There is one complication though -- imagine if the user wants to bind
'C-c x y z' to something, effectively creating sub-keymaps.  Should
this be possible?  How?  I'm leaning towards not supporting it.  The
problem is to find out when the key pressed by the user "ends".  It is
easier to only allow the user to only add simple key bindings to
existing keymaps.

> I think that our current interface for adding to an alist
> is rather inconvenient too.

Hm, I can't think of anything I find problematic.

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

* Re: Customize key bindings?
  2003-12-30 20:34   ` Simon Josefsson
@ 2004-01-02 16:11     ` Kai Grossjohann
  0 siblings, 0 replies; 9+ messages in thread
From: Kai Grossjohann @ 2004-01-02 16:11 UTC (permalink / raw)


Simon Josefsson <jas@extundo.com> writes:

> The custom buffer could look like:
>
> [INS] [DEL] Key: <f5>...           [READ KEY]
>             Function: compile...
>
> Where the '<f5>...' and 'compile...' are the current string input
> fields, [INS]/[DEL] are the alist buttons, and [READ KEY] is a new
> button users can press that read a key interactively, much like C-h k
> or similar.  Advanced users can still enter the key binding using the
> string input field.
>
> There is one complication though -- imagine if the user wants to bind
> 'C-c x y z' to something, effectively creating sub-keymaps.  Should
> this be possible?  How?  I'm leaning towards not supporting it.  The
> problem is to find out when the key pressed by the user "ends".  It is
> easier to only allow the user to only add simple key bindings to
> existing keymaps.

When I read your description of the interface, I thought users were
supposed to hit [READ KEY], then type C-c, then [READ KEY], then x,
then [READ KEY], then y, and [READ KEY] and z, in order to bind the
key (sequence) C-c x y z.

So I was surprised that you thought that there is a problem with
multi-key sequences ;-)

Kai

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

* Re: Customize key bindings?
  2003-12-29 22:28 Customize key bindings? Simon Josefsson
                   ` (2 preceding siblings ...)
  2003-12-30 19:43 ` Richard Stallman
@ 2004-01-03 23:25 ` Simon Josefsson
  3 siblings, 0 replies; 9+ messages in thread
From: Simon Josefsson @ 2004-01-03 23:25 UTC (permalink / raw)


I realized this same idea can be applied to customizing environment
variables and autoload cookies too.  Here's an improved version of
custom-key.el, now renamed to cus-misc.el because it is no longer key
binding specific.  I suspect there may be other similar things that
can be customized using the same approach, but these cover what I
need.

An approach like this could be used to provide facilities to add paths
to `load-path' and regexps to `auto-mode-alist' too, but I'm not sure
that is a good idea.  Those variables could be properly customizable
with the "difflist" custom :type discussed here earlier.

;;; cus-misc.el --- Customize key bindings, autoloads and env. variables.
;; Copyright (C) 2003, 2004 Free Software Foundation, Inc.

;; Author: Simon Josefsson <simon@josefsson.org>

;; 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
;; 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, evaluate it, and 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))
;;
;; Click on 'Save', and restart Emacs to enjoy the now (hopefully)
;; automagically configured new global key bindings.
;;
;; Similarly, customize `custom-autoload-alist' and
;; `custom-environment-variable-alist' to add autoload cookies and
;; environment variables, respectively.  For example:
;;
;; custom-autoload-alist's value is
;; ((mail-add-payment . "hashcash"))
;;
;; custom-environment-variable-alist's value is
;; (("CVS_RSH" . "ssh"))

;;; History:

;; 2003-12-30 initial release
;; 2003-12-30 second release, fixed comments and added :require to defcustom.
;; 2004-01-04 added autoloads and environment variables,
;;            renamed to cus-misc.el.

(defcustom custom-key-alist nil
  "Association list with key bindings and functions."
  :type '(alist :key-type (string :tag "Key")
		:value-type (function :tag "Command"))
  :set '(lambda (symbol infolist)
	  (set-default symbol infolist)
	  (mapcar (lambda (info)
		    (global-set-key (read-kbd-macro (car info)) (cdr info)))
		  infolist))
  :require 'cus-misc)

(defcustom custom-autoload-alist nil
  "Association list with autoload definitions to set on startup."
  :type '(alist :key-type (symbol :tag "Function")
		:value-type (string :tag "Elisp file"))
  :set '(lambda (symbol infolist)
	  (set-default symbol infolist)
	  (mapcar (lambda (info)
		    (autoload (car info) (cdr info)))
		  infolist))
  :require 'cus-misc)

(defcustom custom-environment-variable-alist nil
  "Association list with environment variables to `setenv' on startup."
  :type '(alist :key-type (string :tag "Environment Variable")
		:value-type (string :tag "Value"))
  :set '(lambda (symbol infolist)
	  (set-default symbol infolist)
	  (mapcar (lambda (info)
		    (setenv (car info) (cdr info)))
		  infolist))
  :require 'cus-misc)

(provide 'cus-misc)

;;; cus-misc.el ends here

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

end of thread, other threads:[~2004-01-03 23:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-29 22:28 Customize key bindings? Simon Josefsson
2003-12-30  2:17 ` Luc Teirlinck
2003-12-30 10:56   ` Simon Josefsson
2003-12-30 14:38 ` Alex Schroeder
2003-12-30 20:21   ` Simon Josefsson
2003-12-30 19:43 ` Richard Stallman
2003-12-30 20:34   ` Simon Josefsson
2004-01-02 16:11     ` Kai Grossjohann
2004-01-03 23:25 ` Simon Josefsson

Code repositories for project(s) associated with this public inbox

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

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