Subject: Re: bug#7503: copy-and-insert-previous-line

From: MON KEY <[email-masked]>
Date: Sun, 28 Nov 2010 16:05:34 -0500

I think such differences is the reason why such commands are not
    very good candidates for inclusion in Emacs: there are so many
    different commands that do something along these lines, that
    adding them all would not make much sense.

FWIW following is my more generalized take on Andreas' and Mads' versions.

This one:
 - Doesn't step on the kill-ring;
 - Has option to keep/omit text-props;
 - inserts only when asked to do so:

;;; <Timestamp: #{2010-11-28T12:10:07-05:00Z}#{10477} - by MON>
(defun line-previous-duplicate (&optional keep-props insrtp intrp)
  "Return content of previous line.
When optional arg KEEP-PROPS is non-nil return value is as if by
`buffer-substring'.  Default is as if by `buffer-substring-no-properties'.
When optional arg INSRTP is non-nil or called-interactively, insert return value
at point. Does not move point."
  (interactive "*i\ni\np")
  (save-excursion
    (let ((lpd-psns `(,(progn (forward-line -1) (point)) .
                      ,(progn (forward-line 1) (point)))))
      (set (or (and intrp  (quote intrp))
               (and insrtp (quote insrtp))
               (and (set (quote intrp) (quote insrtp))
                    (quote insrtp)))
           (or (and keep-props
                    (buffer-substring (car lpd-psns) (cdr lpd-psns)))
               (buffer-substring-no-properties
                (car lpd-psns) (cdr lpd-psns)))))
    (or (and (not (eq intrp 'insrtp))
             (stringp insrtp)
             (insert insrtp))
        (and intrp
             (stringp intrp)
             (insert intrp))
        insrtp)))

--
/s_P\