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 14:23:48 -0700

Emanuel Berg <moasen@zoho.com> wrote:
>> I tried this:
>>
>> (add-hook 'python-mode-hook (lambda ()
>> (font-lock-add-keywords nil
>> '(("\\(\\(?:\\sw\\|\\s_\\|\\.\\)+\\)(" 1
>> font-lock-function-name-face nil)))))
>
> Interesting :)
>
> Here is another way to do it:
>
> Create a file, e.g. display.py .
>
> Open it in Emacs. Notice that the file
> extention is used to automatically put the
> editor in Python mode (defined in python.el).
>
> Now, write the following:
>
>     def display_string():
          ^^^^^^^^^^^^^^

By default, only this one is fontified with
font-lock-function-name-face.

>         print("This string is for display purposes ONLY.")
>
>     display_string()
      ^^^^^^^^^^^^^^

The snippet I posted causes this one to be fontified too.

> Watch out! "display_string" is in
> `font-lock-function-name-face'!

Since python-mode already fontifies the function name at definition
sites, I presume the OP is asking about having it fontified
"everywhere". However, he hasn't explained in detail.

        John



reply via email to

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