From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: elisp exercise: toggle-letter-case Date: Sat, 18 Oct 2008 03:06:08 +0200 Message-ID: References: <420ba543-19ba-4987-9f3a-a57878777c9d@n33g2000pri.googlegroups.com> <1224286525.260548@arno.fh-trier.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1224291997 27444 80.91.229.12 (18 Oct 2008 01:06:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Oct 2008 01:06:37 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Andreas Politz Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Oct 18 03:07:38 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kr0I5-0008KF-9c for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Oct 2008 03:07:37 +0200 Original-Received: from localhost ([127.0.0.1]:45291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kr0H0-0007Ot-Go for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Oct 2008 21:06:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kr0Gh-0007N6-Lv for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 21:06:11 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kr0Gh-0007MZ-2E for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 21:06:11 -0400 Original-Received: from [199.232.76.173] (port=36357 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kr0Gg-0007MS-VV for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 21:06:11 -0400 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:53861) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kr0Gg-0004Ro-Io for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 21:06:10 -0400 Original-Received: from thursday (BAH5d9e.bah.pppool.de [77.135.93.158]) by dd18200.kasserver.com (Postfix) with ESMTP id 7D72C1802F48B; Sat, 18 Oct 2008 03:06:09 +0200 (CEST) In-Reply-To: <1224286525.260548@arno.fh-trier.de> (Andreas Politz's message of "Sat\, 18 Oct 2008 01\:29\:36 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58889 Archived-At: Andreas Politz 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