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

Re: Accidently wrote a command in CAPS LOCK



zzapper wrote:
> 
> Accidently wrote a command in CAPS LOCK
> 
> FTX SUCC BOOK
> 
> What's the best way to lowercase this?

Well, going to the start and using down-case-word (ESC l in Emacs mode)
until you get to the end is the obvious way.

But it's not hard (after you've worked out the offsets, anyway) to write
a widget that transforms the region---I hadn't realised there wasn't
one:

  down-case-region() {
    emulate -L zsh
    integer p1 p2

    if (( CURSOR < MARK )); then
      (( p1=CURSOR+1, p2=MARK ))
    else
      (( p1=MARK+1, p2=CURSOR ))
    fi
    BUFFER[p1,p2]=${(L)BUFFER[p1,p2]}
  }
  zle -N down-case-region

Unfortunately ${(L)...} and parameter indexing don't handle multibyte
characters yet, so down-case-word, which is implemented internally,
should be safer.  You could use some kind of hybrid.

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


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



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