Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Camel case word navigation?



dackz wrote:
> Does anyone know of a simple way to make zsh match camel case words?
> I.e., where fooBar^W would become foo (like c-subword-mode in GNU
> Emacs).
> 
> So far all I can think of is that maybe I could do it by customizing
> match-words-by-style and using select-word-style, but I'm not quite
> sure where to start with that.

There are two problems: first you still need normal word breaks to be
applied, and second the word boundary isn't in quite the same place as
the code normally assumes, i.e. the character in question is itself the
start of the word, not a non-word character.  I think you'd therefore
need to extend the current handling by keeping the current case
statement (adding some "*"s around names so you could add "-camel" at
the end of word-style) and adding a new test to see if there are upper
case characters followed by lower case characters within the word
matched below the case statement.  I don't see a fundamental problem
with that but it might be fiddly to get right.

You can actually get a certain fraction of the behaviour you want with
the following styles (assuming you have used select-word-style to load
the appropriate functions):

zstyle ':zle:*' word-style specified
zstyle ':zle:*' word-chars "${WORDCHARS}abcdefghijklmnopqrstuvwxyz"

which stops upper case letters from being word characters.  However, the
cursor won't be quite where you want it.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author