all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah Lee <xahlee@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs-Devel devel <emacs-devel@gnu.org>,
	Deniz Dogan <deniz.a.m.dogan@gmail.com>
Subject: Re: capitalize-dwim (was: Patch to change just-one-space)
Date: Fri, 14 Aug 2009 08:36:00 -0700	[thread overview]
Message-ID: <aa6b5cbe0908140836o550f39a8oeafe43fcc752bfd9@mail.gmail.com> (raw)
In-Reply-To: <jwvmy62zaif.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2320 bytes --]

On Fri, Aug 14, 2009 at 8:26 AM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:

> >> case changing. Some work on word, some on region... with
> >> transient-mark-mode on now, the region versions could be merged.
>
> It's worth a try, indeed.
>
> >> The lower case and upper case and cap first versions can also be
> >> merged, i think, into one dwim version that just cycles.
>
> I doubt this would work: I very often use M-u, or M-c repeatedly to
> apply the change to a bunch of words: assuming the first word is
> all-lowercase, what should your new command do on the second invocation:
> apply the same change to the second word or cycle the capitalization
> style on the first word?


the code i've been using cycle the case of the first letter, on current
word, or region if there's one.

here's the code i've been using for about 2 years.
Andreas Politz and Nikolaj Schumacher had helped in the code.

(defun toggle-letter-case ()
  "Toggle the letter case of current word or text selection.
Toggles from 3 cases: UPPER CASE, lower case, Title Case,
in that cyclic order."
(interactive)
(let (pos1 pos2 (deactivate-mark nil) (case-fold-search nil))
  (if (and transient-mark-mode mark-active)
      (setq pos1 (region-beginning)
            pos2 (region-end))
    (setq pos1 (car (bounds-of-thing-at-point 'word))
          pos2 (cdr (bounds-of-thing-at-point 'word))))

  (when (not (eq last-command this-command))
    (save-excursion
      (goto-char pos1)
      (cond
       ((looking-at "[[:lower:]][[:lower:]]") (put this-command 'state "all
lower"))
       ((looking-at "[[:upper:]][[:upper:]]") (put this-command 'state "all
caps") )
       ((looking-at "[[:upper:]][[:lower:]]") (put this-command 'state "init
caps") )
       (t (put this-command 'state "all lower") )
       )
      )
    )

  (cond
   ((string= "all lower" (get this-command 'state))
    (upcase-initials-region pos1 pos2) (put this-command 'state "init
caps"))
   ((string= "init caps" (get this-command 'state))
    (upcase-region pos1 pos2) (put this-command 'state "all caps"))
   ((string= "all caps" (get this-command 'state))
    (downcase-region pos1 pos2) (put this-command 'state "all lower"))
   )
)
)

some logic on why i find this useful i wrote about here:
  http://xahlee.org/emacs/modernization_upcase-word.html

 Xah

[-- Attachment #2: Type: text/html, Size: 3555 bytes --]

  reply	other threads:[~2009-08-14 15:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-13 20:37 Patch to change just-one-space Deniz Dogan
2009-08-13 23:12 ` Xah Lee
2009-08-13 23:30   ` Deniz Dogan
2009-08-13 23:35     ` Daniel Colascione
2009-08-13 23:37       ` Deniz Dogan
2009-08-14  0:51         ` Robert J. Chassell
2009-08-14  0:58           ` Deniz Dogan
2009-08-14 10:37           ` Teemu Likonen
2009-12-31 20:55       ` Deniz Dogan
2010-11-22 20:35         ` Deniz Dogan
2010-11-22 22:16         ` Stefan Monnier
2010-11-23  8:29           ` Tassilo Horn
2010-12-06 18:22             ` Stefan Monnier
2010-12-07  0:34               ` Chong Yidong
2010-12-07  9:43               ` Tassilo Horn
2010-12-07 19:45                 ` Tassilo Horn
2010-12-09  3:57                   ` Stefan Monnier
2009-08-14  2:24     ` Xah Lee
2009-08-14  6:53       ` Deniz Dogan
2009-08-14 15:26         ` capitalize-dwim (was: Patch to change just-one-space) Stefan Monnier
2009-08-14 15:36           ` Xah Lee [this message]
2009-08-14 16:33             ` capitalize-dwim joakim
2009-08-15  2:31               ` capitalize-dwim Richard Stallman
2009-08-14  8:05       ` Patch to change just-one-space David Kastrup
2009-08-13 23:19 ` Juri Linkov
2009-08-13 23:33   ` Deniz Dogan
2009-08-14  2:10     ` Stephen J. Turnbull
2009-08-14  6:59       ` Deniz Dogan
2009-08-14 12:19         ` Andreas Roehler
2009-08-14 17:10         ` Stephen J. Turnbull
2009-08-14 15:12       ` Stefan Monnier
2009-08-14 15:16         ` Lennart Borgman
2009-08-14  1:14 ` Miles Bader

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa6b5cbe0908140836o550f39a8oeafe43fcc752bfd9@mail.gmail.com \
    --to=xahlee@gmail.com \
    --cc=deniz.a.m.dogan@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.