5

This might be interersting: For quite some time I used the code block below in my custom.el to make my own emphasis definitions. This worked up to org 9, I think. Then all of a sudden when I needed it again it stopped working. I found out that it had nothing to do with my config. So I filed a bug report. Then Nicolas Goaziou told me that it even if it worked in the past it is not supported meaning they won't fix it. He gave me the advice below, but without any knowlege of coding and lisp that ain't helping. What I need is quite simple. I want to define a character before and after a word or line and the defined face should be applied.Like: %Exampletext Bla Bla% Based on my codeblock this should turn into "org-habit-alert-face" which is more or less yellow. The % character should be invisible when set. Like ** for bold. So can anyone with knowlege of lisp help me out here?

My custom-set-variables block that worked before:

 '(org-emphasis-alist
   (quote
    (
     ("!" org-habit-overdue-face)
     ("%" org-habit-alert-face)
     ("*" bold)
     ("/" italic)
     ("_" underline)
     ("=" org-verbatim verbatim)
     ("~" org-code verbatim)
     ("+" (:strike-through t))
     )))

Advice by Nicolas Goaziou:

You may want to tweak font-lock related variables, e.g., `org-font-lock-hook' to achieve that effect.

8
  • It still works in org-mode 9.0.5. It is very strange that they don't support it since it exists as customization in the original source file org.el of orgmode 9.0.5.
    – Tobias
    Sep 20 '17 at 5:15
  • Oh, it is already too late to edit my former comment. I wanted to be more specific about what works in org-mode 9.0.5: For testing I did just customize org-emphasis-alist. I did not fiddle around directly with custom-set-variables.
    – Tobias
    Sep 20 '17 at 5:25
  • Not so strange. Check out my case at http://lists.gnu.org/archive/html/emacs-orgmode/2017-09/msg00455.html He said that it is intended to change the existing emphasis, not to add new. Well I can't say for sure when it broke exactly. I think 9.1 broke it, it is definitivly broken in 9.1.1. That's what you get when you keep up with the bleeding edge.
    – Jens Lange
    Sep 20 '17 at 10:12
  • 1
    If they don't want items added to org-emphasis-alist they shouldn't use the repeat customization type which allows insertion and deletion. Furthermore, they should add a note about this restriction in the doc string of org-emphasis-alist. Maybe, you can give a follow-up in the bug-report about that. Nevertheless, I don't move a bit from my statement that it is very strange that this option does not work as sanely expected. It would be easy to construct a regexp for the parser from that list and work with that in the library. One shouldn't annoy ones users!
    – Tobias
    Sep 20 '17 at 10:24
  • 1
    @avv the idea was to have extra emphasis markers, the * is a pre-existing one.
    – Jens Lange
    Jul 4 '20 at 0:02
7

I don't really have org-mode 9.1.1 installed. In org-mode 9.0.5 the following works:

(require 'org-habit nil t)

(defun org-add-my-extra-fonts ()
  "Add alert and overdue fonts."
  (add-to-list 'org-font-lock-extra-keywords '("\\(!\\)\\([^\n\r\t]+\\)\\(!\\)" (1 '(face org-habit-alert-face invisible t)) (2 'org-habit-alert-face t) (3 '(face org-habit-alert-face invisible t))) t)
  (add-to-list 'org-font-lock-extra-keywords '("\\(%\\)\\([^\n\r\t]+\\)\\(%\\)" (1 '(face org-habit-overdue-face invisible t)) (2 'org-habit-overdue-face t) (3 '(face org-habit-overdue-face invisible t))) t))

(add-hook 'org-font-lock-set-keywords-hook #'org-add-my-extra-fonts)
5
  • That worked, thanks. I'll add your remarks above to the case, maybe they change their mind about that. I really would like to see the old functionality to come back. As a non programmer I like to avoid any extra functions that I have to maintain myself.
    – Jens Lange
    Sep 20 '17 at 14:03
  • A minor point: should we use the non-greedy versions instead, e.g. use "\\(!\\)\\([^\n\r\t]+?\\)\\(!\\)" rather than "\\(!\\)\\([^\n\r\t]+\\)\\(!\\)"?
    – Jason
    May 27 '20 at 15:43
  • Does this customization still work in export? I tried changing the = verbatim to ```, the font-lock trick works inside emacs, but not when exported html or pdf.
    – Jason
    May 27 '20 at 21:40
  • @Jason, I used it for some time but it broke at some point. In the meantime I used the pre-existing emphasis markers verbatim and code with a custom face definition. I came back after reading your comment, but a try failed again, at least with my full blown config, maybe it works on a vanilla config, might try later, but I assume the script needs an update.
    – Jens Lange
    Jul 4 '20 at 0:07
  • Just tested on vanilla emacs. The code in the answer still works. I need to find the bug in my config. Export does seem to work on pre-existing modifiers.
    – Jens Lange
    Jul 4 '20 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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