GNU bug report logs -
#7503
copy-and-insert-previous-line
Previous Next
Reported by: Mads Jensen <mje <at> inducks.org>
Date: Sun, 28 Nov 2010 10:23:01 UTC
Severity: wishlist
Tags: wontfix
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 7503 in the body.
You can then email your comments to 7503 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 10:23:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Mads Jensen <mje <at> inducks.org>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 28 Nov 2010 10:23:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
I couldn't find a similar macro which did the same trick, so I wrote one
myself:
(defun copy-and-insert-previous-line ()
(interactive)
(save-excursion
(goto-line (1- (line-number-at-pos)))
(copy-current-line))
(yank))
It's quite useful for much of the typing I do.
--
Med Venlig Hilsen / Kind Regards,
Mads Jensen
Rubinsteinsvej 31,st.th
DK-2450 Kbh. SV
Denmark
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 11:05:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 7503 <at> debbugs.gnu.org (full text, mbox):
Mads Jensen <mje <at> inducks.org> writes:
> I couldn't find a similar macro which did the same trick, so I wrote one
> myself:
>
> (defun copy-and-insert-previous-line ()
> (interactive)
> (save-excursion
> (goto-line (1- (line-number-at-pos)))
(forward-line -1)
> (copy-current-line))
This function is not defined.
> (yank))
(defun duplicate-previous-line ()
(interactive "*")
(save-excursion
(insert
(buffer-substring (progn (forward-line -1) (point))
(progn (forward-line 1) (point))))))
Andreas.
--
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 12:52:02 GMT)
Full text and
rfc822 format available.
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
On 2010-11-28 11:10 +0000, Andreas Schwab wrote:
> (defun duplicate-previous-line ()
> (interactive "*")
> (save-excursion
> (insert
> (buffer-substring (progn (forward-line -1) (point))
> (progn (forward-line 1) (point))))))
There's also this:
,----[ C-h f copy-from-above-command RET ]
| copy-from-above-command is an interactive autoloaded Lisp function in
| `misc.el'.
|
| [Arg list not available until function definition is loaded.]
|
| Not documented.
|
| [back]
`----
Leo
--
Any Emacs contains an ad hoc, informally-specified, bug-ridden, slow
implementation of half of Common Lisp.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 13:33:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 7503 <at> debbugs.gnu.org (full text, mbox):
> From: Andreas Schwab <schwab <at> linux-m68k.org>
> Date: Sun, 28 Nov 2010 12:10:25 +0100
> Cc: 7503 <at> debbugs.gnu.org
>
> (buffer-substring (progn (forward-line -1) (point))
> (progn (forward-line 1) (point))))))
What's wrong with line-beginning-position and line-end-position?
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 14:08:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 7503 <at> debbugs.gnu.org (full text, mbox):
> What's wrong with line-beginning-position and line-end-position?
Field boundaries?
martin
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 14:24:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 7503 <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 28 Nov 2010 15:13:00 +0100
> From: martin rudalics <rudalics <at> gmx.at>
> CC: Andreas Schwab <schwab <at> linux-m68k.org>, mje <at> inducks.org,
> 7503 <at> debbugs.gnu.org
>
> > What's wrong with line-beginning-position and line-end-position?
>
> Field boundaries?
"To ignore field boundaries bind `inhibit-field-text-motion' to t."
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 14:28:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 7503 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Andreas Schwab wrote:
>> (defun copy-and-insert-previous-line ()
>> (interactive)
>> (save-excursion
>> (goto-line (1- (line-number-at-pos)))
> (forward-line -1)
>
>> (copy-current-line))
>
> This function is not defined.
Sorry for not remembering to attach this one, too.
(defun copy-current-line ()
(interactive)
(kill-ring-save (point-at-bol) (point-at-eol)))
>> (yank))
>
> (defun duplicate-previous-line ()
> (interactive "*")
> (save-excursion
> (insert
> (buffer-substring (progn (forward-line -1) (point))
> (progn (forward-line 1) (point))))))
There is a difference between my version, and this one, as mine doesn't
add the newline-character from the end of the previous line.
I'm using Emacs 22.2.1 as Emacs 23 is not the default in Ubuntu 9.10.
Thanks for the quick response :-)
--
Med Venlig Hilsen / Kind Regards,
Mads Jensen
Rubinsteinsvej 31,st.th
DK-2450 Kbh. SV
Denmark
[signature.asc (application/pgp-signature, inline)]
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 15:00:03 GMT)
Full text and
rfc822 format available.
Message #26 received at 7503 <at> debbugs.gnu.org (full text, mbox):
>>> What's wrong with line-beginning-position and line-end-position?
>> Field boundaries?
>
> "To ignore field boundaries bind `inhibit-field-text-motion' to t."
Sure. But why bother? `line-beginning-position' does `forward-line'
internally anyway.
martin
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 15:40:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 7503 <at> debbugs.gnu.org (full text, mbox):
> Date: Sun, 28 Nov 2010 16:04:29 +0100
> From: martin rudalics <rudalics <at> gmx.at>
> CC: schwab <at> linux-m68k.org, mje <at> inducks.org, 7503 <at> debbugs.gnu.org
>
> >>> What's wrong with line-beginning-position and line-end-position?
> >> Field boundaries?
> >
> > "To ignore field boundaries bind `inhibit-field-text-motion' to t."
>
> Sure. But why bother?
Because it's a useful level of abstraction?
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 16:06:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 7503 <at> debbugs.gnu.org (full text, mbox):
> Because it's a useful level of abstraction?
Should be. Unfortunately dwarfed by the field motion constraints :-(
It takes me more time to understand something like
This function constrains the returned position to the current field
unless that would be on a different line than the original,
unconstrained result. If N is nil or 1, and a rear-sticky field ends
at point, the scan stops as soon as it starts.
than to code `forward-line' within a `save-excursion'. YMMV.
martin
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 18:53:01 GMT)
Full text and
rfc822 format available.
Message #35 received at 7503 <at> debbugs.gnu.org (full text, mbox):
> There is a difference between my version, and this one, as mine doesn't
> add the newline-character from the end of the previous line.
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.
Luckily, we do have two generic solutions for it:
- you can define it in Elisp as you've done.
- you can define it as a macro.
Stefan
Information forwarded
to
owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
:
bug#7503
; Package
emacs
.
(Sun, 28 Nov 2010 21:01:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 7503 <at> debbugs.gnu.org (full text, mbox):
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\
Added tag(s) wontfix.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Mon, 05 Mar 2012 21:22:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
7503 <at> debbugs.gnu.org and Mads Jensen <mje <at> inducks.org>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 01 Feb 2014 07:27:03 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 01 Mar 2014 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 11 years and 110 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.