🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #1548

Re: kill-region should always do copy-region-as-kill

#1548
From: Roland McGrath
Date: Sat, 01 Apr 1989 19:09
45 lines
2484 bytes
In article <8903311121.AA02388@vega.crg.bull.fr> Stavros.Macrakis@crg.bull.fr writes:
   I suggest that kill-region ALWAYS do copy-region-as-kill, even if the
   kill itself fails (because in a read-only buffer).

I have written a function to modify the `interactive' specs of functions so
they can be used in read-only buffers:

(defun deepcopy-cons (object)
  "Return a copy of a cons.  Each element that is a cons is copied via this
function, so there are no shallow copies of conses anywhere."
  (let ((car (car object))
	(cdr (cdr object)))
    (cons (if (consp car) (deepcopy-cons car) car)
	  (if (consp cdr) (deepcopy-cons cdr) cdr))))

(defun make-command-work-for-read-only (command)
  "Modify the definition of COMMAND so that it will work in read-only buffers."
  (let* ((func (deepcopy-cons (symbol-function command)))
	 (interactive (assq 'interactive func))
	 (string (if interactive (car (setq interactive (cdr interactive)))
		   (signal 'wrong-type-argument
			   (cons 'commandp (cons command nil)))))
	 (star (string-match "\\*" string)))
    (and star
	 (setcar interactive
		 (concat (substring string 0 star)
			 (substring string (1+ star))))
	 (fset command func))
    ))


(make-command-work-for-read-only 'kill-region)
(make-command-work-for-read-only 'kill-line)
(make-command-work-for-read-only 'kill-word)
(make-command-work-for-read-only 'kill-sexp)
(make-command-work-for-read-only 'kill-sentence)
(make-command-work-for-read-only 'kill-paragraph)
(make-command-work-for-read-only 'backward-kill-word)
(make-command-work-for-read-only 'backward-kill-sexp)
(make-command-work-for-read-only 'backward-kill-sentence)
(make-command-work-for-read-only 'backward-kill-paragraph)
--
	Roland McGrath
	Free Software Foundation, Inc.
roland@wheaties.ai.mit.edu, mit-eddie!wheaties.ai.mit.edu!roland
Technical Details
Message-ID: <MCGRATH.89Apr1110904@paris.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!paris.Berkeley.EDU!mcgrath
References: <8903311121.AA02388@vega.crg.bull.fr>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!agate!paris.Berkeley.EDU!mcgrath
From: mcgrath@paris.Berkeley.EDU (Roland McGrath)
Newsgroups: gnu.emacs.bug
Subject: Re: kill-region should always do copy-region-as-kill
Message-ID: <MCGRATH.89Apr1110904@paris.Berkeley.EDU>
Date: 1 Apr 89 19:09:04 GMT
References: <8903311121.AA02388@vega.crg.bull.fr>
Sender: usenet@agate.BERKELEY.EDU
Distribution: gnu
Organization: Hackers Anonymous International, Ltd., Inc. (Applications welcome)
Lines: 45
In-reply-to: Stavros.Macrakis@crg.bull.fr's message of 31 Mar 89 11:21:12 GMT