unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andreas Schwab <schwab@suse.de>
Cc: Stefan Monnier <monnier+gnu/emacs@rum.cs.yale.edu>
Subject: Re: yank-handler
Date: Thu, 15 May 2003 18:19:10 +0200	[thread overview]
Message-ID: <je1xz09o8x.fsf@sykes.suse.de> (raw)
In-Reply-To: <E19GKs7-0004bm-00@fencepost.gnu.org> (Richard Stallman's message of "Thu, 15 May 2003 11:42:19 -0400")

Richard Stallman <rms@gnu.org> writes:

|>     If I kill a piece of a hunk and then yank it in some other buffer,
|>     the "[+-! ]" prefix added to each and every line should be removed
|>     (unless I'm yanking back into a diff-mode buffer or unless there's
|>     something like a "@@ -463,4 +463,36 @@" marker, obviously).
|> 
|> I have a bad feeling about this--it is the sort of thing
|> that makes the editor overall less controllable.  I would
|> prefer some sort of feature to copy part of a diff buffer
|> into the kill ring without these prefixes.

I've been using this for years:

(defun delete-columns (start end cols)
  "Delete columns from the beginning of the lines in the region.
Prefix argument gives the number of columns to delete."
  (interactive "*r\np")
  (save-excursion
    (goto-char end)
    (if (bolp) (forward-line -1))
    (move-to-column cols)
    (if (eolp) (indent-to cols))
    (delete-rectangle
     (save-excursion (goto-char start) (beginning-of-line) (point))
     (point))))

(defun copy-diff (&optional reverse)
  "Copy the current hunk of a context diff into the buffer in the next window.
Point must be at the first line to be copied.
Optional arg REVERSE (prefix arguement if interactive) means to
 assume a reversed patch."
  (interactive "P")
  (let (start region)
    (beginning-of-line)
    (setq start (point))
    (if (not (and (looking-at (if reverse "[-!] " "[+!] "))
		  (re-search-forward (if reverse
					 "\\(^[^-!]\\|\\'\\)"
				       "\\(^[^+!]\\|\\'\\)") nil t)))
	(error "Not at a context diff marker")
      (beginning-of-line)
      (setq region (buffer-substring start (point)))
      (other-window 1)
      (set-buffer (window-buffer (selected-window)))
      (push-mark)
      (insert region)
      (delete-columns (mark t) (point) 2))))

(defun copy-unidiff (&optional reverse)
  "Copy the current hunk of an unified diff into the buffer in the next window.
Point must be at the first line to be copied.
Optional arg REVERSE (prefix arguement if interactive) means to
 assume a reversed patch."
  (interactive "P")
  (let (start region)
    (beginning-of-line)
    (setq start (point))
    (if (not (and (eq (following-char) (if reverse ?- ?+))
		  (re-search-forward (if reverse
					 "\\(^[^-]\\|\\'\\)"
				       "\\(^[^+]\\|\\'\\)") nil t)))
	(error "Not at unified diff marker")
      (beginning-of-line)
      (setq region (buffer-substring start (point)))
      (other-window 1)
      (set-buffer (window-buffer (selected-window)))
      (push-mark)
      (insert region)
      (delete-columns (mark t) (point) 1))))

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

  reply	other threads:[~2003-05-15 16:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-14 16:03 yank-handler Stefan Monnier
2003-05-14 23:09 ` yank-handler Kim F. Storm
2003-05-15 15:42 ` yank-handler Richard Stallman
2003-05-15 16:19   ` Andreas Schwab [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-02-13  3:52 yank-handler Luc Teirlinck
2004-02-13  4:09 ` yank-handler Luc Teirlinck
2004-02-13 16:15 ` yank-handler Kim F. Storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=je1xz09o8x.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=monnier+gnu/emacs@rum.cs.yale.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).