help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: elisp exercise: toggle-letter-case


From: Nikolaj Schumacher
Subject: Re: elisp exercise: toggle-letter-case
Date: Sat, 18 Oct 2008 03:06:08 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin)

Andreas Politz <politza@fh-trier.de> wrote:

> Giving the command a state makes it so much easier, because you
> don't have to look at the text at all.

I think looking at the text is actually less work.  It's only three
lines of code.


(defun toggle-region-case (&optional beg end)
  (interactive (and transient-mark-mode mark-active
                    (list (region-beginning)
                          (region-end))))
  (let ((pt (point))
        case-fold-search
        deactivate-mark)
    (if beg
        (goto-char beg)
      (forward-word)
      (setq end (point))
      (backward-word))
    (cond
     ((looking-at "[[:upper:]][[:upper:]]") (downcase-region (point) end))
     ((looking-at "[[:upper:]]") (upcase-region (point) end))
     (t (upcase-initials-region (point) end)))
    (goto-char pt)))



regards,
Nikolaj Schumacher




reply via email to

[Prev in Thread] Current Thread [Next in Thread]