all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: something like un-camelcase region
Date: Mon, 26 Jul 2010 20:46:03 +0200	[thread overview]
Message-ID: <87sk36ytck.fsf@fh-trier.de> (raw)
In-Reply-To: ff-dnR8jKZbxUtDRnZ2dnUVZ_v-dnZ2d@sysmatrix.net

"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


      parent reply	other threads:[~2010-07-26 18:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sk36ytck.fsf@fh-trier.de \
    --to=politza@fh-trier.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.