all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#55573: 29.0.50; python.el font-locks invalid class/function names
@ 2022-05-22 13:20 kobarity
  2022-05-22 16:53 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: kobarity @ 2022-05-22 13:20 UTC (permalink / raw)
  To: 55573

[-- Attachment #1: Type: text/plain, Size: 2838 bytes --]

When the following Python file is loaded using emacs -Q and M-x
find-file, "1func" is font-locked as a function name although it is not
a valid function name.

#+begin_src python
def 1func():
    pass
#+end_src

Attached is my proposal to fix this issue.

In GNU Emacs 29.0.50 (build 4, x86_64-pc-linux-gnu)
 of 2022-05-21 built on ubuntu
Repository revision: 208102fa470e3417320062cdb48a9967d80bf092
Repository branch: master
System Description: Ubuntu 22.04 LTS

Configured using:
 'configure --without-x --with-gnutls=ifavailable'

Configured features:
ACL LIBXML2 MODULES NOTIFY INOTIFY PDUMPER SECCOMP SOUND SQLITE3 THREADS
XIM ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media rmc puny
dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg
rfc6068 epg-config gnus-util text-property-search time-date mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
wombat-theme manoj-dark-theme dichromacy-theme cus-theme cus-edit pp
cus-start cus-load wid-edit python json map comint regexp-opt ring
cl-loaddefs cl-lib ansi-color seq term/screen term/xterm xterm gv subr-x
byte-opt bytecomp byte-compile cconv iso-transl tooltip eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer
nadvice simple cl-generic cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
faces cus-face macroexp files window text-properties overlay sha1 md5
base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads inotify multi-tty
make-network-process emacs)

Memory information:
((conses 16 84231 7303)
 (symbols 48 8723 1)
 (strings 32 23861 1652)
 (string-bytes 1 712652)
 (vectors 16 12013)
 (vector-slots 8 139506 3457)
 (floats 8 51 673)
 (intervals 56 316 4)
 (buffers 992 13))

[-- Attachment #2: fix-python-font-lock-keywords-level-1.patch --]
[-- Type: application/octet-stream, Size: 1578 bytes --]

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index c1368364a9..9adbb82abf 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -540,9 +540,9 @@ python--font-lock-f-strings
         (setq ppss (syntax-ppss))))))
 
 (defvar python-font-lock-keywords-level-1
-  `((,(rx symbol-start "def" (1+ space) (group (1+ (or word ?_))))
+  `((,(python-rx symbol-start "def" (1+ space) (group symbol-name))
      (1 font-lock-function-name-face))
-    (,(rx symbol-start "class" (1+ space) (group (1+ (or word ?_))))
+    (,(python-rx symbol-start "class" (1+ space) (group symbol-name))
      (1 font-lock-type-face)))
   "Font lock keywords to use in `python-mode' for level 1 decoration.
 
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index a3f778bbbe..479d68a062 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -214,6 +214,18 @@ python-syntax-after-python-backspace
     (should (string= (buffer-string) "\"\""))
     (should (null (nth 3 (syntax-ppss))))))
 
+(ert-deftest python-font-lock-keywords-level-1-1 ()
+  (python-tests-assert-faces
+   "def func():"
+   '((1 . font-lock-keyword-face) (4)
+     (5 . font-lock-function-name-face) (9))))
+
+(ert-deftest python-font-lock-keywords-level-1-2 ()
+  "Invalid function name should not be font-locked."
+  (python-tests-assert-faces
+   "def 1func():"
+   '((1 . font-lock-keyword-face) (4))))
+
 (ert-deftest python-font-lock-assignment-statement-1 ()
   (python-tests-assert-faces
    "a, b, c = 1, 2, 3"

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#55573: 29.0.50; python.el font-locks invalid class/function names
  2022-05-22 13:20 bug#55573: 29.0.50; python.el font-locks invalid class/function names kobarity
@ 2022-05-22 16:53 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-22 16:53 UTC (permalink / raw)
  To: kobarity; +Cc: 55573

kobarity <kobarity@gmail.com> writes:

> When the following Python file is loaded using emacs -Q and M-x
> find-file, "1func" is font-locked as a function name although it is not
> a valid function name.
>
> #+begin_src python
> def 1func():
>     pass
> #+end_src
>
> Attached is my proposal to fix this issue.

Thanks; pushed to Emacs 29.

For future patches, including ChangeLog style commit messages would be
appreciated.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-22 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-22 13:20 bug#55573: 29.0.50; python.el font-locks invalid class/function names kobarity
2022-05-22 16:53 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.