unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Change function name style
Date: Fri, 30 Jul 2010 08:36:50 +0200	[thread overview]
Message-ID: <4C527302.4090105@easy-emacs.de> (raw)
In-Reply-To: <AANLkTimQKkw9b35QuAvFOxC=0D_cSe-nbw+fZ_ER=OXq@mail.gmail.com>

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/














  reply	other threads:[~2010-07-30  6:36 UTC|newest]

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

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=4C527302.4090105@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.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.
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).