emacsfont-lockbackquote

emacs define-generic-mode why cannot use regexp-opt?


I am trying to make simple major mode for syntax highlighting using define-generic-mode. I found that

(define-generic-mode 'mytest-mode
  '("//") nil
  '(
    ((regexp-opt '("int" "string" "bool")) . 'font-lock-type-face)
    )
  nil nil "mytest mode"
  )

is not working. But if I replace regexp-opt call with its manually calculated result, then all works as expected:

(define-generic-mode 'mytest-mode
  '("//") nil
  '(
    ("\\(?:bool\\|int\\|string\\)" . 'font-lock-type-face)
    )
  nil nil "mytest mode"
  )

So, why I cannot just put regexp-opt call in the mode definition?

EDIT

Hint about forced evaluation of items in quoted list from Lindidancer's answer:

(define-generic-mode 'mytest-mode
  '("//") nil
  '(
    (,(regexp-opt '("int" "string" "bool")) 'font-lock-type-face)
    )
  nil nil "mytest mode"
  )

doesn't help: no errors on mode activation but no highlighting also

Second hint about use list function to form lists:

(define-generic-mode 'mytest-mode
  '("//") nil
  (list
    ((regexp-opt '("int" "string" "bool")) 'font-lock-type-face)
    )
  nil nil "mytest mode"
  )

gives error on activating mode: (invalid-function (regexp-opt (quote ("int" "string" "bool"))))

same error when trying evaluate:

  (list
    ((regexp-opt '("int" "string" "bool")) 'font-lock-type-face)
    )

in scratch buffer.

EDIT 1

(list (list (regexp-opt '("int" "string" "bool")) 'font-lock-type-face))

doesn't help also - no errors, no highlighting.

EDIT 2

Steps, what I exactly do, are:

  1. Execute define-generic-mode call in the *Scratch* buffer
  2. Switch to buffer with some keywords under test
  3. M-x mytest-mode

Solution

  • (define-generic-mode 'mytest-mode
      '("//") nil
      `(
        (,(regexp-opt '("int" "string" "bool")) . 'font-lock-type-face)
        )
      nil nil "mytest mode"
      )