I have a function that gathers strings that looks like these:
Example #1:
:event:lawlist:HIGH:misc:
Example #2:
:LOW:
Example #3:
:MEDIUM:task:george:
I created a monstrosity of a snippet that breaks the string down into various sub-components, adds text properties to each component, and then reconstructs the new string.
Q: Is there a more sophisticated way to do this project?
(let* (
new-list
(string ":event:lawlist:HIGH:misc:")
(lst (delete "" (split-string string ":")))
(separator (propertize ":" 'face '(:foreground "cyan"))) )
(dolist (e lst)
(put-text-property 0 (length e) 'face
(cond
((string= e "event")
'(:foreground "red"))
((string= e "lawlist")
'(:foreground "blue"))
((string= e "HIGH")
'(:foreground "yellow"))
(t
'default))
e)
(push e new-list))
(concat separator (mapconcat 'identity (reverse new-list) separator) separator))
org-mode
tags? Can you useorg-tag-faces
for this?org-mode
. Here is a link to an older version of the regexp and function that I am using stackoverflow.com/a/20960301/2112489 I would prefer to operate on strings, instead of the buffer for this particular project. I realize the popular method is to use(while (re-search-forward ...)
, but this project is different.(org-font-lock-add-tag-faces (point-max))
is a means of accomplishing the end goal (but it is not an answer to this question). It operates on the buffer, as @Drew is suggesting. I haven't found an example inorg-mode
that operates on strings. My snippet works, but it's just not very fancy -- I thought perhaps there were a few functions that I am not aware of that permits walking a string with delimiters or regexp to add text properties. In fact, I'd be rather surprised if such a function does not exist already.