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: Sat, 22 Aug 2009 22:12:03 +0200 Organization: Informatimago Message-ID: <87fxbjwquk.fsf@galatea.local> References: <87ab1ru9zt.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 1250973651 8566 80.91.229.12 (22 Aug 2009 20:40:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 22 Aug 2009 20:40:51 +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 Aug 22 22:40:44 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 1MexOD-0006Td-0J for geh-help-gnu-emacs@m.gmane.org; Sat, 22 Aug 2009 22:40:41 +0200 Original-Received: from localhost ([127.0.0.1]:54462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MexOB-0002SI-Cn for geh-help-gnu-emacs@m.gmane.org; Sat, 22 Aug 2009 16:40:39 -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: 101 Original-X-Trace: individual.net BCg513+TfPmzSGkiYORmEwwGv+SyEgJXemGxnFwnYZcDh9rWQL Cancel-Lock: sha1:YjFiZTU2YzZkYjIxMWIwNjA5YWQzZDNiYjQxMWU1YzBhNDU2NjAwYQ== sha1:AfoX2diH4mg3jQQmwdOfqQwi62c= 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:172278 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:67428 Archived-At: Harry Putnam writes: > I realize that upcase-region can do the above but its actually more > cumbersome that what I described above and appears to need more > keystrokes too > > create region/call upcase region > > Maybe its the same number of strokes but more inconvenient in that it > breaks the movements up in a different way than > > My current method: > ctrl- | Ctrl-d | ctrl-d | shift It's simplier if you write it in the emacs standard notation: C-M-f C-d C-d S- > Using upcase-region > ctrl- It even looks more awkward in writting. > > But really, either of those above seems too time consuming when I have > hundreds of edits to make in that manner. When working becomes too hard, you must start programming. Let the computer do the work for you! > Any suggestions about how to automate or reduce time on these edits? > > > Once more... the edit: > > Some words similar to this > > I need to remove the space and upcase the next Char. > > SomeWordsSimilarToThis First you must do the transformation in a order that makes it easy for a computer to do. You are asking to first remove the spaces thus getting: Somewordssimilartothis and then cutting words. But removing spaces removed information, and now you need strong artificial intelligence to recover the information. So me word ss i milar tot his ; Oops! Next, you're asking too a low level operation. Upcasing the first letter of a word is abstracted into a capitalizing operation. Select the whole sentence: Some Words Similar To This with C-a C-SPC C-e and use M-x capitalize-region RET command. Then select it again, and remove spaces: C-SPC C-a M-x replace-string RET SPC RET RET Now you are ready to write an emacs lisp command doing the same: (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 "\\s-+" end t) (delete-region (match-beginning 0) (match-end 0)))) (set-marker m nil)))) Type: C-x C-e after the previous expression to have it taken into account immediately. Put it in your ~/.emacs file to get it loaded next time you start emacs. And then you can select a region such as the sentence: Some words similar to this and type M-x camelize-region RET to get: SomeWordsSimilarToThis -- __Pascal Bourguignon__