🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98544

control-z-prefix.el (Was: C-c LETTER transgressions)

#98544
From: Bruce Leban
Date: Fri, 17 May 1991 20:03
123 lines
5649 bytes
DanJ> From: Dan_Jacobson@ATT.COM
DanJ> * Please do not define `C-c LETTER' as a key.  These sequences are
DanJ> reserved for users; they are the *only* sequences reserved for
DanJ> users, so we cannot do without them.

WJC> From: wjc@hos1cad.att.com (William J Carpenter)
WJC> [2]  Telling people not to use C-c without suggesting an alternative
WJC> is promoting chaos.  How shall you set your keybindings?  Just pick
WJC> some other prefix key that you're sure isn't in use?  They're mighty
WJC> scarce.
WJC> 
WJC> [3]  If the point of the request was to save me trouble and confusion,
WJC> it would have just the opposite effect.  Many of the bindings that I
WJC> use all the time would have to go to some other keys, and I would have
WJC> to relearn them (or rebind them myself to what they are now).  The
WJC> C-c prefix is a sort of de facto standard for keys used by packages.

I have a simple suggestion.  Create a new prefix character.  It would
certainly be unreasonable to take C-a and make it a prefix character.  (It's
bad enough that backspace on some terminals is a help key.)  C-z is bound to
suspend-emacs for historical reasons.  I suggest defining:

	C-c	mode prefix character -- these commands depend on the
		mode of the current buffer
	C-z	user prefix character -- reserved for user

Suspend-emacs is already bound to C-x C-z.  If the user wants to define mode
specific commands, they can either define C-z prefix commands in the
appropriate mode map or they can fit them into the holes in the C-c map for
that mode.

I've been using this for a while and I find it vastly preferable to trying
to fit my additional key bindings into the holes in the default bindings.
Here for example are some of my bindings:
	(define-control-z "\C-d" 'delete-file)
	(define-control-z "\C-r" 'rename-file)
	(define-control-z "\C-c" 'copy-file)
	(define-control-z "\C-w" 'write-region)
	(define-control-z "r" 'rename-buffer)

	--- Bruce
	Leban@cs.umass.edu  @amherst.mass.usa.earth

   o /
----X----- control-z-prefix.el -------------------------------------------
   o \

;; Control-Z prefix for Emacs.
;; Copyright (C) 1991 Bruce Leban.

;; This file is NOT YET 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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA.

; -------------------------- C-z (USER PREFIX) ---------------------------

; C-z is the "user" command prefix, just like C-c is the mode command
; prefix.  Emacs will NEVER define commands that start with C-z.  Add to
; this list whenever you find yourself doing something with M-x repeatedly.

; To add keys to the user prefix map, put lines like the following in 
; your .emacs file:
;	(load "c-z-prefix")
;	(define-control-z "." 'goto-line)
; which defines the key sequence C-z . to execute goto-line.

; Do NOT redefine C-z C-h (control-z-help).
; Do NOT redefine C-z C-g (keyboard-quit).

; ------------------------------------------------------------------------

;(global-set-key "\C-x\C-z" (key-binding "\C-z")) ; not necessary

(global-unset-key "\C-z")
(global-set-key "\C-z\C-h" 'control-z-help)
(global-set-key "\C-h\C-z" 'control-z-help)
(global-set-key "\C-z\C-g" 'keyboard-quit)

(defun control-z-help ()
    (interactive)
    (if (fboundp 'with-electric-help)
	(with-electric-help 'control-z-bindings)
	(with-output-to-temp-buffer "*Help*"
	    (set-buffer "*Help*")
	    (control-z-bindings)
	    (print-help-return-message))))

(defun control-z-bindings ()
    (insert "Control-Z (User Prefix) Bindings:\n")
    (let ((i 0))
	(while (<= i 127)
	    (let* ((key (concat "\C-z" (char-to-string i)))
		   (bind (key-binding key)))
		(if bind
		    (insert ?\n
			    (key-description key)
			    ?\C-i
			    (symbol-name bind))))
	    (setq i (1+ i)))))

(defun define-control-z (key binding)
    "Give C-z KEY a definition of BINDING.
See global-set-key for more info." 
    (interactive "cSet Key: C-z 
CSet key C-z %s to command: ")
    (let* ((z-key (concat "\C-z" (if (numberp key) (char-to-string key) key)))
	   (old-binding (key-binding z-key)))
	(if old-binding
	    (error "%s is already defined as %s."
		   (key-description z-key) old-binding)
	    (global-set-key z-key binding))))
Technical Details
Message-ID: <LEBAN.91May17160327@par6.cs.umass.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!unreplyable!garbage
References: <1991May15.153747.1005@cbnewse.att.com> <1991May15.162011.16617@cbnewsh.att.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,6fb737b2af94eef7
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-05-17 13:03:27 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!unreplyable!garbage
From: leban%par6@cs.umass.edu (Bruce Leban)
Newsgroups: gnu.emacs.bug
Subject: control-z-prefix.el   (Was: C-c LETTER transgressions)
Message-ID: <LEBAN.91May17160327@par6.cs.umass.edu>
Date: 17 May 91 20:03:27 GMT
References: <1991May15.153747.1005@cbnewse.att.com> <1991May15.162011.16617@cbnewsh.att.com>
Sender: daemon@tut.cis.ohio-state.edu
Followup-To: gnu.emacs.bug
Distribution: gnu
Organization: /usr/par/leban/.organization
Lines: 123
Approved: bug-gnu-emacs@prep.ai.mit.edu