help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Change function name style


From: Andreas Röhler
Subject: Re: Change function name style
Date: Fri, 30 Jul 2010 08:36:50 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6

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 via email to

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