0

I read here that I could colorize the markup in my org-mode configuration, so I searched, and here I found an example.

The problem is when I append this code, as the answer suggests, to my .emacs:

(add-to-list 'org-emphasis-alist '("*" (:foreground "red")))

When I restart Emacs, I get this error:

Warning (initialization): An error occurred while loading ‘c:/Users/username/.emacs’:

Symbol's value as variable is void: org-emphasis-alist

To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the ‘--debug-init’ option to view a complete error backtrace.

  • What happens when if you start Emacs using emacs -Q (no init file), and then you do M-: (add-to-list 'org-emphasis-alist '("*" (:foreground "red"))), that is, the same code. If that does what you want then the problem is in the rest of your init file - the part that you appended this code to (and which you don't show). – Drew Aug 12 '18 at 20:16
  • @Drew Doing what you suggest i've got an error, that i'm gonna to split in two comments because it's too long: Debugger entered--Lisp error: (void-variable org-emphasis-alist) (member '("*" (:foreground "red")) org-emphasis-alist) (if (member '("*" (:foreground "red")) org-emphasis-alist) org-emphasis-alist (setq org-emphasis-alist (cons '("*" (:foreground "red")) org-emphasis-alist))) eval((if (member '("*" (:foreground "red")) org-emphasis-alist) org-emphasis-alist – wing Aug 13 '18 at 13:23
  • (setq org-emphasis-alist (cons '("*" (:foreground "red")) org-emphasis-alist))) nil) eval-expression((add-to-list 'org-emphasis-alist '("*" (:foreground "red"))) nil nil 127) funcall-interactively(eval-expression (add-to-list 'org-emphasis-alist '("*" (:foreground "red"))) nil nil 127) call-interactively(eval-expression nil nil) command-execute(eval-expression) – wing Aug 13 '18 at 13:23
  • 1
    Yes, well you need to M-x org-mode first. Library Org (or whatever library defines org-emphasis-list) needs to be loaded before you can refer to that variable. – Drew Aug 13 '18 at 14:46
  • yep, after a few tries i got it how to do, but there's another problem ^^ see the comment to the answer. I can't make a string delimitated by * at the same time bold and red; it's bold or it's red @Drew – wing Aug 13 '18 at 15:01
3

In general, you can only add-to-list to an already defined variable. The variable org-emphasis-alist is not defined until org-mode is loaded. So you need to delay the add-to-list until after it is loaded: just move it to (say) the end of your init file (assuming that somewhere in your init file, org-mode is loaded).

HOWEVER that is not going to work in this particular case, because org-emphasis-alist is a special variable: (re)setting it has no effect until the new value has been used to recalculate a bunch of stuff that depends on it. So you either need to figure out how to do these recalculations, so you can do them by hand after modifying the variable in your init file (not recommended) or you have to find an easier way.

The easiest way to deal with this case is to use the customization mechanism: customize the value of org-emphasis-alist, save it (for this and future sessions) and you should be all set. The customization mechanism takes care of recalculating the extra stuff.

  • ok, understood, works but...how i can make a string delimitaded by * (e.g. *something*) bold and red? something like this doesn't works (setq org-emphasis-alist '(("*" bold :foreground "red") ("/" italic) ("_" underline) ("=" org-verbatim verbatim) ("~" org-code verbatim) ("+" (:strike-through t)))) – wing Aug 13 '18 at 14:37
1

EUREKA! To everyone struggling like me to obtain an "easy to make highlight style", Make something like this:

(setq org-emphasis-alist
  '(("*" (bold :foreground "Orange" ))
    ("/" italic)
    ("_" underline)
    ("=" (:background "maroon" :foreground "white"))
    ("~" (:background "deep sky blue" :foreground "MidnightBlue"))
    ("+" (:strike-through t))))

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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