1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-31 11:10:51 -07:00
emacs/test/lisp/progmodes/m4-mode-tests.el
Basil L. Contovounesios d01a33662c Improve m4-mode font lock
Emacs 28 started fontifying several 'composite' (non-builtin) GNU M4
macros which, while listed under '(m4) Macro index', are not defined
by GNU M4, and are included in its manual for illustrative purposes.

These macro keywords range from clearly misleading (e.g., 'example',
which the GNU M4 manual explicitly describes as nonexistent),
to common in Autoconf's M4sugar layer (e.g., 'm4_quote'),
to variations thereof (e.g., 'foreachq').

It is arguably too late to revert all of these additions, so this
patch selects a handful to remove, and categorizes the rest; this
should make it easier to hide some categories behind a font lock
level or user option in the future, if desired.

This patch reverts the Emacs 28 addition of 'example', and removes
the older 'file', 'line', and 'gnu' macros.  GNU M4 renamed 'gnu' to
'__gnu__' already in 1990; and I couldn't find references to the
other two which exist as '__file__' and '__line__', respectively.

The remaining macros are partitioned into three sets: built-in,
M4sugar-like, and other (bug#80412).  For discussion, see also:
https://lists.gnu.org/r/emacs-devel/2025-10/msg00357.html

* lisp/progmodes/m4-mode.el (m4-program-options): Remove stale
commentary.
(m4--macro-list): Remove, replacing with...
(m4--builtin, m4--autoconf, m4--composite): ...these new rx
definitions.  All uses changed.  Remove 'example', 'file', 'gnu',
and 'line' as keywords.
(m4-font-lock-keywords): For consistency with real #-comments,
fontify dnl macro with font-lock-comment-delimiter-face, and only
the rest of its line with font-lock-comment-face.  Fontify argument
references with font-lock-variable-use-face rather than
font-lock-variable-name-face.  Use font lock faces rather than their
eponymous but obsolete variables.  Remove redundant entries for $@
and $*.  Prefer shy regexp groups where applicable.
(m4-mode-syntax-table): Quote syntactically special characters.
(m4-m4-buffer): DRY using m4-m4-region.
(m4-m4-region): Take region bounds as optional arguments, as
recommended under '(elisp) The Mark'.  Quote shell command.
Support non-contiguous regions.
(m4-current-defun-name): Recognize m4 backtick in addition to
Autoconf bracket.  Prefer shy regexp groups where applicable.
(m4-mode): Simplify font-lock-defaults.

* test/lisp/progmodes/m4-mode-resources/font-lock.m4:
* test/lisp/progmodes/m4-mode-tests.el: New test files.
2026-02-22 17:10:17 +01:00

55 lines
1.8 KiB
EmacsLisp

;;; m4-mode-tests.el --- tests for m4-mode.el -*- lexical-binding: t -*-
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(require 'ert-font-lock)
(require 'm4-mode)
(ert-deftest m4-current-defun-name ()
"Test `m4-current-defun-name' behavior."
(with-temp-buffer
(m4-mode)
(insert "define(`a', `')")
(should (equal (m4-current-defun-name) "a"))
;; Not at toplevel.
(insert "define(`b', `')")
(should (equal (m4-current-defun-name) "a"))
(insert "\nm4_define(`c', `')")
(should (equal (m4-current-defun-name) "c"))
(insert "\nAC_DEFUN([d], [])")
(should (equal (m4-current-defun-name) "d"))
(insert "\nAU_DEFUN([e], [])")
(should (equal (m4-current-defun-name) "e"))))
(ert-deftest m4-mode-comment-syntax ()
"Test `m4-mode' comment syntax."
(with-temp-buffer
(m4-mode)
(insert "# comment")
(should (eq (syntax-ppss-context (syntax-ppss)) 'comment))
(insert ?\n)
(should-not (syntax-ppss-context (syntax-ppss)))))
(ert-font-lock-deftest-file m4-mode-font-lock
"Test `m4-mode' font lock."
m4-mode "font-lock.m4")
;;; m4-mode-tests.el ends here