* bug#7503: copy-and-insert-previous-line
@ 2010-11-28 10:27 Mads Jensen
2010-11-28 11:10 ` Andreas Schwab
2010-11-28 21:05 ` MON KEY
0 siblings, 2 replies; 12+ messages in thread
From: Mads Jensen @ 2010-11-28 10:27 UTC (permalink / raw
To: 7503
[-- Attachment #1: Type: text/plain, Size: 398 bytes --]
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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 10:27 bug#7503: copy-and-insert-previous-line Mads Jensen
@ 2010-11-28 11:10 ` Andreas Schwab
2010-11-28 12:56 ` Leo
` (2 more replies)
2010-11-28 21:05 ` MON KEY
1 sibling, 3 replies; 12+ messages in thread
From: Andreas Schwab @ 2010-11-28 11:10 UTC (permalink / raw
To: Mads Jensen; +Cc: 7503
Mads Jensen <mje@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@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 11:10 ` Andreas Schwab
@ 2010-11-28 12:56 ` Leo
2010-11-28 13:37 ` Eli Zaretskii
2010-11-28 14:32 ` Mads Jensen
2 siblings, 0 replies; 12+ messages in thread
From: Leo @ 2010-11-28 12:56 UTC (permalink / raw
To: bug-gnu-emacs
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.
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 11:10 ` Andreas Schwab
2010-11-28 12:56 ` Leo
@ 2010-11-28 13:37 ` Eli Zaretskii
2010-11-28 14:13 ` martin rudalics
2010-11-28 14:32 ` Mads Jensen
2 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2010-11-28 13:37 UTC (permalink / raw
To: Andreas Schwab; +Cc: mje, 7503
> From: Andreas Schwab <schwab@linux-m68k.org>
> Date: Sun, 28 Nov 2010 12:10:25 +0100
> Cc: 7503@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?
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 13:37 ` Eli Zaretskii
@ 2010-11-28 14:13 ` martin rudalics
2010-11-28 14:28 ` Eli Zaretskii
0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2010-11-28 14:13 UTC (permalink / raw
To: Eli Zaretskii; +Cc: Andreas Schwab, mje, 7503
> What's wrong with line-beginning-position and line-end-position?
Field boundaries?
martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 14:13 ` martin rudalics
@ 2010-11-28 14:28 ` Eli Zaretskii
2010-11-28 15:04 ` martin rudalics
0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2010-11-28 14:28 UTC (permalink / raw
To: martin rudalics; +Cc: schwab, mje, 7503
> Date: Sun, 28 Nov 2010 15:13:00 +0100
> From: martin rudalics <rudalics@gmx.at>
> CC: Andreas Schwab <schwab@linux-m68k.org>, mje@inducks.org,
> 7503@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."
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 11:10 ` Andreas Schwab
2010-11-28 12:56 ` Leo
2010-11-28 13:37 ` Eli Zaretskii
@ 2010-11-28 14:32 ` Mads Jensen
2010-11-28 18:57 ` Stefan Monnier
2 siblings, 1 reply; 12+ messages in thread
From: Mads Jensen @ 2010-11-28 14:32 UTC (permalink / raw
To: Andreas Schwab, 7503
[-- Attachment #1.1: Type: text/plain, Size: 983 bytes --]
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
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 261 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 14:28 ` Eli Zaretskii
@ 2010-11-28 15:04 ` martin rudalics
2010-11-28 15:44 ` Eli Zaretskii
0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2010-11-28 15:04 UTC (permalink / raw
To: Eli Zaretskii; +Cc: schwab, mje, 7503
>>> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 15:04 ` martin rudalics
@ 2010-11-28 15:44 ` Eli Zaretskii
2010-11-28 16:11 ` martin rudalics
0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2010-11-28 15:44 UTC (permalink / raw
To: martin rudalics; +Cc: schwab, mje, 7503
> Date: Sun, 28 Nov 2010 16:04:29 +0100
> From: martin rudalics <rudalics@gmx.at>
> CC: schwab@linux-m68k.org, mje@inducks.org, 7503@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?
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 15:44 ` Eli Zaretskii
@ 2010-11-28 16:11 ` martin rudalics
0 siblings, 0 replies; 12+ messages in thread
From: martin rudalics @ 2010-11-28 16:11 UTC (permalink / raw
To: Eli Zaretskii; +Cc: schwab, mje, 7503
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 14:32 ` Mads Jensen
@ 2010-11-28 18:57 ` Stefan Monnier
0 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2010-11-28 18:57 UTC (permalink / raw
To: Mads Jensen; +Cc: Andreas Schwab, 7503
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* bug#7503: copy-and-insert-previous-line
2010-11-28 10:27 bug#7503: copy-and-insert-previous-line Mads Jensen
2010-11-28 11:10 ` Andreas Schwab
@ 2010-11-28 21:05 ` MON KEY
1 sibling, 0 replies; 12+ messages in thread
From: MON KEY @ 2010-11-28 21:05 UTC (permalink / raw
To: 7503; +Cc: mje, schwab, sdl.web
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\
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-11-28 21:05 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-28 10:27 bug#7503: copy-and-insert-previous-line Mads Jensen
2010-11-28 11:10 ` Andreas Schwab
2010-11-28 12:56 ` Leo
2010-11-28 13:37 ` Eli Zaretskii
2010-11-28 14:13 ` martin rudalics
2010-11-28 14:28 ` Eli Zaretskii
2010-11-28 15:04 ` martin rudalics
2010-11-28 15:44 ` Eli Zaretskii
2010-11-28 16:11 ` martin rudalics
2010-11-28 14:32 ` Mads Jensen
2010-11-28 18:57 ` Stefan Monnier
2010-11-28 21:05 ` MON KEY
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.