0

Why do I get the error: font-lock-fontify-keywords-region: Invalid function: (concat "\\\\" (regexp-opt (quote ("cs" "hepth" "hepph" "heplat" "hepex" "nuclth" "nuclex" "grqc" "qalg" "dgga" ...))) "{\\([0-9]+\\)}")

when this code is evaluated?:

(defvar biblinks-keywords
  '(((concat "\\\\" (regexp-opt '("cs"
                  "hepth"
                  "hepph"
                  "heplat"
                  "hepex"
                  "nuclth"
                  "nuclex"
                  "grqc"
                  "qalg"
                  "dgga"
                  "accphys"
                  "alggeom"
                  "astroph"
                  "chaodyn"
                  "condmat"
                  "nlinsys"
                  "nlinsi"
                  "nlin"
                  "quantph"
                  "solvint"
                  "suprcon"
                  "mathph"
                  "physics")) "{\\([0-9]+\\)}")
 (0 `(face
  link
  keymap
  ,oldarXivid-keymap)
prepend))))

If I use the following code instead, it works:

(defvar biblinks-keywords
  '(("\\\\\\(?:a\\(?:ccphys\\|lggeom\\|stroph\\)\\|c\\(?:haodyn\\|ondmat\\|s\\)\\|dgga\\|grqc\\|hep\\(?:ex\\|lat\\|[pt]h\\)\\|mathph\\|n\\(?:lin\\(?:s\\(?:i\\|ys\\)\\)?\\|ucl\\(?:ex\\|th\\)\\)\\|physics\\|q\\(?:alg\\|uantph\\)\\|s\\(?:olvint\\|uprcon\\)\\){\\([0-9]+\\)}"
      (0 `(face
           link
           keymap
           ,oldarXivid-keymap)
         prepend))))
phils
  • 50,977
  • 3
  • 79
  • 122
Gabriele
  • 1,554
  • 9
  • 21

1 Answers1

1

The documentation for font-lock-keywords tells us:

Each element in a user-level keywords list should have one of these forms:

MATCHER (MATCHER . SUBEXP) (MATCHER . FACENAME) (MATCHER . HIGHLIGHT) (MATCHER HIGHLIGHT ...) (eval . FORM)

where MATCHER can be either the regexp to search for, or the function name to call to make the search ...

Your keywords list was:

(((concat "\\\\" (regexp-opt '("cs" ...)))))

And so the first item of that list is:

((concat "\\\\" (regexp-opt '("cs" ...))))

Which is a cons cell, so the car of that value will be MATCHER (as it is not eval). The car is:

(concat "\\\\" (regexp-opt '("cs" ...)))

MATCHER can either be a regexp or a function name, and it's not a regexp (that would be a string), so it has to be a function name. Therefore Emacs tries to call the function with the name:

(concat "\\\\" (regexp-opt '("cs" ...)))

Hence:

Invalid function: (concat "\\\\" (regexp-opt (quote ("cs" ...))))
phils
  • 50,977
  • 3
  • 79
  • 122