On Wed, Jan 30, 2008 at 6:22 PM, dackz <[EMAIL PROTECTED]> wrote:

> And I'll definitely think about contributing some code to change the
> word behavior, and I'll be sure to study previous implementations,
> since I'm sure it's a touchy matter.


The behavior that I always favored for word removal was 'all
variable-legal-characters and spaces', then 'all
non-variable-legal-characters and spaces', and you alternate.

For example given this string:

foo --bar "baz biff" --long_option
foo --bar "baz biff" --
foo --bar "baz biff"
foo --bar "baz biff
foo --bar "baz
foo --bar "
foo --bar
foo --
foo

It's more keypresses than methods that jump from space to space, but it also
doesn't remove so much that it's useless when trying to delete through regex
or code that has no spaces in it. It's also relatively simple... when
deleting a word, it checks the character to the left of the cursor, and
performs one of three matches (and, I'm sure the pseudocode could be
better... my linux box is dead at the moment, so I'm not testing the regex):

if $character ~= /[ \t\n]/
  s/[ \t\n]*$//s
elseif $character ~= /[a-zA-Z0-9_]/
  s/[ \t]*[a-zA-Z0-9_]+$//
else
  s/[ \t]*[^a-zA-Z0-9_ \t\n]$/
end

Notable items:
* Whitespace at the end is removed greedily. The cursor should always be
next to non-whitespace after a word removal. In the examples below, the
dollar sign indicates the end of the line (it's not really there):
AAA BBB     CCC$
AAA BBB$
AAA$

* Whitespace is a primary separator, so punctuation with spaces in it will
be removed chunk by chunk.
-- ^^ --$
-- ^^$
--$

* Intermixed punctuation and words count as separate tokens for removal.
aaa/bb bb/ccc$
aaa/bb bb/$
aaa/bb bb$
aaa/bb$
aaa/$
aaa$

* If the cursor starts next to whitespace, it only removes whitespace.
aaa      $
aaa$

* When deleting through a multi-line string, it will always stop at the
beginning of a line, then delete through it. In the following example, the
backslash only indicates a newline character, it is not actually part of the
example string.
aaa   \
bbb   \
   ccc$

aaa   \
bbb   \
$

aaa   \
bbb$

aaa   \
$

aaa$

These features make the function more general... it breaks at almost every
spot you would want it to, depending on the situation. But it also makes it
slower... more keypresses to remove the same amount of content. But I think
the mix of simplicity of implementation (only 3 states, simple test for
state depending on character to left of cursor) and generality make it
better than the current implementation.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to