unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* something like un-camelcase region
@ 2010-07-25 18:13 B. T. Raven
  2010-07-25 22:12 ` Tim X
       [not found] ` <87y6czqs1r.fsf@fh-trier.de>
  0 siblings, 2 replies; 3+ messages in thread
From: B. T. Raven @ 2010-07-25 18:13 UTC (permalink / raw)
  To: help-gnu-emacs

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?


Thanks,

Ed


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: something like un-camelcase region
  2010-07-25 18:13 something like un-camelcase region B. T. Raven
@ 2010-07-25 22:12 ` Tim X
       [not found] ` <87y6czqs1r.fsf@fh-trier.de>
  1 sibling, 0 replies; 3+ messages in thread
From: Tim X @ 2010-07-25 22:12 UTC (permalink / raw)
  To: help-gnu-emacs

"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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: something like un-camelcase region
       [not found]   ` <ff-dnR8jKZbxUtDRnZ2dnUVZ_v-dnZ2d@sysmatrix.net>
@ 2010-07-26 18:46     ` Andreas Politz
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Politz @ 2010-07-26 18:46 UTC (permalink / raw)
  To: help-gnu-emacs

"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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-26 18:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-25 18:13 something like un-camelcase region B. T. Raven
2010-07-25 22:12 ` Tim X
     [not found] ` <87y6czqs1r.fsf@fh-trier.de>
     [not found]   ` <ff-dnR8jKZbxUtDRnZ2dnUVZ_v-dnZ2d@sysmatrix.net>
2010-07-26 18:46     ` Andreas Politz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).