[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: kill-region and white space
From: |
Kevin Rodgers |
Subject: |
Re: kill-region and white space |
Date: |
Wed, 01 Sep 2004 10:16:49 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 |
kgold wrote:
> Kevin Rodgers <ihs_4664@yahoo.com> writes:
>>kgold wrote:
>> > (defadvice kill-word (after delete-horizontal-space activate)
>> > "Delete trailing whitespace as well."
>> > (if (looking-at "\\s ")
>> > (just-one-space)))
>>
>>Why not advise kill-region similarly, since that's what you've bound
>>mouse-3 to?
>
> Here's what I tried. They both kill correctly, but the yank does not
> yank the whitespace. I think I need the mouse-1 double click to
> select the word and the whitespace after it.
>
> (defadvice kill-region (after delete-horizontal-space activate)
> "Delete trailing whitespace as well."
> (if (looking-at "\\s ")
> (just-one-space)))
>
> That is, I think the problem and solution involve the select, not the
> kill.
OK, get rid of both command advices -- a word does not include
trailing whitespace, and altering the text at the region boundary
could adversely affect other calls to kill-region. Instead, there are
2 utility functions that try be intelligent about what the user is
selecting depending on where the mouse clicks occur: mouse-start-end
and mouse-skip-word. So I think you could advise mouse-skip-word like
this:
(defadvice mouse-skip-word (after trailing-whitespace activate)
"Skip trailing whitespace at a word boundary when going forward."
(if (and (> (ad-get-arg 0) 0) (looking-at "\\>"))
(skip-syntax-forward " ")))
--
Kevin Rodgers