all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Problems with the capitalization in Word Abbreviation Mode
Date: Mon, 6 Oct 2008 21:06:14 -0700 (PDT)	[thread overview]
Message-ID: <a1ef1496-d9ca-43b0-bcf2-e1ee24d75713@z11g2000prl.googlegroups.com> (raw)
In-Reply-To: e5b03fff-e9cb-4f50-8772-4d876bc8bd4c@k13g2000hse.googlegroups.com

another way to fix letter-case typo problem is to use one of emacs
commands to change letter case.

There are capitalize-word, downcase-word, upcase-word. Type C-h
‹function-name› to see their default keybindings.

There are also several varieties:
(upcase obj)
(upcase-word 3)
(upcase-region beg end)
(upcase-initials obj)
(upcase-initials-region beg end)
(capitalize obj)
(capitalize-word n)
(capitalize-region myStartPos myEndPos)
(downcase)
(downcase-word arg)
(downcase-region beg end)

One problem with them is that you need to move your cursor to the
beginning of the word first. For example, if your cursor is on the “A”
In “THat”, And You Call downcase-word, but it doesn't do anything
because it only start at the cursor point to end of word.

It would be nice if it'll just automatically perform the operation on
the whole word as a region.

Another problem is that it only performs one specific operation as
opposed to considering the final result. For example, if you have
“oncE upon a time ...”, and you select the whole sentence and call
upcase-initials-region, it becomes “OncE Upon A Time ...”, but the
capital E is not automatically lowered.

Also, most of these commands have a “-word” and “-region” version...
great for precision in elisp programing but not smart as user
commands. It would be nice if a region is active, then automatically
do the command on the region, else the current word. (emacs is this
way because technically, a “region” always exists. The modern concept
of text selection (with highlighting) didn't come to emacs until it
had transient-mark-mode, along with the complexity of “mark-active”.
Things would be much simpler if emacs adopted transient-mark-mode by
default.)

I've combined these into one function and i think fixed the above
usability issues:

(defun toggle-letter-case ()
  "Toggle the current word or region's letter case.
Toggles from 3 cases: upper case, lower case, title case,
in that order.
Title case means upcase first letter of each word."
(interactive)

(save-excursion
(let (pt pos1 pos2 cap1p cap2p (deactivate-mark nil) (case-fold-search
nil))
  (setq pt (point))
  (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))))

  (goto-char pos1)
  (setq cap1p (looking-at "[A-Z]"))
  (goto-char (1+ pos1))
  (setq cap2p (looking-at "[A-Z]"))

  (cond
   ((and (not cap1p) (not cap2p)) (upcase-initials-region pos1 pos2))
   ((and cap1p (not cap2p)) (upcase-region pos1 pos2) )
   ((and cap1p cap2p) (downcase-region pos1 pos2) )
   (t (downcase-region pos1 pos2) )
   )
  )
)
)

and recently assigned it a single shortcut. See
http://xahlee.org/emacs/ergonomic_emacs_keybinding.html

  Xah
∑ http://xahlee.org/

  parent reply	other threads:[~2008-10-07  4:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-06  8:12 Problems with the capitalization in Word Abbreviation Mode Hans-Christian Mick
2008-10-06 13:12 ` Andreas Politz
2008-10-06 14:31   ` Hans-Christian Mick
2008-10-06 16:53     ` Andreas Politz
2008-10-07  4:06 ` Xah [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-10-06 16:06 martin rudalics
     [not found] <mailman.381.1223309323.25473.help-gnu-emacs@gnu.org>
2008-10-07 18:35 ` Xah

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=a1ef1496-d9ca-43b0-bcf2-e1ee24d75713@z11g2000prl.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.
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.