* copy-word-from-line-above
@ 2007-01-18 17:51 HS
2007-01-18 20:50 ` copy-word-from-line-above Marc Tfardy
2007-01-19 20:25 ` copy-word-from-line-above rgb
0 siblings, 2 replies; 13+ messages in thread
From: HS @ 2007-01-18 17:51 UTC (permalink / raw)
Hello!
Does anyone have a function that copies words from the line above, word
after word ?
I'd like this function so I could have something like this:
double int xxx;
Then I'd just put the cursor under that line, press <f2> (for example)
twice and would be in this state:
double int xxx;
double int
then I would continue adding the new variable.
Thanks in advance,
HS
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-18 17:51 copy-word-from-line-above HS
@ 2007-01-18 20:50 ` Marc Tfardy
2007-01-19 0:36 ` copy-word-from-line-above Nikos Apostolakis
2007-01-19 20:25 ` copy-word-from-line-above rgb
1 sibling, 1 reply; 13+ messages in thread
From: Marc Tfardy @ 2007-01-18 20:50 UTC (permalink / raw)
HS wrote:
> Hello!
> Does anyone have a function that copies words from the line above, word
> after word ?
> I'd like this function so I could have something like this:
>
> double int xxx;
>
> Then I'd just put the cursor under that line, press <f2> (for example)
> twice and would be in this state:
>
> double int xxx;
> double int
>
> then I would continue adding the new variable.
Not exactly what you looking for, but a simple macro do a similar job:
C-a ;; beginning-of-line
C-p ;; previous-line
C-SPC ;; set-mark-command
C-e ;; end-of-line
M-w ;; kill-ring-save
C-a ;; beginning-of-line
C-n ;; next-line
C-y ;; yank
or:
(fset 'duplicate-last-line
[?\C-a ?\C-p ?\C- ?\C-e ?\M-w ?\C-a ?\C-n ?\C-y])
This macro duplcates whole previous line. The point is on the
end of the line. Now you can press (one or more times ) M-DEL
and continue editing.
regards
Marc
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-18 20:50 ` copy-word-from-line-above Marc Tfardy
@ 2007-01-19 0:36 ` Nikos Apostolakis
0 siblings, 0 replies; 13+ messages in thread
From: Nikos Apostolakis @ 2007-01-19 0:36 UTC (permalink / raw)
Marc Tfardy <m-t-o@web.de> writes:
> HS wrote:
>> Hello!
>> Does anyone have a function that copies words from the line above, word
>> after word ?
>> I'd like this function so I could have something like this:
>>
>> double int xxx;
>>
>> Then I'd just put the cursor under that line, press <f2> (for example)
>> twice and would be in this state:
>>
>> double int xxx;
>> double int
>>
>> then I would continue adding the new variable.
>
> Not exactly what you looking for, but a simple macro do a similar job:
>
[...]
>
> This macro duplcates whole previous line. The point is on the
> end of the line. Now you can press (one or more times ) M-DEL
> and continue editing.
Here is a slightly better keyboard macro to record. Go underneath
the line that you want to incrementally copy and do (spaces inseted
for readability)
C-x( C-e C-p C-M-s \< C-<space> C-M-s C-s M-w C-n C-y C-x)
IOW, go to the end of line, go to the line above, search for
beginning of word, set the mark, find the next beginning of word,
copy region, go to next line, yank. Now hit C-xe to copy the word
above and (in emacs22 at least) keep hiting "e" to repeat as many
times as desired. Haven't thoroughly checked it but it should work.
Shouldn't be hard to write this in lisp, either.
HTH
Nikos
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-18 17:51 copy-word-from-line-above HS
2007-01-18 20:50 ` copy-word-from-line-above Marc Tfardy
@ 2007-01-19 20:25 ` rgb
2007-01-21 5:36 ` copy-word-from-line-above Greg Bognar
1 sibling, 1 reply; 13+ messages in thread
From: rgb @ 2007-01-19 20:25 UTC (permalink / raw)
HS wrote:
> Hello!
> Does anyone have a function that copies words from the line above, word
> after word ?
> I'd like this function so I could have something like this:
>
> double int xxx;
>
> Then I'd just put the cursor under that line, press <f2> (for example)
> twice and would be in this state:
>
> double int xxx;
> double int
>
I use this because its a bit more flexable.
It allows you to copy exactly the parts you want even if not full
words.
(global-set-key [?\C-\M-z] 'insert-prior-line-char)
(defun insert-prior-line-char ()
"Insert the same character as in the prior line. Space if none."
(interactive)
(let* ((cur (current-column))
(char (save-excursion
(if (or (not (eq 0 (forward-line -1)))
(not (eq cur (move-to-column cur)) ))
32
(char-after)))))
(insert char)))
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-19 20:25 ` copy-word-from-line-above rgb
@ 2007-01-21 5:36 ` Greg Bognar
2007-01-21 16:15 ` copy-word-from-line-above rgb
0 siblings, 1 reply; 13+ messages in thread
From: Greg Bognar @ 2007-01-21 5:36 UTC (permalink / raw)
> I use this because its a bit more flexable. It allows you to copy exactly
> the parts you want even if not full words.
>
> (global-set-key [?\C-\M-z] 'insert-prior-line-char)
>
> (defun insert-prior-line-char ()
> "Insert the same character as in the prior line. Space if none."
> (interactive)
> (let* ((cur (current-column))
> (char (save-excursion
> (if (or (not (eq 0 (forward-line -1)))
> (not (eq cur (move-to-column cur)) ))
> 32
> (char-after)))))
> (insert char)))
This is great, but wouldn't it be nicer if you could give it an argument?
Then you could do, say, C-8 C-M-z and the next 8 characters would be
inserted.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-21 5:36 ` copy-word-from-line-above Greg Bognar
@ 2007-01-21 16:15 ` rgb
2007-01-22 13:02 ` copy-word-from-line-above HS
0 siblings, 1 reply; 13+ messages in thread
From: rgb @ 2007-01-21 16:15 UTC (permalink / raw)
Greg Bognar wrote:
> > I use this because its a bit more flexable. It allows you to copy exactly
> > the parts you want even if not full words.
> >
> > (global-set-key [?\C-\M-z] 'insert-prior-line-char)
> >
> > (defun insert-prior-line-char ()
> > "Insert the same character as in the prior line. Space if none."
> > (interactive)
> > (let* ((cur (current-column))
> > (char (save-excursion
> > (if (or (not (eq 0 (forward-line -1)))
> > (not (eq cur (move-to-column cur)) ))
> > 32
> > (char-after)))))
> > (insert char)))
>
> This is great, but wouldn't it be nicer if you could give it an argument?
> Then you could do, say, C-8 C-M-z and the next 8 characters would be
> inserted.
I've got my keyboard repeat rate high enough that I've not missed
that feature but it's a good idea. Maybe I'll add that Monday when
I have time to goof of at work:-)
thanks
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-21 16:15 ` copy-word-from-line-above rgb
@ 2007-01-22 13:02 ` HS
2007-01-24 12:19 ` copy-word-from-line-above rgb
0 siblings, 1 reply; 13+ messages in thread
From: HS @ 2007-01-22 13:02 UTC (permalink / raw)
Cool! Post it here as well!
Cheers everyone!
rgb escreveu:
> Greg Bognar wrote:
> > > I use this because its a bit more flexable. It allows you to copy exactly
> > > the parts you want even if not full words.
> > >
> > > (global-set-key [?\C-\M-z] 'insert-prior-line-char)
> > >
> > > (defun insert-prior-line-char ()
> > > "Insert the same character as in the prior line. Space if none."
> > > (interactive)
> > > (let* ((cur (current-column))
> > > (char (save-excursion
> > > (if (or (not (eq 0 (forward-line -1)))
> > > (not (eq cur (move-to-column cur)) ))
> > > 32
> > > (char-after)))))
> > > (insert char)))
> >
> > This is great, but wouldn't it be nicer if you could give it an argument?
> > Then you could do, say, C-8 C-M-z and the next 8 characters would be
> > inserted.
>
> I've got my keyboard repeat rate high enough that I've not missed
> that feature but it's a good idea. Maybe I'll add that Monday when
> I have time to goof of at work:-)
> thanks
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-22 13:02 ` copy-word-from-line-above HS
@ 2007-01-24 12:19 ` rgb
2007-01-24 17:34 ` copy-word-from-line-above HS
0 siblings, 1 reply; 13+ messages in thread
From: rgb @ 2007-01-24 12:19 UTC (permalink / raw)
To: help-gnu-emacs
On Jan 22, 7:02 am, "HS" <hug...@gmail.com> wrote:
> Cool! Post it here as well!
> Cheers everyone!
>
> rgb escreveu:
>
>
>
> > Greg Bognar wrote:
> > > > I use this because its a bit more flexable. It allows you to copy exactly
> > > > the parts you want even if not full words.
>
> > > > (global-set-key [?\C-\M-z] 'insert-prior-line-char)
>
> > > > (defun insert-prior-line-char ()
> > > > "Insert the same character as in the prior line. Space if none."
> > > > (interactive)
> > > > (let* ((cur (current-column))
> > > > (char (save-excursion
> > > > (if (or (not (eq 0 (forward-line -1)))
> > > > (not (eq cur (move-to-column cur)) ))
> > > > 32
> > > > (char-after)))))
> > > > (insert char)))
>
> > > This is great, but wouldn't it be nicer if you could give it an argument?
> > > Then you could do, say, C-8 C-M-z and the next 8 characters would be
> > > inserted.
>
> > I've got my keyboard repeat rate high enough that I've not missed
> > that feature but it's a good idea. Maybe I'll add that Monday when
> > I have time to goof of at work:-)
> > thanks-
Somebody must have told the boss I had goof-off time!
But I got to it this morning...
(defun insert-prior-line-char (cnt)
"Insert the same character as in the prior line. Space if none."
(interactive "p")
(while (< 0 cnt)
(setq cnt (1- cnt))
(let* ((cur (current-column))
(char (save-excursion
(if (or (not (eq 0 (forward-line -1)))
(not (eq cur (move-to-column cur)) ))
32
(char-after)))))
(insert char))))
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-24 12:19 ` copy-word-from-line-above rgb
@ 2007-01-24 17:34 ` HS
2007-01-24 20:21 ` copy-word-from-line-above Markus Triska
0 siblings, 1 reply; 13+ messages in thread
From: HS @ 2007-01-24 17:34 UTC (permalink / raw)
To: help-gnu-emacs
In practive I found out that copying chars is slower than typing, most
of the times...
Is there any kind soul here able to work out a insert-prior-line-word
from rgb's function? :)
Cheers
HS
On 24 jan, 09:19, "rgb" <rbiel...@i1.net> wrote:
> On Jan 22, 7:02 am, "HS" <hug...@gmail.com> wrote:
>
>
>
> > Cool! Post it here as well!
> > Cheers everyone!
>
> > rgb escreveu:
>
> > > Greg Bognar wrote:
> > > > > I use this because its a bit more flexable. It allows you to copy exactly
> > > > > the parts you want even if not full words.
>
> > > > > (global-set-key [?\C-\M-z] 'insert-prior-line-char)
>
> > > > > (defun insert-prior-line-char ()
> > > > > "Insert the same character as in the prior line. Space if none."
> > > > > (interactive)
> > > > > (let* ((cur (current-column))
> > > > > (char (save-excursion
> > > > > (if (or (not (eq 0 (forward-line -1)))
> > > > > (not (eq cur (move-to-column cur)) ))
> > > > > 32
> > > > > (char-after)))))
> > > > > (insert char)))
>
> > > > This is great, but wouldn't it be nicer if you could give it an argument?
> > > > Then you could do, say, C-8 C-M-z and the next 8 characters would be
> > > > inserted.
>
> > > I've got my keyboard repeat rate high enough that I've not missed
> > > that feature but it's a good idea. Maybe I'll add that Monday when
> > > I have time to goof of at work:-)
> > > thanks-Somebody must have told the boss I had goof-off time!
> But I got to it this morning...
>
> (defun insert-prior-line-char (cnt)
> "Insert the same character as in the prior line. Space if none."
> (interactive "p")
> (while (< 0 cnt)
> (setq cnt (1- cnt))
> (let* ((cur (current-column))
> (char (save-excursion
> (if (or (not (eq 0 (forward-line -1)))
> (not (eq cur (move-to-column cur)) ))
> 32
> (char-after)))))
> (insert char))))
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-24 17:34 ` copy-word-from-line-above HS
@ 2007-01-24 20:21 ` Markus Triska
2007-01-25 16:07 ` copy-word-from-line-above HS
2007-01-25 16:16 ` copy-word-from-line-above rgb
0 siblings, 2 replies; 13+ messages in thread
From: Markus Triska @ 2007-01-24 20:21 UTC (permalink / raw)
To: help-gnu-emacs
"HS" <hugows@gmail.com> writes:
> insert-prior-line-word
What about:
(defun insert-word-above ()
(interactive)
(let (word whitespace)
(save-excursion
(let ((col (current-column)))
(forward-line -1)
(move-to-column col))
(setq word (or (thing-at-point 'word)
(error "No word above")))
(forward-word)
(setq whitespace (or (thing-at-point 'whitespace) "")))
(insert word whitespace)))
(global-set-key [f2] 'insert-word-above)
All the best,
Markus Triska
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-24 20:21 ` copy-word-from-line-above Markus Triska
@ 2007-01-25 16:07 ` HS
2007-01-25 20:13 ` copy-word-from-line-above Markus Triska
2007-01-25 16:16 ` copy-word-from-line-above rgb
1 sibling, 1 reply; 13+ messages in thread
From: HS @ 2007-01-25 16:07 UTC (permalink / raw)
To: help-gnu-emacs
Hello!
Thanks Triska!
But your function would not copy symbols like '(' so I tried something,
and think I just wrote my first defun :)
Here it is:
(defun insert-word-above ()
(interactive)
(save-excursion
(let ((col (current-column)))
(forward-line -1)
(move-to-column col))
(let ((beg (point)))
(forward-word)
(copy-region-as-kill-nomark beg (point))))
(yank))
It seems to work!
Cheers,
HS
On 24 jan, 17:21, Markus Triska <markus.tri...@gmx.at> wrote:
> "HS" <hug...@gmail.com> writes:
> > insert-prior-line-wordWhat about:
>
> (defun insert-word-above ()
> (interactive)
> (let (word whitespace)
> (save-excursion
> (let ((col (current-column)))
> (forward-line -1)
> (move-to-column col))
> (setq word (or (thing-at-point 'word)
> (error "No word above")))
> (forward-word)
> (setq whitespace (or (thing-at-point 'whitespace) "")))
> (insert word whitespace)))
>
> (global-set-key [f2] 'insert-word-above)
>
> All the best,
> Markus Triska
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-24 20:21 ` copy-word-from-line-above Markus Triska
2007-01-25 16:07 ` copy-word-from-line-above HS
@ 2007-01-25 16:16 ` rgb
1 sibling, 0 replies; 13+ messages in thread
From: rgb @ 2007-01-25 16:16 UTC (permalink / raw)
To: help-gnu-emacs
> (defun insert-word-above ()
> (interactive)
> (let (word whitespace)
> (save-excursion
> (let ((col (current-column)))
> (forward-line -1)
> (move-to-column col))
> (setq word (or (thing-at-point 'word)
> (error "No word above")))
> (forward-word)
> (setq whitespace (or (thing-at-point 'whitespace) "")))
> (insert word whitespace)))
>
> (global-set-key [f2] 'insert-word-above)
This does all kinds of bizar things whenever a seperator
other than whitespace surrounds a word. So it's probably
a good thing that it doesn't accept a count argument.
It acted slightly better (for me) replacing 'word with 'symbol
and (forward-word) with (forward-symbol 1).
I suspect that the OP is running Emacs remotely
and so the repeat key rate using insert-prior-line-char
is insufficient :-(
A solution like this might work better under such
circumstances.
(defun insert-prior-line-word (cnt)
"Insert chars in prior line starting above point until whitespace.
With prefix arg, do it CNT times."
(interactive "p")
(while (< 0 cnt)
(setq cnt (1- cnt))
(let (word whitespace)
(save-excursion
(let ((col (current-column)))
(forward-line -1)
(move-to-column col))
(save-match-data
(setq word (if (looking-at "\\S-+")
(prog1 (match-string 0)
(goto-char (match-end 0))))
whitespace (and (looking-at "\\s-+")
(match-string 0)))))
(or word whitespace (error "No word above"))
(if word (insert word whitespace)
(insert whitespace)))))
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: copy-word-from-line-above
2007-01-25 16:07 ` copy-word-from-line-above HS
@ 2007-01-25 20:13 ` Markus Triska
0 siblings, 0 replies; 13+ messages in thread
From: Markus Triska @ 2007-01-25 20:13 UTC (permalink / raw)
To: help-gnu-emacs
"HS" <hugows@gmail.com> wrote:
> Hello!
> Thanks Triska!
> But your function would not copy symbols like '(' so I tried something,
> and think I just wrote my first defun :)
Cool; I changed "copy-region-as-kill-nomark" to "copy-region-as-kill"
to get it working. To preserve the kill ring, you can use:
(defun insert-word-above ()
(interactive)
(let (string beg end)
(save-excursion
(let ((col (current-column)))
(forward-line -1)
(move-to-column col))
(setq beg (point))
(forward-word)
(setq end (point)))
(insert (buffer-substring beg end))))
All the best,
Markus Triska
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2007-01-25 20:13 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-18 17:51 copy-word-from-line-above HS
2007-01-18 20:50 ` copy-word-from-line-above Marc Tfardy
2007-01-19 0:36 ` copy-word-from-line-above Nikos Apostolakis
2007-01-19 20:25 ` copy-word-from-line-above rgb
2007-01-21 5:36 ` copy-word-from-line-above Greg Bognar
2007-01-21 16:15 ` copy-word-from-line-above rgb
2007-01-22 13:02 ` copy-word-from-line-above HS
2007-01-24 12:19 ` copy-word-from-line-above rgb
2007-01-24 17:34 ` copy-word-from-line-above HS
2007-01-24 20:21 ` copy-word-from-line-above Markus Triska
2007-01-25 16:07 ` copy-word-from-line-above HS
2007-01-25 20:13 ` copy-word-from-line-above Markus Triska
2007-01-25 16:16 ` copy-word-from-line-above rgb
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).