all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Change function name style
@ 2010-07-29 16:14 Andrea Crotti
  2010-07-29 19:33 ` Andreas Röhler
  2010-07-30  2:44 ` Thamer Mahmoud
  0 siblings, 2 replies; 15+ messages in thread
From: Andrea Crotti @ 2010-07-29 16:14 UTC (permalink / raw)
  To: help-gnu-emacs

Supposing I have many C files with functions in camelized mode and I
want to change them all to underscore mode.

Even better, something like:
thisFunction -> this_function
this_function -> _this_function

how could I make the wonderful emacs do that for me?
I think I could use or the mode informations (with describe-face) or
even semantic with some tricks, but I'm not sure why...
Any idea?
Thanks





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

* Re: Change function name style
  2010-07-29 16:14 Change function name style Andrea Crotti
@ 2010-07-29 19:33 ` Andreas Röhler
  2010-07-29 19:45   ` Andrea Crotti
       [not found]   ` <mailman.3.1280432759.8442.help-gnu-emacs@gnu.org>
  2010-07-30  2:44 ` Thamer Mahmoud
  1 sibling, 2 replies; 15+ messages in thread
From: Andreas Röhler @ 2010-07-29 19:33 UTC (permalink / raw)
  To: help-gnu-emacs

Am 29.07.2010 18:14, schrieb Andrea Crotti:
> Supposing I have many C files with functions in camelized mode and I
> want to change them all to underscore mode.
>
> Even better, something like:
> thisFunction ->  this_function
> this_function ->  _this_function
>
> how could I make the wonderful emacs do that for me?
> I think I could use or the mode informations (with describe-face) or
> even semantic with some tricks, but I'm not sure why...
> Any idea?
> Thanks
>
>
>
>

with a regexp employing [[:lower:]]+[[:upper:]] etc. inside
\\(...\\)



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

* Re: Change function name style
  2010-07-29 19:33 ` Andreas Röhler
@ 2010-07-29 19:45   ` Andrea Crotti
  2010-07-29 20:30     ` suvayu ali
       [not found]   ` <mailman.3.1280432759.8442.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Andrea Crotti @ 2010-07-29 19:45 UTC (permalink / raw)
  To: help-gnu-emacs


> with a regexp employing [[:lower:]]+[[:upper:]] etc. inside
> \\(...\\)

Yes well that's last possibility, what if I have a variable called
myVariable?

A regexp can't know when I have a function or a function call, while
both emacs c-mode and semantic do...




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

* Re: Change function name style
       [not found]   ` <mailman.3.1280432759.8442.help-gnu-emacs@gnu.org>
@ 2010-07-29 20:29     ` Elena
  2010-07-29 21:53       ` Colin S. Miller
  0 siblings, 1 reply; 15+ messages in thread
From: Elena @ 2010-07-29 20:29 UTC (permalink / raw)
  To: help-gnu-emacs

On 29 Lug, 21:45, Andrea Crotti <andrea.crott...@gmail.com> wrote:
> A regexp can't know when I have a function or a function call, while
> both emacs c-mode and semantic do...

Then write a loop which opens those files with font-lock enabled.
Start searching in each buffer with above regexp, check face with
(face-at-point) at each match before replacing. Then save and close
the buffer.



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

* Re: Change function name style
  2010-07-29 19:45   ` Andrea Crotti
@ 2010-07-29 20:30     ` suvayu ali
  2010-07-29 21:42       ` Andrea Crotti
       [not found]       ` <mailman.16.1280439739.8442.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 15+ messages in thread
From: suvayu ali @ 2010-07-29 20:30 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On 29 July 2010 12:45, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
>
>> with a regexp employing [[:lower:]]+[[:upper:]] etc. inside
>> \\(...\\)
>
> Yes well that's last possibility, what if I have a variable called
> myVariable?
>
> A regexp can't know when I have a function or a function call, while
> both emacs c-mode and semantic do...
>

I am a lisp newbie but how about something like this,

(string-match "function-name"
			   (symbol-name (if (< (point) (point-max))
					    (face-at-point)
					  (backward-char)
					  (face-at-point))))

I use this to have context sensitive abbreviation expansion. Maybe you
can adapt it for your case?

-- 
Suvayu

Open source is the future. It sets us free.



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

* Re: Change function name style
  2010-07-29 20:30     ` suvayu ali
