From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Help with upcasing words first char Date: Tue, 25 Aug 2009 23:02:47 +0200 Organization: Informatimago Message-ID: <87bpm3vc7c.fsf@galatea.local> References: <87ab1ru9zt.fsf@newsguy.com> <87fxbjwquk.fsf@galatea.local> <7cpralutkh.fsf@pbourguignon.anevia.com> <874orwsu8s.fsf@newsguy.com> <87iqgcvkg7.fsf@galatea.local> <87ab1n52ma.fsf@newsguy.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1251236453 19680 80.91.229.12 (25 Aug 2009 21:40:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Aug 2009 21:40:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Aug 25 23:40:46 2009 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 1Mg3kw-0000oj-U1 for geh-help-gnu-emacs@m.gmane.org; Tue, 25 Aug 2009 23:40:44 +0200 Original-Received: from localhost ([127.0.0.1]:45751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mg3kw-0001O4-9w for geh-help-gnu-emacs@m.gmane.org; Tue, 25 Aug 2009 17:40:42 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 85 Original-X-Trace: individual.net TG5UUG1/zUiKhDB4V8k/5gFTwlD+3XdtlyoOQWLqCEFF1bISEa Cancel-Lock: sha1:ZjQ5MDY4NTFmZWE2ZDE0NjY4MmZjYjdhYWJhMDFiM2Q5Mjk2YzUwNg== sha1:na0JPvCQ8pA1535lNUnGMsgyuBo= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:172387 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:67530 Archived-At: Harry Putnam writes: > If I might try your patience even further.. I wondered if you might > take time to explain what controls where the cursor ends up... in the > code you proposed earlier. (A slightly changed version is included at > the end) Good question! :-) > What I see looks like this (Upcase X is where cursor ends up): > > some more xrays > > SomeMoreXrays > - > Is it this bit where that happens? > (delete-region (match-beginning 0) (match-end 0)))) > (set-marker end nil)))) No. This is about the only expression that doesn't move the cursor (other than leaving it at the start of the deleted region if it was inside). > Can something be altered in there to make the cursor land at the end > of the line? > > SomeMoreXrays[here] Yes, indeed. > Or is it done where `m' is assigned the value it holds? No. The marker is used to keep track of the end position of the region, since we are changing the length of that region by deleting parts. > It appears to my untrained eye that `m' is told to hold the position of > the end of the effected text... Yes, that's correct, and we will use it to position the cursor there, adding a (goto-char end) before resetting the marker with (set-marker end nil). > which would be the last place a space > or tab was removed... (I guess.) Not exactly. The two expressions that move the cursor are (goto-char start) that puts it at the beginning of the region, and (re-search-forward ...) that moves it to the start of the matching string (ie. the position of (match-beginning 0)). Deleting the region will leave it at this position, and when there is no more any space till the end, it will stay here. Hence why it was left at the beginning of the last word. If you selected trailling spaces in the region, it would move here. > Anyway... how would I go about making this useful function place the > cursor where I want it (at the end of the effected text (including > what ever string of text is past the last affected area [spc/\t] where > action is taken? Using goto-char, you can position the cursor at the position you want: (defun camelize-region (start end) (interactive "r") (capitalize-region start end) (let ((end (let ((m (make-marker))) (set-marker m end) m))) (unwind-protect (progn (goto-char start) (while (re-search-forward "[ \t]+" end t) (delete-region (match-beginning 0) (match-end 0)))) (goto-char end) (set-marker end nil)))) -- __Pascal Bourguignon__