help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copy-word-from-line-above


From: rgb
Subject: Re: copy-word-from-line-above
Date: 25 Jan 2007 08:16:16 -0800
User-agent: G2/1.0

> (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)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]