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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: something like un-camelcase region


From: Andreas Politz
Subject: Re: something like un-camelcase region
Date: Wed, 08 Dec 2010 15:21:03 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

"B. T. Raven" <nihil@nihilo.net> writes:

> Andreas Politz wrote:
>> "B. T. Raven" <nihil@nihilo.net> writes:
>> 
>>> I am looking for a regular expression that finds capital letters within
>>> words (i.e. not at beginning of word or line)so that I can downcase
>>> these caps only. I have a couple of non-functional functions that might
>>> illustrate the general problem.
>>>
>> 
>> (while (re-search-forward "\\b\\w\\(\\w+\\)")
>>   (replace-match (downcase (match-string 1)) t t nil 1))
>> 
>> Downcases all but the first character in all words.
>
> Can't get this to work in ver. 22.3
> Where does match-string come from if re-search-forward returns only the
> buffer position? How would your (while) function above be wrapped in an
> interactive function? Or doesn't that make sense here? It works if I
> just evaluate it at beginning of file of interest. Does it have to be
> wrapped in  a lamba to make it interactive?
>

re-search-forward and some other functions store informations about the
matched entities (e.g. 1st parentheses-group) and functions like match-string
access this data. See (info "(elisp) Match Data") .

Here is one way of wrapping it up.  Of course it (and therefore the
regexp) depends on your idea of a camel-cased word.

(defun uncamelcase-region (beg end)
  (interactive
   (if (and transient-mark-mode mark-active)
       (list (region-beginning) (region-end))
     (list (point) (point-max))))
  (goto-char beg)
  (while (re-search-forward "\\b\\w\\(\\w+\\)" end 'move)
    (downcase-region (match-beginning 1) (match-end 1))
    ;;(replace-match (downcase (match-string 1)) t t nil 1)
    ))


-ap


reply via email to

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