@ 2010-07-29 21:42       ` Andrea Crotti
  2010-07-29 23:48         ` suvayu ali
       [not found]       ` <mailman.16.1280439739.8442.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Andrea Crotti @ 2010-07-29 21:42 UTC (permalink / raw)
  To: help-gnu-emacs

> I am a lisp newbie but how about something like this,
>
> (string-match "function-name"
> 			   (symbol-name (if (< (point) (point-max))
> 					    (face-at-point)
> 					  (backward-char)
> 					  (face-at-point))))
>
> I use this to have context sensitive abbreviation expansion. Maybe you
> can adapt it for your case?

Thanks a lot, but how do you use exactly this thing that there is no
defun?

Anyway I see that strangely if I do face-at-point on a function call

functionCall(...)

I get a "default", it only recognizes functions when they're defined.
So maybe is not the way to go...




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

* Re: Change function name style
  2010-07-29 20:29     ` Elena
@ 2010-07-29 21:53       ` Colin S. Miller
  2010-07-29 22:01         ` Elena
  0 siblings, 1 reply; 15+ messages in thread
From: Colin S. Miller @ 2010-07-29 21:53 UTC (permalink / raw)
  To: help-gnu-emacs

Elena wrote:
> On 29 Lug, 21:45, Andrea Crotti <andrea.crott...@gmail.com> wrote:
>> A regexp can't know when I have a function or a function call, while
>> both emacs c-mode and semantic do...
> 
> Then write a loop which opens those files with font-lock enabled.
> Start searching in each buffer with above regexp, check face with
> (face-at-point) at each match before replacing. Then save and close
> the buffer.
> 

Why close the buffer?
If it is to ensure the buffer is fontified correctly, the
(font-lock-fontify-buffer) will force a refontification.

HTH,
Colin S. Miller

-- 
Replace the obvious in my email address with the first three letters of the hostname to reply.


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

* Re: Change function name style
  2010-07-29 21:53       ` Colin S. Miller
@ 2010-07-29 22:01         ` Elena
  0 siblings, 0 replies; 15+ messages in thread
From: Elena @ 2010-07-29 22:01 UTC (permalink / raw)
  To: help-gnu-emacs

On 29 Lug, 23:53, "Colin S. Miller" <no-spam-
thank-...@csmiller.demon.co.uk> wrote:
> Why close the buffer?

Because he just needed to replace function names, he does not need to
keep the files open.


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

* Re: Change function name style
       [not found]       ` <mailman.16.1280439739.8442.help-gnu-emacs@gnu.org>
@ 2010-07-29 22:15         ` Elena
  0 siblings, 0 replies; 15+ messages in thread
From: Elena @ 2010-07-29 22:15 UTC (permalink / raw)
  To: help-gnu-emacs

On 29 Lug, 23:42, Andrea Crotti <andrea.crott...@gmail.com> wrote:
> Anyway I see that strangely if I do face-at-point on a function call
>
> functionCall(...)
>
> I get a "default", it only recognizes functions when they're defined.
> So maybe is not the way to go...

Well, if functions are not recognized, I suppose you'll have to resort
to regexps.

I think you'll need to perform your task in two steps:
- look for a regexp which includes parentheses and then check faces
(like I said before);
- call `rgrep' with the same regexp and fix the missed hits into
"*grep*" buffer and then call `grep-edit-finish-edit'.


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

