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.
This commit is contained in:
Jonas Bernoulli 2026-09-10 12:19:22 +02:00
parent 67eb1ee26e
commit 5210b89cfa
No known key found for this signature in database
GPG key ID: 230C2EFBB326D927
3 changed files with 21 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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)))