I've added some keywords using the following construct (where tag-todo
and tag-note
are variable holding a SVG image and tag-key ()
is a function returning a SVG image):
(font-lock-add-keywords nil
'(("\\(\:TODO\:\\)" 1 `(face nil display ,tag-todo))
("\\(\:NOTE\:\\)" 1 `(face nil display ,tag-note))
("\\(=[0-9a-zA-Z- ]+?=\\)" 1
`(face nil display ,(tag-key (match-string 0))))))
This works great (see reddit post) but I would like now to do the same using a list of regexp / tag (or function):
(setq tags '((":TODO:" . tag-todo)
(":NOTE:" . tag-note)
("=[0-9a-zA-Z- ]+?=" . tag-key)))
I can iterate over the list using dolist
but then I'not sure how to write the actual call to font-lock-add-keywords
(building the regexp and make sure the tag variable (or function) is called):
(dolist (item tags)
(let ((regexp (car item))
(tag (cdr item)))
(message (format "%s : %s" regexp tag))
;; HOW TO CALL font-lock-add-keywords with regexp and tag ?
))
Update
I've tried using mapcar, but the (cdr item)
does not evaluate to the actual tag content.
(defun f (item)
`( ,(concat "\\(" (car item) "\\)") 1
`(face nil display (cdr item))))
(mapcar 'f tags)