Error when opening ROAM_REFS cite link

I get an Error (org-mode-hook): Error running hook "org-fancy-priorities-mode" because: (end-of-buffer) when clicking on a org-ref cite: link after the ROAM_REFS header.

cite: links elsewhere in the .org document works as expected, opening up a menu to choose from.

Wonder what is the cause of the error?

Debug Trace:

Debugger entered--Lisp error: (doom-hook-error org-fancy-priorities-mode (end-of-buffer))
  signal(doom-hook-error (org-fancy-priorities-mode (end-of-buffer)))
  (condition-case e (funcall hook) ((debug error) (signal 'doom-hook-error (list hook e))))
  doom-run-hook(org-fancy-priorities-mode)
  run-hook-wrapped(doom-run-hook org-fancy-priorities-mode)
  (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car (cdr e))) (symbol-name (car (cdr e))) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e)))))
  (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car ...)) (symbol-name (car ...)) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--)))
  (while --dolist-tail-- (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp ...) (symbol-name ...) (car ...)) (car (cdr ...)))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--))))
  (let ((--dolist-tail-- hooks)) (while --dolist-tail-- (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if ... ... ...) (car ...))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  doom-run-hooks(change-major-mode-after-body-hook text-mode-hook outline-mode-hook org-mode-hook)
  apply(doom-run-hooks (change-major-mode-after-body-hook text-mode-hook outline-mode-hook org-mode-hook))
  run-hooks(change-major-mode-after-body-hook text-mode-hook outline-mode-hook org-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook text-mode-hook outline-mode-hook org-mode-hook))
  run-mode-hooks(org-mode-hook)
  org-mode()
  org-link-open-from-string("cite:林素英_郭店服喪思想_2003")
  org-open-at-point-global()
  funcall-interactively(org-open-at-point-global)
  call-interactively(org-open-at-point-global)
  org-open-at-point()
  org-open-at-mouse((mouse-2 (#<window 16 on 林素英_郭店服喪思想_2003.org> 85 (436 . 68) 189552908 nil 85 (28 . 2) nil (7 . 14) (26 . 34))))
  funcall-interactively(org-open-at-mouse (mouse-2 (#<window 16 on 林素英_郭店服喪思想_2003.org> 85 (436 . 68) 189552908 nil 85 (28 . 2) nil (7 . 14) (26 . 34))))
  call-interactively(org-open-at-mouse nil nil)
  command-execute(org-open-at-mouse)

The cause of the error is org-fancy-priorities-mode.

Below is a rough sketch of what happens when you try to open a link from a property drawer. It does not necessarily need to be a cite:link, just any link.

  1. org-open-at-point parses the element at point and recognizes it’s within a node-property element
  2. org-open-at-point does not open links contained within the node-property directly but delegates the task to org-open-at-point-global
  3. org-open-at-point-global detects that the point is on a valid link and pushes the raw unparsed link string to org-link-open-from-string for further processing
  4. org-link-open-from-string takes the string, inserts it into a temporary buffer and calls org-mode in that buffer.
  5. When org-mode is called in the temporary buffer, various hook functions registered with org-mode are called. Among those functions is org-fancy-priorities-mode.
  6. org-fancy-priorities-mode attempts to inject its functionality into font-lock and this is where the end-of-buffer error happens.

I didn’t investigate in detail of how the error is produced exactly. It is rather complicated. In general, it is related to the edge case that org-mode needs to be initialized in a temporary buffer and org-fancy-priorities-mode does not account for this edge case. This may be considered a bug in org-fancy-priorities package. It may also be considered a bug in Org-mode that leads to such situations in the first place. Org-fancy-priorities is not the only package that suffers from it.

Why doesn’t this happen when you open a link from anywhere else? This is a rough sketch of what happens in such a case:

  1. org-open-at-point parses the element at point and recognizes it’s within a link element
  2. org-open-at-point calls org-link-open feeding it all the necessary information about the link
  3. org-link-open opens the link directly. It does not need to do additional parsing and therefore does not need a temporary buffer, hence the above edge case situation never arises.
1 Like