🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.epoch.misc
Article #1979

Re: keysym binding - how ??

#1979
From: Douglas K. Rand
Date: Wed, 22 May 1991 00:27
297 lines
14449 bytes
** carroll@a.cs.uiuc.edu  (Alan M. Carroll) on 20 May 91 20:59:21 GMT
** in [Re: keysym binding - how ??] writes:

Alan> What you actually must do is bind the function key to some other
Alan> sequence of characters, and then bind that sequence to the
Alan> function you want. For instance, I bind "Home" to "\C-^k7" with

Alan> (rebind-key "Home" 0 "\C-^k7")

Alan> and then bind that to move to the start of the line with

Alan> (global-set-key "\C-^k7" 'beginning-of-line)

If anybody is interested, I wrote a small piece of Lisp code that
allows you to use the X name for a key in your bindings. First I
created a list of the X name of a key, and a number.

(defvar *xemacs-keys*
  '(("Select"		. 129)
    ("Insert"		. 129)
	.....))

Then I made a list of the prefixes I might want to use.

(defvar *xemacs-modifiers*
  '((shift	. (129 . xemacs-prefix-shift))
    (lock	. (130 . xemacs-prefix-lock))
    (control	. (131 . xemacs-prefix-control))
    (meta	. (132 . xemacs-prefix-meta))
    (mod1	. (133 . xemacs-prefix-mod1))
    (mod2	. (134 . xemacs-prefix-mod2))
    (mod3	. (135 . xemacs-prefix-mod3))
    (mod4	. (136 . xemacs-prefix-mod4))
    (mod5	. (137 . xemacs-prefix-mod5))
    (nil       	. (138 . xemacs-prefix-normal))))

And finally a prefix string.

(setq xemacs-prefix-string "\C-^")

My lisp function than remaps the key Insert to be the string
"\C-^ \138 \129". (Just pretend the numbers following the "\" are
decimal.)

And finally you can call my bind-xemacs-key like so:

(bind-xemacs-key "Select" 'shift 'overwrite-mode nil)

The second argument being the modifier you want to use, and the third
and forth arguments are for the normal and Meta bindings for the key
respectivly.

The lisp function should really be enhanced to automatically generate
the list of X key names to character bindings on the fly. If it can't
find the name on the list, then add it to the list with the next
available character. But, it works now. ;-)

Here is the lisp code I use on my Apollo. The bindings make
Emacs/Epoch look a lot like Apollo's DM. (Please, no flames!)

;;
;; XKEYS.EL
;;
;;	Defines the extra keys that most keyboards have to send unique key sequences
;;	that Emacs/Epoch won't otherwise use. This only works with X and requires a
;;	working x-rebind-key or epoch::rebind-key. This is done to allow function keys
;;	to directly call functions with out having to resort to the string:
;;		"\e-x<function-name>"
;;	or finding an unused key (how few there are) to bind the function to.
;;
;;	A prefix character of \C-^ (0x1e) is used. (I hope that nobody else uses this
;;	key.) Each of the prefix keys are also given a unique prefix. All of the keys
;;	used (with the exception of \C-^) are greater than 0x7f, making them unproducable
;;	regular keyboards.
;;
;; Bugs
;;	The caps-lock key is recognized as a modifier, and I don't like it. So when your
;;	caps-lock key is down, none of the function keys work.
;;

(setq xemacs-prefix-string "\C-^")						; define the prefix character to use
(setq epoch::function-key-mapping nil)						; tell Epoch to not do any function key mapping

