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))))
1
  • 1
    Because of the quote, the call to concat is not evaluated. You need backquote. See e.g. this Emacs SE question.
    – NickD
    Feb 1, 2021 at 13:50

1 Answer 1

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" ...))))
5
  • Ok, can I make emacs evaluate (concat ...)? Alternatively, can I store the regexp in a variable. I already tried the secon option, without success. Feb 1, 2021 at 20:53
  • 1
    Yes, with backquote - see the link in my comment.
    – NickD
    Feb 1, 2021 at 22:01
  • @NickD I've already tried to backquote following your link. Problably i missed/messed something. I'll try again,. Feb 2, 2021 at 0:00
  • Try (defvar biblinks-keywords `((,(concat .... .
    – NickD
    Feb 2, 2021 at 1:41
  • @NickD I tried again and now it works. Thanks. Feb 2, 2021 at 8:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.