🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #99511

copying-kill command

#99511
From: Roland McGrath
Date: Tue, 07 Aug 1990 00:32
60 lines
3257 bytes
This file defines the command copying-kill, which I bind to C-c C-y.

This command allows you to get the effect of copy-region-as-kill for any kill
command, not just kill-region.  For example, to copy a word to the kill-ring
without deleting it, do C-c C-y M-d.  This has the same effect as
C-SPC M-f M-w C-u C-SPC (push a new mark, move forward a word, copy the region
to the kill ring, and pop the mark).

It works by temporarily redefining kill-region as copy-region-as-kill, so it is
not dependent on particular killing commands.  It just assumes that all killing
commands will use kill-region to do the work instead of fiddling the kill-ring
and deleting manually.

Enjoy,
Roland

;;; copy-kill.el -- Perform killing commands without killing.
;;;
;;; Copyright (C) 1990 Roland McGrath
;;;
;;; This program 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.
;;;
;;; This program 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.
;;;
;;; A copy of the GNU General Public License can be obtained from this
;;; program's author (send electronic mail to roland@ai.mit.edu) or from
;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
;;; 02139, USA.
;;;
;;; Send bug reports to roland@ai.mit.edu.

;; To use this, byte-compile this file, and then put the following line
;; in your .emacs (or site-init.el, etc.):
;;  (autoload 'copying-kill "copy-kill" nil t)
;;
;; To bind this to a key, do, for example:
;;  (global-set-key "\C-c\C-y" 'copying-kill)

(defun copying-kill (command)
  "Execute the following command such that kills don't kill, but still save.
This is done by using copy-region-as-kill in place of kill-region.
Called from a program, takes one arg, which is anything that can be given
to command-execute (which see)."
  (interactive (list (key-binding
		      (let* ((this-keys (key-description (this-command-keys)))
			     (keys (read-key-sequence (concat this-keys "-"))))
			(message (concat this-keys " " (key-description keys)))
			keys))))
  (if (null command)
      (ding)
    (let ((kill-region (symbol-function 'kill-region)))
      (fset 'kill-region 'copy-region-as-kill)
      (prog1 (let (kill-region) (command-execute command))
	(fset 'kill-region kill-region)))))
Technical Details
Message-ID: <9008070032.AA28213@paris.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!gmdzi!unido!isaak!escher!nadia!smurf!ira.uka.de!sol.ctr.columbia.edu!cica!tut.cis.ohio-state.edu!PARIS.BERKELEY.EDU!mcgrath

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,f4a402b58101dc77,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-08-06 17:32:06 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!isaak!escher!nadia!smurf!ira.uka.de!sol.ctr.columbia.edu!cica!tut.cis.ohio-state.edu!PARIS.BERKELEY.EDU!mcgrath
From: mcgrath@PARIS.BERKELEY.EDU (Roland McGrath)
Newsgroups: gnu.emacs.bug
Subject: copying-kill command
Message-ID: <9008070032.AA28213@paris.Berkeley.EDU>
Date: 7 Aug 90 00:32:06 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 60
Posted: Tue Aug  7 01:32:06 1990