1

I wish to map the text properties onto a list and them insert them on a new buffer. For some reason the following snippet doesn't work. I've used the -map utility from dash.el package for the map.

    (-map
 (lambda (x) (insert (propertize "a"
                     'font-lock-face
                     '(:foreground x))))

 '("red" "green" "orange"))

I wish to achieve something like this

enter image description here

Drew
  • 75,699
  • 9
  • 109
  • 225

1 Answers1

1

I am not familiar with using the dash library, but the problem likely has to do with using a single quote for the list of face properties instead of using a backtick/comma combination.

(mapc
  (lambda (x) (insert (propertize "a" 'face `(:foreground ,x))))
  '("red" "green" "orange"))

Here is an alternative to the backtick/comma list format, which uses the function list:

(mapc
  (lambda (x) (insert (propertize "a" 'face (list :foreground x))))
  '("red" "green" "orange"))

I have not delved into the usages of the font-lock-face property described in the manual, so I just used face for this example since I am more familiar with it. https://www.gnu.org/software/emacs/manual/html_node/elisp/Special-Properties.html#Special-Properties


Here are links to the manual for the quote versus the backquote:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Quoting.html#Quoting

https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html#Backquote

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • `font-lock-face` is the same as `face` but is to be used when `font-lock-mode` is on, as `face` is ignored (elisp manual 22.6.6 https://www.gnu.org/software/emacs/manual/html_node/elisp/Precalculated-Fontification.html#Precalculated-Fontification) – JeanPierre Nov 27 '16 at 13:43
  • See also http://emacs.stackexchange.com/questions/7481/how-to-evaluate-the-variables-before-adding-them-to-a-list – npostavs Dec 22 '16 at 15:02