[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with upcasing words first char
From: |
Pascal J. Bourguignon |
Subject: |
Re: Help with upcasing words first char |
Date: |
Sat, 22 Aug 2009 22:12:03 +0200 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) |
Harry Putnam <reader@newsguy.com> 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-<right arrow> | Ctrl-d | ctrl-d | shift <type char>
It's simplier if you write it in the emacs standard notation:
C-M-f C-d C-d S-<char>
> Using upcase-region
> ctrl-<right arrow | ctrl-d | ctrl-spc | right arrow | upcase-region
or:
C-M-f C-d C-SPC C-f M-x upcase-region RET
> 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__
- Help with upcasing words first char, Harry Putnam, 2009/08/22
- Message not available
- Re: Help with upcasing words first char,
Pascal J. Bourguignon <=
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/24
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/24
- Message not available
- Re: Help with upcasing words first char, Pascal J. Bourguignon, 2009/08/24
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/24
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/24
- Message not available
- Re: Help with upcasing words first char, Pascal J. Bourguignon, 2009/08/24
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/25
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/25
- Message not available
- Re: Help with upcasing words first char, Pascal J. Bourguignon, 2009/08/25
- Re: Help with upcasing words first char, Harry Putnam, 2009/08/29