Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why is this function not instantaneous?

7 views
Skip to first unread message

B. T. Raven

unread,
Mar 19, 2013, 4:04:35 PM3/19/13
to
A few months ago I somehow misplaced the original of this function:


(defun copy-to-other-window (beg end) ;; bind to f8
"Copy region text to buffer in other window\n"
(interactive "r")
(if (not (use-region-p))
(progn
(backward-word)
(let ((beg (point))) (forward-word) (copy-region-as-kill \
beg (point)))
))
(other-window 1)
(yank)
)

The earlier version worked with no extraneous disk activity going on.
This version bogs down for 2, 3, or 4 seconds while showing the Windows
7 whirly disk. If transient mark mode is inactive, the "if" form makes a
region out of the word where the cursor is at or inside of. Does any of
you know what this little function would look like if I knew what I were
doing?

Thanks,

Ed

Eric Abrahamsen

unread,
Mar 19, 2013, 9:30:59 PM3/19/13
to help-gn...@gnu.org
"B. T. Raven" <btr...@nihilo.net> writes:

> A few months ago I somehow misplaced the original of this function:
>
>
> (defun copy-to-other-window (beg end) ;; bind to f8
> "Copy region text to buffer in other window\n"
> (interactive "r")
> (if (not (use-region-p))
> (progn
> (backward-word)
> (let ((beg (point))) (forward-word) (copy-region-as-kill \
> beg (point)))
> ))
> (other-window 1)
> (yank)
> )

I have no idea why that would bog down your machine, but here's my
equivalent version of the same thing -- see if this works? Your use of
`other-window' might be better than my `next-window', which could
potentially yank into a non-visible window.

(defun my-yank-to-other-window (p m)
"Yank region to point of other window."
(interactive "r")
(let ((s (if (use-region-p)
(buffer-substring-no-properties p m)
(current-word))))
(select-window (next-window))
(insert s)))


HTH,
Eric


B. T. Raven

unread,
Mar 21, 2013, 3:38:37 PM3/21/13
to
Eric wrote:

> (defun my-yank-to-other-window (p m)
> "Yank region to point of other window."
> (interactive "r")
> (let ((s (if (use-region-p)
> (buffer-substring-no-properties p m)
> (current-word))))
> (select-window (next-window))
> (insert s)))

Thanks, Eric. That works without delay. Since I use this only (almost
only) to transfer text between a dictionary and an rcirc window, I will
use this hybrid of my and your functions:

(defun tow (p m) ;; bind to F8
"Copy region text or word to buffer in other window\n"
(interactive "r")
(let ((s (if (use-region-p)
(buffer-substring-no-properties p m)
(current-word nil t))))
(other-window 1)
(insert s)))

I don't really understand the "strict" and "reallyword" optional
arguments to 'current-word but using nil and t for them doesn't cause a
hang-up like my 'copy-region-as-kill function did. (could it be coercing
garbage collection?) In fact, 'current-word was a new function to me.
Thanks for that.

Btw, my pathological naming 'tow is just so I can used M-x tow in case I
want to assign something else to f8.

Ed

Eric Abrahamsen

unread,
Mar 22, 2013, 2:08:16 AM3/22/13
to help-gn...@gnu.org
"B. T. Raven" <btr...@nihilo.net> writes:

It really beats me why yours was slow, but at least it's solved! The
STRICT arg to current-word, if nil, lets you slurp in the nearest word
(even if it's many spaces distant). If REALLYWORD is nil, it adds a few
less "wordy" characters (those matching the "_" syntax) to what it will
consider a word. I agree the docstring is unhelpful, though. Anyway,
neither of those would cause a hangup, so that's still a mystery...

E


0 new messages