From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Newsgroups: gmane.emacs.help Subject: Re: elisp exercise: toggle-letter-case Date: Sat, 18 Oct 2008 11:53:48 -0700 (PDT) Organization: http://groups.google.com 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1224359002 26655 80.91.229.12 (18 Oct 2008 19:43:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Oct 2008 19:43:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Oct 18 21:44:04 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 1KrHgK-0000gS-1E for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Oct 2008 21:41:48 +0200 Original-Received: from localhost ([127.0.0.1]:47117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KrHfE-0003TL-Uk for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Oct 2008 15:40:40 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!c22g2000prc.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 51 Original-NNTP-Posting-Host: 24.6.185.159 Original-X-Trace: posting.google.com 1224356028 22729 127.0.0.1 (18 Oct 2008 18:53:48 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Sat, 18 Oct 2008 18:53:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c22g2000prc.googlegroups.com; posting-host=24.6.185.159; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.22, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:163570 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:58912 Archived-At: On Oct 17, 6:06 pm, Nikolaj Schumacher wrote: > 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 Nik, your solution failed the spec! lol. It didn't work on single letter case, or words starting with number. Andreas's solution works. But he did use a state. Minor fixable problem is that it didn't consider the word/region's current state, so that sometimes pressing the key doesn't do anything until one invokes it again. The use of =E2=80=9C[[:upper]]=E2=80=9D is great, and the use of properties= to keep state (very nice touch), and the use of =E2=80=9Cinteractive=E2=80=9D with = optional args. Thanks guys. Xah =E2=88=91 http://xahlee.org/ =E2=98=84