unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to convert the case for a single letter
Date: Thu, 20 Nov 2008 03:48:25 -0800 (PST)	[thread overview]
Message-ID: <053692d0-73de-483a-993b-cf8a971d5d5e@s9g2000prg.googlegroups.com> (raw)
In-Reply-To: mailman.824.1227178431.26697.help-gnu-emacs@gnu.org

On Nov 20, 2:58 am, "Anand S. Dhankshirur" <a...@cdotb.ernet.in>
wrote:
> Hi,
> How do i convert the case of the letter (in the word) from lower to
> upper or vice versa.
> I know M-L and M-U do that for the word.

you might be interested in this function:

(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"))
   )
)
)

You can assign it a keyboard shortcut so you can reduce the need for
Alt+u, Alt+l, Alt+c, Ctrl+x Ctrl+u, Ctrl+x Ctrl+l to just one.

For detail, see:

• Usability Problems With Emacs's Letter-Case Commands
http://xahlee.org/emacs/modernization_upcase-word.html

  Xah
∑ http://xahlee.org/

       reply	other threads:[~2008-11-20 11:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.824.1227178431.26697.help-gnu-emacs@gnu.org>
2008-11-20 11:48 ` Xah [this message]
2008-11-20 23:50 ` How to convert the case for a single letter Joe Casadonte
2008-11-21 11:12 ` Niels Giesen
2008-11-21 12:53   ` Peter Dyballa
     [not found]   ` <mailman.932.1227272034.26697.help-gnu-emacs@gnu.org>
2008-11-21 14:29     ` Niels Giesen
2008-11-21 15:08       ` Peter Dyballa
2008-11-20 10:58 Anand S. Dhankshirur
2008-11-20 11:10 ` Peter Dyballa
2008-11-20 11:29   ` Anand S. Dhankshirur
2008-11-22 19:32 ` Rancier, Jeffrey

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=053692d0-73de-483a-993b-cf8a971d5d5e@s9g2000prg.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).