Article View: gnu.epoch.misc
Article #2217Keys and cut/paste
From: rand
Date: Wed, 20 Feb 1991 17:45
Date: Wed, 20 Feb 1991 17:45
256 lines
13132 bytes
13132 bytes
I'm running Epoch on an HP/Apollo, and I have this great keyboard with
lots and lots of function keys. In addition to 10 numbered function
keys, there are a lot with reasonable lables like:
mark delete line delete character
cut copy paste
undo
And many others too. Now for the question:
I like how the mouse works with Epoch to put things into the X
clipboard/paste buffer. So, how can I get my mark/cut/copy/paste keys
to do this too? It would even better if they would highlight the
selected region like the mouse.
So that pressing the mark key would then high light the region between
that and where ever I move the text cursor untill I press either the
cut or copy keys. The paste key would paste in what ever happens to be
in the X buffer at that time. (Does this make sense?)
I've included the short little function I've written to do binding to
X keys. It is different from most that I've seen in that you can
actually use the X key name for us humans, and it creates a \C-^
prefix string for you. I welcome any comments and suggestions as I do
not know enough about Lisp to be safe.
(BTW: Epoch is great! Kudos to all!)
;;
;; 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
(defvar *xemacs-keys*
"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."
'(("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)))
(defvar *xemacs-modifiers*
"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 (\C-^). The third
is the prefix command for Emacs. Again, using keys greater than 0x7f."
'((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 'apollo-copy-region nil)
(bind-xemacs-key "Cut" 'shift 'apollo-cut-region nil)
(bind-xemacs-key "Paste" nil 'apollo-paste nil)
(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 "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 "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 'goto-percent)
(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)
(bind-xemacs-key "KP_Add" 'shift "\ep" nil)
(bind-xemacs-key "KP_Subtract" 'shift "\en" nil)
--
Douglas Keenan Rand Honeywell -- Air Transport Systems Division
Phone: +1 602 436 2814 US Snail: P.O. Box 21111 Phoenix AZ 85036
Internet: @cim-vax.honeywell.com:rand@hwcae.cfsat.honeywell.com -or-
drand@hi-csc.honeywell.com
UUCP: ...!uunet!asuvax!apciphx!hwcae!rand
Technical Details
Message-ID:
<9102201745.AA09422@hwcae.cfsat.honeywell.com>Path:
arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbageShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc7ee,94bfc4a0679cb576,start X-Google-Attributes: gidfc7ee,public X-Google-ArrivalTime: 1991-02-21 16:35:32 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage From: rand@HWCAE.CFSAT.HONEYWELL.COM Newsgroups: gnu.epoch.misc Subject: Keys and cut/paste Message-ID: <9102201745.AA09422@hwcae.cfsat.honeywell.com> Date: 20 Feb 91 17:45:14 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 256