From 5210b89cfad217e97fa57d93979ec6825dc617ab Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli Date: Thu, 10 Sep 2026 12:19:22 +0200 Subject: [PATCH] Allow setting font-lock-keyword property using declare form * doc/lispref/functions.texi (Declare Form): Document 'font-lock-keyword' meta property. * etc/NEWS: Announce addition of 'font-lock-keyword' meta property. * lisp/emacs-lisp/byte-run.el (byte-run--set-font-lock-keyword): New function. * (defun-declarations-alist): Add entry for 'font-lock-keyword', using 'byte-run--set-font-lock-keyword'. * (with-no-warnings): Set 'font-lock-keyword' meta property. --- doc/lispref/functions.texi | 5 +++++ etc/NEWS | 8 ++++++++ lisp/emacs-lisp/byte-run.el | 10 ++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index 876cb702e3b..6a3b4d82876 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -2924,6 +2924,11 @@ original signature to avoid these issues. This is valid for macros only. Macros with this declaration are highlighted by font-lock (@pxref{Font Lock Mode}) as normal functions, not specially as macros. + +@item font-lock-keyword +Normal functions with this declaration are highlighted by font-lock +(@pxref{Font Lock Mode}) like macros. + @end table @end defmac diff --git a/etc/NEWS b/etc/NEWS index 31a4b78ad18..fb434538b61 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -467,6 +467,7 @@ Emacs 30. It allows Lisp programs that present completion candidates ("completion frontends") to provide additional information which can be used to adjust or optimize completion candidates computation. ++++ ** D-Bus +++ @@ -508,6 +509,13 @@ the actual and expected output. Strings should use numeric abbreviations like "-0600" instead of alphabetic abbreviations like "CST", which are too often ambiguous. +** Function 'declare' forms + ++++ +*** New 'font-lock-keyword' function declaration +The declaration '(font-lock-keyword t)' specifies that a normal +functions is to be highlighted by font-lock a macros. + * Changes in Emacs 32.1 on Non-Free Operating Systems diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index edd85f7bd43..e9b9603ee3b 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -252,6 +252,11 @@ declaration" f2 f)) (let ((code (apply fn args))) (list 'progn ':autoload-end code))))) +(defalias 'byte-run--set-font-lock-keyword + #'(lambda (name _args val) + (list 'function-put (list 'quote name) + ''font-lock-keyword (list 'quote val)))) + ;; Add any new entries to info node `(elisp)Declare Form'. (defvar defun-declarations-alist (list @@ -276,7 +281,8 @@ If `error-free', drop calls even if `byte-compile-delete-errors' is nil.") (list 'completion #'byte-run--set-completion) (list 'modes #'byte-run--set-modes) (list 'interactive-args #'byte-run--set-interactive-args) - (list 'ftype #'byte-run--set-function-type)) + (list 'ftype #'byte-run--set-function-type) + (list 'font-lock-keyword #'byte-run--set-font-lock-keyword)) "List associating function properties to their macro expansion. Each element of the list takes the form (PROP FUN) where FUN is a function. For each (PROP . VALUES) in a function's declaration, @@ -707,7 +713,7 @@ enabled." (defun with-no-warnings (&rest body) "Like `progn', but prevents compiler warnings in the body." - (declare (indent 0)) + (declare (indent 0) (font-lock-keyword t)) ;; The implementation for the interpreter is basically trivial. (car (last body)))