[Top][All Lists]

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

Re: Change function name style

From: suvayu ali
Subject: Re: Change function name style
Date: Thu, 29 Jul 2010 16:48:33 -0700

On 29 July 2010 14:42, Andrea Crotti <address@hidden> 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))
      (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. :)


Open source is the future. It sets us free.

reply via email to

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