help-gnu-emacs
[Top][All Lists]
Advanced

[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: Mon, 24 Aug 2009 17:20:46 +0200
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux)

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__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]