@@ 0,0 1,59 @@
+;;; pubs-follow.el --- open cite links in org with pubs -*- lexical-binding: t; -*-
+
+;;;; This package provides a citation processor that only has a follow function
+;;;; that opens the document associated to a citekey within emacs.
+
+(require 'oc)
+(require 'oc-basic)
+
+(defcustom pubs-follow/library-directory
+ "/home/USER/docs/library/"
+ "Directory where the library resides")
+
+(defun pubs-follow/get-documents-directory ()
+ "Get the directory where pubs' documents live"
+ (concat (file-name-as-directory pubs-follow/library-directory) "doc"))
+
+
+(defun pubs-follow/get-documents (citekey)
+ "Get the documents matching a `CITEKEY'"
+ (let ((doc-dir (pubs-follow/get-documents-directory)))
+ (directory-files doc-dir t
+ (rx bol (literal citekey) "."))))
+
+(defun pubs-follow/open-document (citekey)
+ "Open a document matching the `CITEKEY'"
+ (let ((results (pubs-follow/get-documents citekey)))
+ (pcase (length results)
+ (0 (user-error "No documents match key."))
+ (1 (find-file (car results)))
+ (_ (user-error "Too many documents match key.")))))
+
+(defun pubs-follow/goto (datum _)
+ "Follow citation or citation datum, open the corresponding document."
+ (let* ((key
+ (if (eq 'citation-reference (org-element-type datum))
+ (org-element-property :key datum)
+ (pcase (org-cite-get-references datum t)
+ (`(,key) key)
+ (keys
+ (or (completing-read "Select citation key: " keys nil t)
+ (user-error "Aborted")))))))
+ (pubs-follow/open-document key)))
+
+;;;###autoload
+(defun pubs/open-document ()
+ "Open a pubs' document"
+ (interactive)
+ (pubs-follow/open-document (org-cite-basic--complete-key)))
+
+
+;;; Register processor
+(org-cite-register-processor 'pubs-follow
+ :activate nil
+ :export-bibliography nil
+ :export-citation nil
+ :export-finalizer nil
+ :follow #'pubs-follow/goto
+ :insert nil
+ :cite-styles nil)