* Re: Change function name style
  2010-07-29 21:42       ` Andrea Crotti
@ 2010-07-29 23:48         ` suvayu ali
  2010-07-30  6:36           ` Andreas Röhler
  0 siblings, 1 reply; 15+ messages in thread
From: suvayu ali @ 2010-07-29 23:48 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On 29 July 2010 14:42, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
>> I am a lisp newbie but how about something like this,
>>
>> (string-match "function-name"
>>                          (symbol-name (if (< (point) (point-max))
>>                                           (face-at-point)
>>                                         (backward-char)
>>                                         (face-at-point))))
>>
>> I use this to have context sensitive abbreviation expansion. Maybe you
>> can adapt it for your case?
>
> Thanks a lot, but how do you use exactly this thing that there is no
> defun?
>

Sorry I didn't include the entire defun as it involved all the other
things not relevant to your requirement. What I was suggesting was in
your defun you could check for the face with that snippet and then
apply the regex as suggested by Andreas.

So something like this might work, (untested)

(defun function-name-p (camelcase-to-underscore)
  "Convert camel case function names to underscored names."
  ;; backward-char checks if end-of-buffer as when point at e-o-b face is `nil'
  (if (not (save-excursion
	     (string-match "function-name"
			   (symbol-name (if (< (point) (point-max))
					    (face-at-point)
					  (backward-char)
					  (face-at-point))))))
      (funcall camelcase-to-underscore)))

where camelcase-to-underscore is a defun that you defined to do the
conversion using the regex.

How this works:
It looks at the face at point and checks whether the face name has the
string "function-name" and calls the function camelcase-to-underscore.

> Anyway I see that strangely if I do face-at-point on a function call
>
> functionCall(...)
>
> I get a "default", it only recognizes functions when they're defined.
> So maybe is not the way to go...
>

Of course my above proposal assumes you have font lock working
properly and `M-x describe-face' returns
"font-lock-function-name-face". For my setup the returns this name
both in emacs-lisp-mode and c++-mode. So I was expecting it would do
the same for your case.

Good luck figuring this out. And do post back if you get any solution,
I would be interested to know. :)

-- 
Suvayu

Open source is the future. It sets us free.



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

* Re: Change function name style
  2010-07-29 16:14 Change function name style Andrea Crotti
  2010-07-29 19:33 ` Andreas Röhler
@ 2010-07-30  2:44 ` Thamer Mahmoud
  2010-07-30 12:04   ` Andrea Crotti
       [not found]   ` <mailman.0.1280492013.7663.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 15+ messages in thread
From: Thamer Mahmoud @ 2010-07-30  2:44 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> Supposing I have many C files with functions in camelized mode and I
> want to change them all to underscore mode.
>

Try glasses-mode.

hth,
Thamer




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

* Re: Change function name style
  2010-07-29 23:48         ` suvayu ali
@ 2010-07-30  6:36           ` Andreas Röhler
  0 siblings, 0 replies; 15+ messages in thread
From: Andreas Röhler @ 2010-07-30  6:36 UTC (permalink / raw)
  To: help-gnu-emacs

Am 30.07.2010 01:48, schrieb suvayu ali:
> On 29 July 2010 14:42, Andrea Crotti<andrea.crotti.0@gmail.com>  wrote:
>>> I am a lisp newbie but how about something like this,
>>>
>>> (string-match "function-name"
>>>                           (symbol-name (if (<  (point) (point-max))
>>>                                            (face-at-point)
>>>                                          (backward-char)
>>>                                          (face-at-point))))
>>>
>>> I use this to have context sensitive abbreviation expansion. Maybe you
>>> can adapt it for your case?
>>
>> Thanks a lot, but how do you use exactly this thing that there is no
>> defun?
>>
>
> Sorry I didn't include the entire defun as it involved all the other
> things not relevant to your requirement. What I was suggesting was in
> your defun you could check for the face with that snippet and then
> apply the regex as suggested by Andreas.
>
> So something like this might work, (untested)
>
> (defun function-name-p (camelcase-to-underscore)
>    "Convert camel case function names to underscored names."
>    ;; backward-char checks if end-of-buffer as when point at e-o-b face is `nil'
>    (if (not (save-excursion
> 	     (string-match "function-name"
> 			   (symbol-name (if (<  (point) (point-max))
> 					    (face-at-point)
> 					  (backward-char)
> 					  (face-at-point))))))
>        (funcall camelcase-to-underscore)))
>
> where camelcase-to-underscore is a defun that you defined to do the
> conversion using the regex.
>
> How this works:
> It looks at the face at point and checks whether the face name has the
> string "function-name" and calls the function camelcase-to-underscore.
>
>> Anyway I see that strangely if I do face-at-point on a function call
>>
>> functionCall(...)
>>
>> I get a "default", it only recognizes functions when they're defined.
>> So maybe is not the way to go...
>>
>
> Of course my above proposal assumes you have font lock working
> properly and `M-x describe-face' returns
> "font-lock-function-name-face". For my setup the returns this name
> both in emacs-lisp-mode and c++-mode. So I was expecting it would do
> the same for your case.
>
> Good luck figuring this out. And do post back if you get any solution,
> I would be interested to know. :)
>

Interesting, but

even if it's the case or quite possible, the markup of a C-mode is 
written that way, putting different faces upon function and variable 
definitions, you can't rely on that with this purpose.

Also you can't assume, a certain face isn't used otherwise too.

To discriminate these forms, there is no way to parse the code 
understanding its content.

Some tools may provide it,

would assume Emacs' Cedet does. It comes a code-browser ECB with Emacs too.


Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/














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

* Re: Change function name style
  2010-07-30  2:44 ` Thamer Mahmoud
