diff options
-rw-r--r-- | coorgi-client.el | 63 | ||||
-rw-r--r-- | coorgi-client.org | 7 |
2 files changed, 68 insertions, 2 deletions
diff --git a/coorgi-client.el b/coorgi-client.el new file mode 100644 index 0000000..5f296c7 --- /dev/null +++ b/coorgi-client.el @@ -0,0 +1,63 @@ +;;; coorgi-client.el --- A collaborative org document sync client. -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Grant Shangreaux + +;; Author: Grant Shangreaux <shoshin@cicadas.surf> +;; Maintainer: Grant Shangreaux <shoshin@cicadas.surf> +;; Created: 11 Nov 2022 +;; Keywords: org sync collaborative +;; URL: https://cicadas.surf/cgit/coorgi-client.git + +;; This file is not part of GNU Emacs. + +;; This file is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this file. If not, see <https://www.gnu.org/licenses/>. + +(require 'cl-lib) + +(defvar coorgi-properties '(:COORGI-KEY + :COORGI-LAST-MODIFIED + :COORGI-LAST-MODIFIED-BY + :COORGI-VERSION) + "List of properties coorgi cares about.") + +(defun coorgi--find-heading (heading org-data) + (car (org-element-map org-data 'headline + (lambda (hl) + (when (string-equal (org-element-property :raw-value hl) + (org-element-property :raw-value heading)) + hl))))) + +(defun coorgify-at-point () + (save-excursion + (let* ((current-element (org-element-at-point)) + (entry (if (not (equal (car current-element) 'heading)) + (progn (org-up-heading-safe) + (org-element-at-point)) + current-element)) + (parsed (print (org-element-parse-buffer))) + (props (org-element--get-node-properties)) + (non-coorgi-props (cl-loop for (key value) on props by #'cddr + unless (member key coorgi-properties) + append (list key value))) + (content-bounds (cons (progn (org-down-element) (org-forward-element) (point)) (plist-get (cadr entry) :contents-end)))) + `( type entry + headline ,(plist-get (cadr entry) :title) + version ,(string-to-number (plist-get props :COORGI-VERSION)) + last-modified-by ,(plist-get props :COORGI-LAST-MODIFIED-BY) + last-modified ,(plist-get props :COORGI-LAST-MODIFIED) + key ,(plist-get props :COORGI-KEY) + properties ,non-coorgi-props + contents ,(buffer-substring-no-properties (car content-bounds) (cdr content-bounds)))))) + +;;; coorgi-client.el ends here diff --git a/coorgi-client.org b/coorgi-client.org index 4844c31..119998f 100644 --- a/coorgi-client.org +++ b/coorgi-client.org @@ -10,8 +10,11 @@ <<license>> <<dependencies>> + <<defvars>> + <<coorgi--find-heading>> + <<coorgify-at-point>> ;;; coorgi-client.el ends here @@ -19,7 +22,7 @@ * dependencies -#+begin_src emacs-lisp :tangle yes :results none :noweb-ref dependencies +#+begin_src emacs-lisp :results silent :noweb-ref dependencies (require 'cl-lib) #+end_src @@ -33,7 +36,7 @@ This variable stores a list of upcased symbols that appear in the headline element's parsed property drawer. -#+begin_src emacs-lisp :tangle yes :results none +#+begin_src emacs-lisp (defvar coorgi-properties '(:COORGI-KEY :COORGI-LAST-MODIFIED :COORGI-LAST-MODIFIED-BY |