Skip to content

Instantly share code, notes, and snippets.

@borwickatuw
Created September 29, 2025 14:22
Show Gist options
  • Select an option

  • Save borwickatuw/098b0d3a3b599f3f00c069309e8fd462 to your computer and use it in GitHub Desktop.

Select an option

Save borwickatuw/098b0d3a3b599f3f00c069309e8fd462 to your computer and use it in GitHub Desktop.
;; org-roam-copy.el --- Copy `:COPY:` property from an org-roam node
;; Author: John Borwick <borwick@uw.edu>
;; This file is NOT part of GNU Emacs.
;; Copyright (c) 2025 University of Washington
;; All rights reserved.
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;; - Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;; - Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials provided
;; with the distribution.
;; - Neither the name of the University of Washington nor the names
;; of its contributors may be used to endorse or promote products
;; derived from this software without specific prior written
;; permission.
;; THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND
;; CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR
;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
;; USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
;; OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;; SUCH DAMAGE.
;;; Commentary:
;;
;; This builds on top of org-roam. It looks for a `:COPY:` property for a node, and copies that value into the buffer. Any `\\` is converted to newlines.
(defun org-roam-copy-convert-newlines (value)
(replace-regexp-in-string "\s*\\\\\\\\\s*" "\n" value))
(defun org-roam-copy-property (buf pos)
"Search BUF for a :COPY: property at POS and copy its value to the clipboard."
(with-current-buffer buf
(save-excursion
(goto-char pos)
(let ((value (org-entry-get nil "COPY" t))) ;; nil = current heading or file-level
(if value
(progn
(kill-new (org-roam-copy-convert-newlines value))
(message "Copied property value:\n%s" value))
(message "No :COPY: property found."))))))
(cl-defun org-roam-copy-node (&optional other-window initial-input filter-fn pred &key templates)
"Copy the :COPY: property from an Org-roam node, then return to the original buffer and point."
(interactive current-prefix-arg)
(let ((origin-buf (current-buffer))
(origin-point (point))
(node (org-roam-node-read initial-input filter-fn pred)))
(if-let ((file (org-roam-node-file node)))
(progn
(org-roam-node-visit node other-window)
(let ((buf (find-buffer-visiting file)))
(if buf
(org-roam-copy-property buf (org-roam-node-point node))
(message "Buffer not found for file: %s" file)))
;; Restore original buffer and point
(switch-to-buffer origin-buf)
(goto-char origin-point))
(error "Could not find node"))))
(provide 'org-roam-copy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment