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

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

Re: Regex to match underscore in function name in Python Mode?


From: John Mastro
Subject: Re: Regex to match underscore in function name in Python Mode?
Date: Mon, 24 Jul 2017 11:38:49 -0700

John Mastro <john.b.mastro@gmail.com> wrote:
>> In C mode I have the following in my ~/.emacs that will highlight a
>> function name:
>>
>> ;; Highlight punctuation in C mode
>> (add-hook
>>  'c-mode-common-hook
>>  (lambda ()
>>    (font-lock-add-keywords
>>     nil
>>     '(("[<>:&*=+^%!~,.?;/-]"
>>        0 font-lock-warning-face nil)))
>>    ))
>
> I think you may have posted the wrong snippet? This seems to fontify
> punctuation characters, not function names.

[snip]

> Is the goal to fontify function names at use sites (e.g. the `foo` in
> `foo(0)`) in addition to declaration and definition sites (where they're
> already fontified by the major mode)?

I tried this:

(add-hook
 'python-mode-hook
 (lambda ()
   (font-lock-add-keywords
    nil
    '(("\\(\\(?:\\sw\\|\\s_\\|\\.\\)+\\)("
       1 font-lock-function-name-face nil)))))

I'm not sure it's exactly the same thing you're trying to do, but
underscores didn't pose any problems for highlighting the full symbol.
Perhaps your regular expressions just isn't quite right.

        John



reply via email to

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