* Help with upcasing words first char
@ 2009-08-22 15:46 Harry Putnam
2009-08-22 18:40 ` Harry Putnam
[not found] ` <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-22 15:46 UTC (permalink / raw)
To: help-gnu-emacs
I need to do a pile of editing that involves:
Removing a space between words and upcasing the first letter of the
next word like:
Some example
to
SomeExample
I went thru M-x apropos <RET> <case> <RET>
But didn't find a likely candidate ... or at least none appeared to be
the right thing for what I want.
So far I've been
Ctrl <right arrow> To get to the space between words
Ctrl-d Ctrl-d To remove the space and the leading lowercase char of
the next word
Shift <Char> to replace with uppercase
Then back to Ctrl <right arrow>
Where can I save some keyboard strokes?
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-22 15:46 Help with upcasing words first char Harry Putnam
@ 2009-08-22 18:40 ` Harry Putnam
2009-08-24 13:01 ` Harry Putnam
[not found] ` <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 20+ messages in thread
From: Harry Putnam @ 2009-08-22 18:40 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam <reader@newsguy.com> writes:
> I need to do a pile of editing that involves:
>
> Removing a space between words and upcasing the first letter of the
> next word like:
>
> Some example
> to
> SomeExample
>
> I went thru M-x apropos <RET> <case> <RET>
>
> But didn't find a likely candidate ... or at least none appeared to be
> the right thing for what I want.
>
> So far I've been
>
> Ctrl <right arrow> To get to the space between words
> Ctrl-d Ctrl-d To remove the space and the leading lowercase char of
> the next word
>
> Shift <Char> to replace with uppercase
>
> Then back to Ctrl <right arrow>
>
> Where can I save some keyboard strokes?
Just to add a bit here...
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>
Using upcase-region
ctrl-<right arrow | ctrl-d | ctrl-spc | right arrow | upcase-region
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.
Incidentally ... it appears `Ctrl-<arrow key>' keystrokes to move
to next space between words, is only available on windows UI. At
least I don't see it on my linux OS.
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
^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>]
* Re: Help with upcasing words first char
[not found] ` <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>
@ 2009-08-22 19:02 ` A.Politz
2009-08-22 19:32 ` Joost Kremers
2009-08-22 21:29 ` John A Pershing Jr
2009-08-22 20:12 ` Pascal J. Bourguignon
2009-08-23 18:14 ` B. T. Raven
2 siblings, 2 replies; 20+ messages in thread
From: A.Politz @ 2009-08-22 19:02 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 22, 8:40 pm, Harry Putnam
> 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
I always wished emacs had some kind of interpreted, builtin language
for such cumbersome tasks. Or at least some support for basic
keyboard
macros.
Well, whay do you do.
-ap
-ap
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-22 19:02 ` A.Politz
@ 2009-08-22 19:32 ` Joost Kremers
2009-08-22 21:29 ` John A Pershing Jr
1 sibling, 0 replies; 20+ messages in thread
From: Joost Kremers @ 2009-08-22 19:32 UTC (permalink / raw)
To: help-gnu-emacs
A.Politz wrote:
> On Aug 22, 8:40 pm, Harry Putnam
>> I need to remove the space and upcase the next Char.
>>
>> SomeWordsSimilarToThis
>
> I always wished emacs had some kind of interpreted, builtin language
> for such cumbersome tasks. Or at least some support for basic
> keyboard macros.
> Well, whay do you do.
i hear vi has some sort of scripting language, maybe you can use that?
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-22 19:02 ` A.Politz
2009-08-22 19:32 ` Joost Kremers
@ 2009-08-22 21:29 ` John A Pershing Jr
1 sibling, 0 replies; 20+ messages in thread
From: John A Pershing Jr @ 2009-08-22 21:29 UTC (permalink / raw)
To: help-gnu-emacs
"A.Politz" <politza@googlemail.com> writes:
> I always wished emacs had some kind of interpreted, builtin language
> for such cumbersome tasks. Or at least some support for basic keyboard
> macros. Well, whay do you do.
I assume you are being sarcastic here...
If not... Of course, Emacs has a builtin language for such tasks. It
also has keyboard macros, which is what I would probably use for this
task:
C-x ( M-f M-\ M-c C-x )
{Start macro, forward word, delete space, capitalize word, end macro}
followed by: C-x e
to (re-)execute the macro.
You can even save a keyboard macro into a file and reload it later, or
edit the saved macro (carefully!). I have a gigantic keyboard macro
(for processing a particular LISTSERV digest) which grew from humble
origins to its current size. In this case, it's much easier to keep it
as a keyboard macro rather than transliterating it into elisp.
-jp
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
[not found] ` <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>
2009-08-22 19:02 ` A.Politz
@ 2009-08-22 20:12 ` Pascal J. Bourguignon
2009-08-24 13:08 ` Harry Putnam
` (2 more replies)
2009-08-23 18:14 ` B. T. Raven
2 siblings, 3 replies; 20+ messages in thread
From: Pascal J. Bourguignon @ 2009-08-22 20:12 UTC (permalink / raw)
To: help-gnu-emacs
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__
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-22 20:12 ` Pascal J. Bourguignon
@ 2009-08-24 13:08 ` Harry Putnam
2009-08-24 13:59 ` Harry Putnam
[not found] ` <mailman.5250.1251122398.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-24 13:08 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> 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
Thank you for such a clear and helpful response. Just the ticket.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-22 20:12 ` Pascal J. Bourguignon
2009-08-24 13:08 ` Harry Putnam
@ 2009-08-24 13:59 ` Harry Putnam
[not found] ` <mailman.5250.1251122398.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-24 13:59 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> 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))))
That works nicely but does throw an error when it finishes. My
non-existent lisp skills were not able to determine what is causing
it.
(From *Messages* Buffer)
Mark set
unwind-protect: Symbol's value as variable is void: m
Mark set
Also I tried it on a larger region consisting of several lines and
again it worked but in that case also removed the newlines.
I don't really understand what the regex you used (\s-+) means. I
understand `\s' to mean any single occurrence of any whitespace.
And also understand the `+' operator to mean `at least one plus any
number of matches to preceding regex. But again ... not sure what the
`-' operator does.
But I wondered if that `\s' could be changed to something a little more
exclusive.... like maybe tabs and spaces only.. and if that would
allow the function to work on more than one line?
^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <mailman.5250.1251122398.2239.help-gnu-emacs@gnu.org>]
* Re: Help with upcasing words first char
[not found] ` <mailman.5250.1251122398.2239.help-gnu-emacs@gnu.org>
@ 2009-08-24 15:20 ` Pascal J. Bourguignon
2009-08-24 22:49 ` Harry Putnam
0 siblings, 1 reply; 20+ messages in thread
From: Pascal J. Bourguignon @ 2009-08-24 15:20 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam <reader@newsguy.com> writes:
> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>
>> 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))))
>
> That works nicely but does throw an error when it finishes. My
> non-existent lisp skills were not able to determine what is causing
> it.
>
> (From *Messages* Buffer)
>
> Mark set
> unwind-protect: Symbol's value as variable is void: m
> Mark set
The error is on the last line, replace m by end:
(set-marker end nil))))
Sorry about that.
> Also I tried it on a larger region consisting of several lines and
> again it worked but in that case also removed the newlines.
Since the case of newlines has not been specified, I considered them
as whitespaces...
> I don't really understand what the regex you used (\s-+) means. I
> understand `\s' to mean any single occurrence of any whitespace.
>
> And also understand the `+' operator to mean `at least one plus any
> number of matches to preceding regex. But again ... not sure what the
> `-' operator does.
>
> But I wondered if that `\s' could be changed to something a little more
> exclusive.... like maybe tabs and spaces only.. and if that would
> allow the function to work on more than one line?
See: (info "(emacs)Regexp Backslash") C-x C-e
\s- represents any character having the syntax denoted by -, that is,
any whitespace.
+ is 1 or more occurences of the previous expression.
\s-+ is one or more occurences of whitespaces.
If you want only spaces or tabs, you can use "[ \t]+" instead.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-24 15:20 ` Pascal J. Bourguignon
@ 2009-08-24 22:49 ` Harry Putnam
2009-08-24 23:03 ` Harry Putnam
[not found] ` <mailman.5277.1251155045.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-24 22:49 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
>>
>> Mark set
>> unwind-protect: Symbol's value as variable is void: m
>> Mark set
>
> The error is on the last line, replace m by end:
>
> (set-marker end nil))))
>
> Sorry about that.
>
>
>> Also I tried it on a larger region consisting of several lines and
>> again it worked but in that case also removed the newlines.
>
> Since the case of newlines has not been specified, I considered them
> as whitespaces...
Your right... I did not specify that and really only thought of it
after having posted the OP.
[...] snipped more nifty tips
> If you want only spaces or tabs, you can use "[ \t]+" instead.
That works and allows the function to work over mulitple lines.
So with near total plagiarism of your code... I post below what
appears to be working code... I'm assuming there are other lisp
challenged readers who may find use for it. These tiny changes appear
to allow it to work over multiple lines.
(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)
(while (re-search-forward "[ \t]+" end t)
(delete-region (match-beginning 0) (match-end 0))))
(set-marker end nil))))
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-24 22:49 ` Harry Putnam
@ 2009-08-24 23:03 ` Harry Putnam
[not found] ` <mailman.5277.1251155045.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-24 23:03 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam <reader@newsguy.com> writes:
> (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)
> (while (re-search-forward "[ \t]+" end t)
> (delete-region (match-beginning 0) (match-end 0))))
> (set-marker end nil))))
Egad... please excuse my foolish blundering above... that code fails to
remove the spaces... Somehow I failed to notice that....
Maybe I'll get it right yet if I keep monkeying around with it.
^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <mailman.5277.1251155045.2239.help-gnu-emacs@gnu.org>]
* Re: Help with upcasing words first char
[not found] ` <mailman.5277.1251155045.2239.help-gnu-emacs@gnu.org>
@ 2009-08-24 23:52 ` Pascal J. Bourguignon
2009-08-25 15:34 ` Harry Putnam
0 siblings, 1 reply; 20+ messages in thread
From: Pascal J. Bourguignon @ 2009-08-24 23:52 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam <reader@newsguy.com> writes:
> Harry Putnam <reader@newsguy.com> writes:
>
>> (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)
>> (while (re-search-forward "[ \t]+" end t)
>> (delete-region (match-beginning 0) (match-end 0))))
>> (set-marker end nil))))
>
> Egad... please excuse my foolish blundering above... that code fails to
> remove the spaces... Somehow I failed to notice that....
>
> Maybe I'll get it right yet if I keep monkeying around with it.
It works for me.
(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))))
(set-marker end nil))))
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-24 23:52 ` Pascal J. Bourguignon
@ 2009-08-25 15:34 ` Harry Putnam
2009-08-25 19:35 ` Harry Putnam
[not found] ` <mailman.5347.1251228972.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-25 15:34 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> Harry Putnam <reader@newsguy.com> writes:
>
>> Harry Putnam <reader@newsguy.com> writes:
>>
>>> (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)
>>> (while (re-search-forward "[ \t]+" end t)
>>> (delete-region (match-beginning 0) (match-end 0))))
>>> (set-marker end nil))))
>>
>> Egad... please excuse my foolish blundering above... that code fails to
>> remove the spaces... Somehow I failed to notice that....
>>
>> Maybe I'll get it right yet if I keep monkeying around with it.
>
>
> It works for me.
>
> (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))))
> (set-marker end nil))))
Yes... and again more blundering here... I tested with a copy that
lacked the `[]' brackets... and in that case it Does the
capitalization but ignores the spaces.
By the time I saw that I'd made that oversite... I figured I'd already
looked dumb enough... and didn't post a correction.
Learning this has been like many new bits of knowledge that come my
way... first I thrash around with it... making every mistake humanly
possible and finally settle down with a new tool that works and that I
understand well enough to get use from it.
Thanks for your patience.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-25 15:34 ` Harry Putnam
@ 2009-08-25 19:35 ` Harry Putnam
[not found] ` <mailman.5347.1251228972.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-25 19:35 UTC (permalink / raw)
To: help-gnu-emacs
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)
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))))
Can something be altered in there to make the cursor land at the end
of the line?
SomeMoreXrays[here]
Or is it done where `m' is assigned the value it holds?
It appears to my untrained eye that `m' is told to hold the position of
the end of the effected text... which would be the last place a space
or tab was removed... (I guess.)
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?
===== * ===== * ===== * =====
(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))))
(set-marker end nil))))
^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <mailman.5347.1251228972.2239.help-gnu-emacs@gnu.org>]
* Re: Help with upcasing words first char
[not found] ` <mailman.5347.1251228972.2239.help-gnu-emacs@gnu.org>
@ 2009-08-25 21:02 ` Pascal J. Bourguignon
2009-08-30 1:42 ` Harry Putnam
0 siblings, 1 reply; 20+ messages in thread
From: Pascal J. Bourguignon @ 2009-08-25 21:02 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam <reader@newsguy.com> 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__
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
2009-08-25 21:02 ` Pascal J. Bourguignon
@ 2009-08-30 1:42 ` Harry Putnam
0 siblings, 0 replies; 20+ messages in thread
From: Harry Putnam @ 2009-08-30 1:42 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
> 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))))
Very nice... thanks again.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: Help with upcasing words first char
[not found] ` <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>
2009-08-22 19:02 ` A.Politz
2009-08-22 20:12 ` Pascal J. Bourguignon
@ 2009-08-23 18:14 ` B. T. Raven
2 siblings, 0 replies; 20+ messages in thread
From: B. T. Raven @ 2009-08-23 18:14 UTC (permalink / raw)
To: help-gnu-emacs
Harry Putnam wrote:
> Harry Putnam <reader@newsguy.com> writes:
>
>> I need to do a pile of editing that involves:
>>
>> Removing a space between words and upcasing the first letter of the
>> next word like:
>>
>> Some example
>> to
>> SomeExample
>>
>> I went thru M-x apropos <RET> <case> <RET>
>>
>> But didn't find a likely candidate ... or at least none appeared to be
>> the right thing for what I want.
>>
>> So far I've been
>>
>> Ctrl <right arrow> To get to the space between words
>> Ctrl-d Ctrl-d To remove the space and the leading lowercase char of
>> the next word
>>
>> Shift <Char> to replace with uppercase
>>
>> Then back to Ctrl <right arrow>
>>
>> Where can I save some keyboard strokes?
>
> Just to add a bit here...
>
> 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>
>
> Using upcase-region
> ctrl-<right arrow | ctrl-d | ctrl-spc | right arrow | upcase-region
>
> 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.
>
> Incidentally ... it appears `Ctrl-<arrow key>' keystrokes to move
> to next space between words, is only available on windows UI. At
> least I don't see it on my linux OS.
>
>
> 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
>
>
>
This almost works:
(defun cap-n-crunch-region (beg end)
(interactive "r")
(capitalize-region beg end)
(goto-char beg)
(while (search-forward " " end t)
(replace-match "" nil t))
)
It produced (only when quoted in the buffer!):
"OneTwoThreeFour"
Someone who knows elisp could fix it and then the interactive function
could be assigned to key combo or alias:
(global-set-key [(super c)] 'cap-n-crunch-region)
(defalias 'ccr 'cap-n-crunch-region)
Ed
^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <mailman.5143.1250956067.2239.help-gnu-emacs@gnu.org>]
end of thread, other threads:[~2009-08-30 1:42 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-22 15:46 Help with upcasing words first char Harry Putnam
2009-08-22 18:40 ` Harry Putnam
2009-08-24 13:01 ` Harry Putnam
[not found] ` <mailman.5160.1250966493.2239.help-gnu-emacs@gnu.org>
2009-08-22 19:02 ` A.Politz
2009-08-22 19:32 ` Joost Kremers
2009-08-22 21:29 ` John A Pershing Jr
2009-08-22 20:12 ` Pascal J. Bourguignon
2009-08-24 13:08 ` Harry Putnam
2009-08-24 13:59 ` Harry Putnam
[not found] ` <mailman.5250.1251122398.2239.help-gnu-emacs@gnu.org>
2009-08-24 15:20 ` Pascal J. Bourguignon
2009-08-24 22:49 ` Harry Putnam
2009-08-24 23:03 ` Harry Putnam
[not found] ` <mailman.5277.1251155045.2239.help-gnu-emacs@gnu.org>
2009-08-24 23:52 ` Pascal J. Bourguignon
2009-08-25 15:34 ` Harry Putnam
2009-08-25 19:35 ` Harry Putnam
[not found] ` <mailman.5347.1251228972.2239.help-gnu-emacs@gnu.org>
2009-08-25 21:02 ` Pascal J. Bourguignon
2009-08-30 1:42 ` Harry Putnam
2009-08-23 18:14 ` B. T. Raven
[not found] <mailman.5143.1250956067.2239.help-gnu-emacs@gnu.org>
2009-08-22 17:42 ` Joost Kremers
2009-08-22 18:15 ` Xah Lee
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.