unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: stromme@mi.uib.no (Stein A. Stromme)
Subject: Re: Copy and Pasting in Emacs...
Date: Mon, 08 Mar 2004 15:00:57 +0100	[thread overview]
Message-ID: <wwllmbsajq.fsf@eliud.mi.uib.no> (raw)
In-Reply-To: jwvznar1mqv.fsf-monnier+gnu.emacs.help@asado.iro.umontreal.ca

[Stefan Monnier on copying a line]

|        Stefan "who'd use C-k C-y to copy and then C-y to yank"

I have this in my .emacs, stolen from Xemacs but works in GNU Emacs
as well:

    ;;; Utility from xemacs/lisp/misc.el

    (defun copy-from-above-command (&optional arg)
      "Copy characters from previous nonblank line, starting just above point.
    Copy ARG characters, but not past the end of that line.
    If no argument given, copy the entire rest of the line.
    The characters copied are inserted in the buffer before point."
      (interactive "P")
      (let ((cc (current-column))
        n
        (string ""))
        (save-excursion
          (beginning-of-line)
          (backward-char 1)
          (skip-chars-backward "\ \t\n")
          (move-to-column cc)
          ;; Default is enough to copy the whole rest of the line.
          (setq n (if arg (prefix-numeric-value arg) (point-max)))
          ;; If current column winds up in middle of a tab,
          ;; copy appropriate number of "virtual" space chars.
          (if (< cc (current-column))
          (if (eq (char-before (point)) ?\t)
              (progn
            (setq string (make-string (min n (- (current-column) cc)) ?\ ))
            (setq n (- n (min n (- (current-column) cc)))))
            ;; In middle of ctl char => copy that whole char.
            (backward-char 1)))
          (setq string (concat string
                   (buffer-substring
                    (point)
                    (min (save-excursion (end-of-line) (point))
                     (+ n (point)))))))
        (insert string)))

    (define-key global-map [(insert)] 'copy-from-above-command)

So to copy a line I move point below the line and do C-o (if
necessary, to make space for the new line) and then [insert].
(Feel free to use a different keystroke if you actually need the
insert key for something else.)

Of course this is only useful if you really want the new copy to come
immediately after the original, but I find this often to be the case.

SA
-- 
Stein Arild Strømme            +47 55584825, +47 95801887
Universitetet i Bergen                  Fax: +47 55589672     
Matematisk institutt               www.mi.uib.no/stromme/         
Johs Brunsg 12, N-5008 BERGEN           stromme@mi.uib.no

  reply	other threads:[~2004-03-08 14:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-07 23:20 Copy and Pasting in Emacs Patrick
2004-03-08  0:34 ` Billy O'Connor
2004-03-08  2:42 ` Benjamin Rutt
2004-03-08  4:36 ` Floyd L. Davidson
2004-03-08 13:44 ` Stefan Monnier
2004-03-08 14:00   ` Stein A. Stromme [this message]
2004-03-08 18:58   ` Kevin Rodgers

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=wwllmbsajq.fsf@eliud.mi.uib.no \
    --to=stromme@mi.uib.no \
    /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.
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).