unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* why is this function not instantaneous?
@ 2013-03-19 20:04 B. T. Raven
  2013-03-20  1:30 ` Eric Abrahamsen
       [not found] ` <mailman.22508.1363742738.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: B. T. Raven @ 2013-03-19 20:04 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: why is this function not instantaneous?
  2013-03-19 20:04 why is this function not instantaneous? B. T. Raven
@ 2013-03-20  1:30 ` Eric Abrahamsen
       [not found] ` <mailman.22508.1363742738.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2013-03-20  1:30 UTC (permalink / raw)
  To: help-gnu-emacs

"B. T. Raven" <btraven@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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: why is this function not instantaneous?
       [not found] ` <mailman.22508.1363742738.855.help-gnu-emacs@gnu.org>
@ 2013-03-21 19:38   ` B. T. Raven
  2013-03-22  6:08     ` Eric Abrahamsen
  0 siblings, 1 reply; 4+ messages in thread
From: B. T. Raven @ 2013-03-21 19:38 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: why is this function not instantaneous?
  2013-03-21 19:38   ` B. T. Raven
@ 2013-03-22  6:08     ` Eric Abrahamsen
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2013-03-22  6:08 UTC (permalink / raw)
  To: help-gnu-emacs

"B. T. Raven" <btraven@nihilo.net> writes:

> 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.

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-03-22  6:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-19 20:04 why is this function not instantaneous? B. T. Raven
2013-03-20  1:30 ` Eric Abrahamsen
     [not found] ` <mailman.22508.1363742738.855.help-gnu-emacs@gnu.org>
2013-03-21 19:38   ` B. T. Raven
2013-03-22  6:08     ` Eric Abrahamsen

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