;;
;; Defines all of the keys used on this keyboard. Each of the names that X knows the
;; key by should be listed, and a unique number should follow. Making the numbers greater
;; than 0x7f will prevent accidently mappingn to a regular key."
;;
(defvar *xemacs-keys*
  '(("Select"		. 129)
    ("Insert"		. 129)
    ("LineDel"		. 130)
    ("CharDel"		. 131)
    ("Copy"		. 132)
    ("Cut"		. 132)
    ("Paste"		. 133)
    ("Undo"		. 133)
    ("Grow"		. 134)
    ("LeftBar"		. 135)
    ("Cmd"		. 136)
    ("Shell"		. 136)
    ("RightBar"		. 137)
    ("LeftBox"		. 138)
    ("Up"		. 139)
    ("RightBox"		. 140)
    ("Left"		. 141)
    ("Next"		. 142)
    ("Right"		. 143)
    ("UpBox"		. 144)
    ("Down"		. 145)
    ("DownBox"		. 146)
    ("F10"		. 147)
    ("F1"		. 148)
    ("F2"		. 149)
    ("F3"		. 150)
    ("F4"		. 151)
    ("F5"		. 152)
    ("F6"		. 153)
    ("F7"		. 154)
    ("F8"		. 155)
    ("F9"		. 156)
    ("Redo"		. 157)
    ("Read"		. 158)
    ("Edit"		. 159)
    ("Save"		. 159)
    ("Exit"		. 160)
    ("Cancel"		. 160)
    ("Pause"		. 161)
    ("Help"		. 161)
    ("KP_0"		. 162)
    ("KP_1"		. 163)
    ("KP_2"		. 164)
    ("KP_3"		. 165)
    ("KP_4"		. 166)
    ("KP_5"		. 167)
    ("KP_6"		. 168)
    ("KP_7"		. 169)
    ("KP_8"		. 170)
    ("KP_9"		. 171)
    ("KP_Enter"		. 172)
    ("KP_Subtract"	. 173)
    ("KP_Add"		. 174)
    ("KP_Decimal"	. 175)))

;;
;; The list of modifiers availible. This list shouldn't change much between hosts. The
;; first item is the X modifier. The second will be the key after the prefix. The third
;; is the prefix command for Emacs. Again, using keys greater than 0x7f."
;;
(defvar *xemacs-modifiers*
  '((shift	. (129 . xemacs-prefix-shift))
    (lock	. (130 . xemacs-prefix-lock))
    (control	. (131 . xemacs-prefix-control))
    (meta	. (132 . xemacs-prefix-meta))
    (mod1	. (133 . xemacs-prefix-mod1))
    (mod2	. (134 . xemacs-prefix-mod2))
    (mod3	. (135 . xemacs-prefix-mod3))
    (mod4	. (136 . xemacs-prefix-mod4))
    (mod5	. (137 . xemacs-prefix-mod5))
    (nil       	. (138 . xemacs-prefix-normal))))

;;
;; Define the prefix key-maps as function definitions.
;;
(define-prefix-command 'xemacs-prefix)
(define-prefix-command 'xemacs-prefix-shift)
(define-prefix-command 'xemacs-prefix-lock)
(define-prefix-command 'xemacs-prefix-control)
(define-prefix-command 'xemacs-prefix-meta)
(define-prefix-command 'xemacs-prefix-mod1)
(define-prefix-command 'xemacs-prefix-mod2)
(define-prefix-command 'xemacs-prefix-mod3)
(define-prefix-command 'xemacs-prefix-mod4)
(define-prefix-command 'xemacs-prefix-mod5)
(define-prefix-command 'xemacs-prefix-normal)
;;
;; Now define the keys in the key map for the modifiers. (This should be a loop stepping
;; through the list. But since I don't really do Lisp, I'll leave it like this.)
;;
(global-set-key xemacs-prefix-string 'xemacs-prefix)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'shift	*xemacs-modifiers*)))) 'xemacs-prefix-shift)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'lock	*xemacs-modifiers*)))) 'xemacs-prefix-lock)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'control	*xemacs-modifiers*)))) 'xemacs-prefix-control)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'meta	*xemacs-modifiers*)))) 'xemacs-prefix-meta)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'mod1	*xemacs-modifiers*)))) 'xemacs-prefix-mod1)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'mod2	*xemacs-modifiers*)))) 'xemacs-prefix-mod2)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'mod3	*xemacs-modifiers*)))) 'xemacs-prefix-mod3)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'mod4	*xemacs-modifiers*)))) 'xemacs-prefix-mod4)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc 'mod5	*xemacs-modifiers*)))) 'xemacs-prefix-mod5)
(define-key 'xemacs-prefix (char-to-string (car (cdr (assoc   nil      	*xemacs-modifiers*)))) 'xemacs-prefix-normal)