@ 2010-07-30 12:04   ` Andrea Crotti
  2010-08-03 10:00     ` Andrea Crotti
       [not found]   ` <mailman.0.1280492013.7663.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 15+ messages in thread
From: Andrea Crotti @ 2010-07-30 12:04 UTC (permalink / raw)
  To: help-gnu-emacs

>
> Try glasses-mode.
>
> hth,
> Thamer

Ah very nice, always find new modes :D, only two problems
- it doesn't change to lowercase the letter after _
- it's not "context sensitive", since I only want to manipulate functions


I'll see what I can understand from semantic I think is the only way to go.




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

* Re: Change function name style
       [not found]   ` <mailman.0.1280492013.7663.help-gnu-emacs@gnu.org>
@ 2010-07-30 13:19     ` Elena
  0 siblings, 0 replies; 15+ messages in thread
From: Elena @ 2010-07-30 13:19 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 30, 12:04 pm, Andrea Crotti <andrea.crott...@gmail.com> wrote:
> I'll see what I can understand from semantic I think is the only way to go.

You know what? Just grab an IDE and make it do this damned
refactoring ;-) Bloated as IDEs can be, these jobs are their bread and
butter.

None of the users of Emacs who answered has been able to provide a
definite solution. To be an effective user of Emacs, I think you must
learn when other tools are just more effective.

Cheers.


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

* Re: Change function name style
  2010-07-30 12:04   ` Andrea Crotti
@ 2010-08-03 10:00     ` Andrea Crotti
  0 siblings, 0 replies; 15+ messages in thread
From: Andrea Crotti @ 2010-08-03 10:00 UTC (permalink / raw)
  To: help-gnu-emacs


> Ah very nice, always find new modes :D, only two problems
> - it doesn't change to lowercase the letter after _
> - it's not "context sensitive", since I only want to manipulate functions
>
>
> I'll see what I can understand from semantic I think is the only way to go.

I was trying with regexp again to see if it works, and for example with

startFunction(...)

I can do
--8<---------------cut here---------------start------------->8---
M-x query-replace-regexp start\([A-Z].*\) start_\1
--8<---------------cut here---------------end--------------->8---

but I can't put the second string to lower case, which I guess is
harder.
Any way to do that just with regexps?




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

end of thread, other threads:[~2010-08-03 10:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-29 16:14 Change function name style Andrea Crotti
2010-07-29 19:33 ` Andreas Röhler
2010-07-29 19:45   ` Andrea Crotti
2010-07-29 20:30     ` suvayu ali
2010-07-29 21:42       ` Andrea Crotti
2010-07-29 23:48         ` suvayu ali
2010-07-30  6:36           ` Andreas Röhler
     [not found]       ` <mailman.16.1280439739.8442.help-gnu-emacs@gnu.org>
2010-07-29 22:15         ` Elena
     [not found]   ` <mailman.3.1280432759.8442.help-gnu-emacs@gnu.org>
2010-07-29 20:29     ` Elena
2010-07-29 21:53       ` Colin S. Miller
2010-07-29 22:01         ` Elena
2010-07-30  2:44 ` Thamer Mahmoud
2010-07-30 12:04   ` Andrea Crotti
2010-08-03 10:00     ` Andrea Crotti
     [not found]   ` <mailman.0.1280492013.7663.help-gnu-emacs@gnu.org>
2010-07-30 13:19     ` Elena

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.