0

I created a highlighter for org-mode which worked great (pre orgmode 9.0). But now my customizations are being ignored...

Here is the excerpt from my init.el file:

;;; Create highlighter face
(defface my-highlight-face
   '((t (:inherit org-default :foreground "#000000" :background "#ffffe7")))
   "Face for highlighting text")
(defvar my-highlight1-face 'my-highlight1-face)

;; Add to list 
(setq org-emphasis-alist `(("*" bold)
                                 ("/" italic)
                                 ("_" underline)
                                 ("=" org-verbatim verbatim)
                                 ("~" org-code verbatim)
                                 ("+" ,(if (featurep 'xemacs) 'org-table '(:strike-through t)))
                                 ("!" my-highlight1-face verbatim)))

;;; Reload org to make it stick
(org-reload)

To check that this worked, I restart emacs and run M-x customize-variable > org-emphasis-alist. Scrolling down, I can see that my-highlight1-face has been added to the list:

screenshot of org-emphasis-alist

But opening a random org buffer and typing !text to highlight! does nothing.

What am I missing?

  • 1. Show the exact error message. 2. The ,(if...) won't be evaluated because you've hidden it inside quote - use backquote instead. – Drew Jan 20 '18 at 15:06
  • Thanks @Drew. I updated my code to use backquote and I just ran --debug-init. The ccomplete error message is posted above. – Adam Jan 20 '18 at 15:55
  • @Drew I have updated my original post. Turns out the error I was getting had no relevance. Fixed this and also swapped in backquotes but this still doesn't work. Please see revised above. Thanks! – Adam Jan 20 '18 at 20:38
  • The marker in your lisp code is a sharp sign while in the custom buffer it is an exclamation mark. How does this go together? As a general rule: Don't mix customization via customization interface and setting up options via setq. This can cause all sorts of confusion (on the software side and on the human side). – Tobias Jan 20 '18 at 20:45
  • I actually have 4 different highlight faces. For the sake of brevity I paired this down to 1 for stackexchange but failed to select the same face for the screenshot. All my changes were done via setq. I'll revise the code above to match the screenshot. – Adam Jan 20 '18 at 21:27
1

Okay, in the end, this post by Steven Pigeon, along with @Tobias' earlier post gave me the way forward. Here is the revised code.

;;; Create highlighter face for marking up text in org-mode
(defface font-lock-highlight-face
   '((t (:inherit org-default :foreground "#000000" :background "#ffffe7")))
   "Face for highlighting text")
(defvar font-lock-highlight-face 'font-lock-highlight-face)

;;; Add keywords
(defun add-highlight-keywords()
  "adds custom keywords for highlighting text in org-mode."
  ;
  (font-lock-add-keywords nil
    '(("\\(!\\)\\([^[:space:]][^\n\r\t]+[^[:space:]]\\)\\(!\\)" . 'font-lock-highlight-face )))
)
(add-hook 'org-mode-hook 'add-highlight-keywords)

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.