(defun bind-xemacs-key (xemacs-key modifier binding meta-binding)
  "This defines the key passed for the given modifier. It defines both the regular
key, and the meta equivelant. This is done so that ESC can still be used as a meta key.
It is accomplished by having the meta key actually send the ESC char first."
  (interactive)
  (let ((key-code (cdr (assoc xemacs-key *xemacs-keys*)))			; find the key code for this key
	(modifier-code (car (cdr (assoc modifier *xemacs-modifiers*)))))	; and the modifier code too
    (if (null key-code)								; is there such a key defined?
	(error "%s is not a legal X11 key name." xemacs-key))
    (if (null modifier-code)							; is there such a modifer defined?
	(error "%s is not a legal X11 modifier." modifier)
    (let ((key-sequence (char-to-string key-code))				; generate a string from the key code
	  (modifier-sequence (char-to-string modifier-code)))			; and from the modifier code too
      (let ((normal-sequence (concat      xemacs-prefix-string			; put the prefix character, the modifier char
					  modifier-sequence key-sequence))	;   and the key character all together into a string
	    (meta-sequence   (concat "\e" xemacs-prefix-string			; put an ESC, and the prefix char, modifier char
				     modifier-sequence key-sequence)))		;   and the key char all together
	(global-set-key normal-sequence binding)				; define a global key for the normal binding
	(global-set-key meta-sequence   meta-binding)				; and for the meta binding
	(if (null modifier)							; is there an X modifier to tie the key to?
	    (progn								; nope...
	      (epoch::rebind-key xemacs-key 0 normal-sequence)			;   bind the key with out a modifier
	      (epoch::rebind-key xemacs-key 'meta meta-sequence))		;   and with the meta modifier too
	    (progn								; yup...
	      (epoch::rebind-key xemacs-key modifier normal-sequence)		; bind the key with the modifier
	      (epoch::rebind-key xemacs-key (list modifier 'meta) meta-sequence))))))))	; and add the meta modifier too

;;
;; Define the X keys we need. The first argument is the string that X know s the key by. The second is
;; the modifier for the key. The next two are the functions (or macros) to execute. The first is for a normal
;; (non-meta) key, and the second is for the meta.
;;
(bind-xemacs-key "Select"	nil	'set-mark-command		nil)
(bind-xemacs-key "Insert"	'shift	'overwrite-mode			nil)
(bind-xemacs-key "LineDel"	nil	'kill-whole-line		nil)
(bind-xemacs-key "LineDel"	'shift	'yank-whole-line		nil)
(bind-xemacs-key "CharDel"	nil	'delete-char			nil)
(bind-xemacs-key "Copy"		nil	'copy-region-as-kill            'x-copy-region)
(bind-xemacs-key "Cut"		'shift	'kill-region                    'x-cut-region)
(bind-xemacs-key "Paste"	nil	'yank                           'x-paste-point)
(bind-xemacs-key "Undo"		'shift	'undo				nil)
(bind-xemacs-key "LeftBar"	nil	'beginning-of-line		nil)
(bind-xemacs-key "Cmd"		nil	'execute-extended-command	nil)
(bind-xemacs-key "Shell"	'shift	'new-cmushell			nil)
(bind-xemacs-key "RightBar"	nil	'end-of-line			nil)
(bind-xemacs-key "LeftBox"	nil	'dm-scroll-right		nil)
(bind-xemacs-key "Up"		nil	'previous-line			nil)
(bind-xemacs-key "Up"		'shift	"\e1\ev"			nil)
(bind-xemacs-key "RightBox"	nil	'dm-scroll-left			nil)
(bind-xemacs-key "Left"		nil	'backward-char			nil)
(bind-xemacs-key "Left"		'shift	'backward-word			nil)
(bind-xemacs-key "Next"		nil	'other-window			nil)
(bind-xemacs-key "Right"	nil	'forward-char			nil)
(bind-xemacs-key "Right"	'shift	'forward-word			nil)
(bind-xemacs-key "UpBox"	nil	'dm-scroll-down			'comint-previous-input)
(bind-xemacs-key "UpBox"	'shift	'beginning-of-buffer		nil)
(bind-xemacs-key "Down"		nil	'next-line			nil)
(bind-xemacs-key "Down"		'shift	"\e1\C-v"			nil)
(bind-xemacs-key "DownBox"	nil	'dm-scroll-up			'comint-next-input)
(bind-xemacs-key "DownBox"	'shift	'end-of-buffer			nil)

(bind-xemacs-key "Redo"		nil	'apollo-again			nil)
(bind-xemacs-key "Read"		nil	'find-file-read-only		nil)
(bind-xemacs-key "Read"		'shift	'keyboard-find-file		nil)
(bind-xemacs-key "Edit"		nil	'find-file			nil)
(bind-xemacs-key "Save"		'shift	'save-buffer			nil)
(bind-xemacs-key "Exit"		nil	'apollo-exit			'server-edit)
(bind-xemacs-key "Cancel"	'shift	'apollo-abort			nil)
(bind-xemacs-key "Help"		'shift	'manual-entry			nil)

(bind-xemacs-key "KP_Subtract"	nil	'comint-next-input		nil)
(bind-xemacs-key "KP_Add"	nil	'comint-previous-input		nil)

(bind-xemacs-key "F10"	nil		'repeat-isearch-forward		'repeat-isearch-backward)
(bind-xemacs-key "F10"	'shift		'repeat-regexp-isearch-forward	'repeat-regexp-isearch-backward)
(bind-xemacs-key "F10"	'control	'toggle-truncate-lines		nil)
(bind-xemacs-key "F1"	nil		'isearch-forward		'isearch-forward-regexp)
(bind-xemacs-key "F1"	'shift		'print-buffer			'print-region)
(bind-xemacs-key "F1"	'control	'eval-current-buffer		'eval-region)
(bind-xemacs-key "F2"	nil		'next-error			'compile)
(bind-xemacs-key "F2"	'shift		'save-some-buffers		nil)
(bind-xemacs-key "F2"	'control	'yank-rectangle			'kill-rectangle)
(bind-xemacs-key "F3"	nil		'fill-paragraph			'auto-fill-mode)
(bind-xemacs-key "F3"	'shift		'indent-region			'indent-region-for-comment)
(bind-xemacs-key "F4"	nil		'indent-for-comment		'c-indent-command)
(bind-xemacs-key "F4"	'shift		'c-function-header		'c-module-header)
(bind-xemacs-key "F5"	nil		'query-replace			'query-replace-regexp)
(bind-xemacs-key "F5"	'shift		'find-tag			'find-next-tag)
(bind-xemacs-key "F6"	nil		'KBD-MACRO-B			'name-kbd-macro-B)
(bind-xemacs-key "F6"	'shift		'goto-mark-B			'set-mark-B)
(bind-xemacs-key "F7"	nil		'KBD-MACRO-A			'name-kbd-macro-A)
(bind-xemacs-key "F7"	'shift		'goto-mark-A			'set-mark-A)
(bind-xemacs-key "F8"	nil		'goto-line			'display-current-line)
(bind-xemacs-key "F8"	'shift		'vm				'mail)
(bind-xemacs-key "F8"	'control	'gnus				'gnus-post-news)
(bind-xemacs-key "F9"	nil		'delete-other-windows		'remove-screen)
(bind-xemacs-key "F9"	'shift		'split-window-vertically	'duplicate-screen)
(bind-xemacs-key "F9"	'control	'enlarge-window			'shrink-window)

(global-set-mouse 2 0 'mouse-find-file)
(global-set-mouse 1 0 'gwm-choose-buffer)

--
Douglas Keenan Rand                Honeywell -- Air Transport Systems Division
Phone: +1 602 436 2814               US Snail: P.O. Box 21111 Phoenix AZ 85036
NSFnet: rand@hwcae.cfsat.honeywell.com   UUCP: uunet!asuvax!apciphx!hwcae!rand
Technical Details
Message-ID: <9105220027.AA17351@hwcae.cfsat.honeywell.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!lll-winken!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage
References: <1991May20.205921.1756@m.cs.uiuc.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc7ee,f5a0e864671ee5b7
X-Google-Attributes: gidfc7ee,public
X-Google-ArrivalTime: 1991-05-22 00:15:07 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!lll-winken!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage
From: rand@hwcae.cfsat.honeywell.com (Douglas K. Rand)
Newsgroups: gnu.epoch.misc
Subject: Re: keysym binding - how ??
Message-ID: <9105220027.AA17351@hwcae.cfsat.honeywell.com>
Date: 22 May 91 00:27:53 GMT
References: <1991May20.205921.1756@m.cs.uiuc.edu>
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 297