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: Tim X
Subject: Re: something like un-camelcase region
Date: Wed, 08 Dec 2010 15:20:56 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

"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.
>
> (defun downcase-bigvowel-within-word ()
>     "Downcase all majuscule vowels not at beginning of words."
>   (interactive)
>   (let ((start (point)))
>     (save-excursion
>       (query-replace-regexp-eval "[^ ][AEIOU]"
>
> ; doesn't cover case of cap at beginning of line
>
>                                  '(cdr (assoc (match-string-no-properties 0)
>        '(("A" . "a") ("E" . "e") ("I" . "i") ("O" . "o") ("U" . "u")
>                                   )))
>                                  nil start (point-max))
> )))
>
>
>
>
> Do I even need a function to solve this problem? Can more than one
> "character set" (in regexp sense) be included in "replace regexp?"
>
> Another function from the wiki (supposedly from friendsnippets.com) is:
>
>     (defun un-camelcase-string (s &optional sep start)
>       "Convert CamelCase string S to lower case with word separator SEP.
>     Default for SEP is a hyphen \"-\".
>
>     If third argument START is non-nil, convert words after that
>     index in STRING."
>       (let ((case-fold-search nil))
>         (while (string-match "[A-Z]" s (or start 1))
>           (setq s (replace-match (concat (or sep "-")
>                                                  (downcase (match-string
> 0 s)))
>                                          t nil s)))
>         (downcase s)))
>
> But this works on string rather than region and puts a hyphen before
> downcased letter.
>
> Any help with my correct regexp?

You may find glasses-mode useful

,----[ C-h f glasses-mode RET ]
| glasses-mode is an interactive autoloaded Lisp function in `glasses.el'.
| 
| (glasses-mode &optional ARG)
| 
| Minor mode for making identifiers likeThis readable.
| When this mode is active, it tries to add virtual separators (like 
underscores)
| at places they belong to.
| 
| [back]
`----


-- 
tcross (at) rapttech dot com dot au


reply via email to

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