1

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
wing
  • 123
  • 7
  • 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 Answers3

7

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))))
wing
  • 123
  • 7
  • 1
    The first answer was pedantic and abstruse, plus led to no obvious solution. This… this works perfectly in the `.emacs`. Great. – ijoseph Feb 04 '19 at 02:44
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.

NickD
  • 27,023
  • 3
  • 23
  • 42
  • 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

As a comment to the answer by wing (but not enough reputation points to comment), org-emphasis-alist is a customizable variable so that it can be customized via the customization menu. It is found in the Org group under the subgroup Org Appearance. Modifications applied via the customization menu should be persistent over sessions.

dalanicolai
  • 6,108
  • 7
  • 23