1

I work with a Makefile-like infrastructure that allows having lists as variables and appending values to them. For this, the += operator is used.

However, I'm having incorrect highlighting using this operator.

+= highlighting

The + is being highlighted as part of the word. I tried doing (modify-syntax-entry ?+ "." my-syntax-table-based-on-makefile-mode-syntax-table) without getting the desired result (having the + in += highlighted the same as =).

Felipe Lema
  • 737
  • 3
  • 11

1 Answers1

1

The highlighting of assignments is not syntax controlled in makefile-mode. It is done via regular expressions inmakefile-font-lock-keywords.

The list makefile-font-lock-keywords is constructed by the function makefile-make-font-lock-keywords which uses the variable makefile-macroassign-regex for macro assignments.

If you change makefile-macroassign-regex you must also re-run makefile-make-font-lock-keywords to reconstruct the font-lock keyword lists you need.

Also makefile-imenu-generic-expression is constructed from makefile-macroassign-regex so you need to reconstruct the value of that variable as well.

I demonstrate that by a self-defined major mode derived from makefile-mode. The most important change in that major mode is the added +-sign in the character groups of makefile-macroassign-regex.

(define-derived-mode my-makefile-mode makefile-mode "myMake"
  "Makefiles with additional operator +=."
  (setq-local makefile-macroassign-regex
              "\\(?:^\\|^export\\|^override\\|:\\|:[ \t]*override\\)[ \t]*\\([^ \n\t+][^:#= \t\n+]*\\)[ \t]*\\(?:!=\\|[*:+]?[:?]?=\\)")
  (setq-local makefile-font-lock-keywords
              (makefile-make-font-lock-keywords
               makefile-var-use-regex
               makefile-statements
               t))
  (setq-local makefile-imenu-generic-expression
              `(("Dependencies" makefile-previous-dependency 1)
                ("Macro Assignment" ,makefile-macroassign-regex 1))))
Tobias
  • 32,569
  • 1
  • 34
  • 75