Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active December 28, 2024 21:26
Show Gist options
  • Save jdtsmith/d49eaaae852c5496a80e2489014bc41c to your computer and use it in GitHub Desktop.
Save jdtsmith/d49eaaae852c5496a80e2489014bc41c to your computer and use it in GitHub Desktop.
org cite "processor" example
(when-let ((basic (org-cite-get-processor 'basic))
(activate (org-cite-processor-activate basic)))
(org-cite-register-processor
'activate-hide-@cite :activate
(lambda (citation)
"Activate CITATION, then make leadup to first ref invisible."
(funcall activate citation)
(when-let ((first-ref (car (org-cite-get-references citation)))
(beg (car (org-cite-boundaries citation))))
(put-text-property (1+ beg) (car (org-cite-key-boundaries first-ref))
'invisible t)))))
@jdtsmith
Copy link
Author

jdtsmith commented Dec 26, 2024

This shows an example of working directly with org-cite processors, which control fontification, activation, export, etc. for org citations. The idea is to register a new citation "processor" that alters behavior.

This example works by duplicating the basic citation processor (see oc-basic.el), and then wrapping the function in basic's activate slot to make the text from the start of the citation to its first keyword invisible. The new processor is called activate-hide-@cite.

After running the above, you can use it in a hook like:

(when (org-cite-get-processor 'activate-hide-@cite)
  (setq-local org-cite-activate-processor 'activate-hide-@cite)
  (face-remap-add-relative 'org-cite-key '(:inherit shadow)))

for a more toned-down org citation style in the buffer.

Idea from this blog post. The advantage over a regexp-search/overlay approach is it works with font-lock, is much faster for long documents, updates during live editing, etc.

@jdtsmith
Copy link
Author

jdtsmith commented Dec 28, 2024

Update: simplified to set only the activate slot of the new processor, since that is all that is used from the org-cite-activate-processor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment