;;; coorgi-client.el --- A collaborative org document sync client. -*- lexical-binding: t; -*- ;; Copyright (C) 2022 Grant Shangreaux ;; Author: Grant Shangreaux ;; Maintainer: Grant Shangreaux ;; 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 . (require 'cl-lib) (defvar coorgi-properties '(:COORGI-KEY :COORGI-LAST-MODIFIED :COORGI-LAST-MODIFIED-BY :COORGI-VERSION) "List of properties the Coorgi server cares about.") (defun coorgi--find-headline (headline 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 headline)) hl))))) (defun coorgi--find-property-drawer (headline) (caddr (caddr headline))) (defun coorgify-at-point () (interactive) (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