changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > core / emacs/lib/graph.el

revision 652: 328e1ff73938
parent 651: af486e0a40c9
child 655: 65102f74d1ae
     1.1--- a/emacs/lib/graph.el	Sat Sep 14 22:13:06 2024 -0400
     1.2+++ b/emacs/lib/graph.el	Sat Sep 14 23:55:38 2024 -0400
     1.3@@ -111,24 +111,21 @@
     1.4 ;; See https://github.com/toshism/org-super-links/blob/develop/org-super-links.el
     1.5 (declare-function org-make-link-description-function "ext:org-mode")
     1.6 
     1.7-(defvar org-graph-edge-backlink-into-drawer "LINKS"
     1.8-  "Controls how/where to insert the backlinks.
     1.9-If non-nil a drawer will be created and backlinks inserted there.  The
    1.10-default is BACKLINKS.  If this is set to a string a drawer will be
    1.11-created using that string.  For example LINKS.  If nil backlinks will
    1.12-just be inserted under the heading.")
    1.13+(defvar org-graph-edge-drawer "LINKS"
    1.14+  "Controls how/where to insert edges. If nil edges will just be inserted
    1.15+under the heading.")
    1.16 
    1.17-(defvar org-graph-edge-backlink-prefix 'org-graph-edge-backlink-prefix-timestamp
    1.18-  "Prefix to insert before the backlink.
    1.19+(defvar org-graph-edge-prefix 'org-graph-edge-prefix-timestamp
    1.20+  "Prefix to insert before the edge.
    1.21 This can be a string, nil, or a function that takes no arguments and
    1.22 returns a string.
    1.23 
    1.24-Default is the function `org-graph-edge-backlink-prefix-timestamp'
    1.25+Default is the function `org-graph-edge-prefix-timestamp'
    1.26 which returns an inactive timestamp formatted according to the variable
    1.27 `org-time-stamp-formats' and a separator ' <- '.")
    1.28 
    1.29-(defvar org-graph-edge-backlink-postfix nil
    1.30-  "Postfix to insert after the backlink.
    1.31+(defvar org-graph-edge-postfix nil
    1.32+  "Postfix to insert after the edge.
    1.33 This can be a string, nil, or a function that takes no arguments and
    1.34 returns a string")
    1.35 
    1.36@@ -165,27 +162,12 @@
    1.37 
    1.38 Default is the variable `org-make-link-desciption-function'.")
    1.39 
    1.40-(defvar org-graph-edge-search-function
    1.41-  (cond ((require 'helm-org-ql nil 'no-error) "helm-org-ql")
    1.42-        ((require 'helm-org-rifle nil 'no-error) "helm-org-rifle")
    1.43-        (t 'org-graph-edge-get-location))
    1.44-  "The interface to use for finding target links.
    1.45-This can be a string with one of the values 'helm-org-ql',
    1.46-'helm-org-rifle', or a function.  If you provide a custom
    1.47+(defvar org-graph-edge-search-function 'org-graph-edge-get-location
    1.48+  "The interface to use for finding target links. If you provide a custom
    1.49 function it will be called with the `point` at the location the link
    1.50 should be inserted.  The only other requirement is that it should call
    1.51-the function `org-graph-edge--insert-link' with a marker to the target link.
    1.52-AKA the place you want the backlink.
    1.53-
    1.54-Using 'helm-org-ql' or 'helm-org-rifle' will also add a new
    1.55-action to the respective action menu.
    1.56-
    1.57-See the function `org-graph-edge-link-search-interface-ql' or for an example.
    1.58-
    1.59-Default is set based on currently installed packages.  In order of priority:
    1.60-- 'helm-org-ql'
    1.61-- 'helm-org-rifle'
    1.62-- `org-graph-edge-get-location'
    1.63+the function `org-graph-edge--insert-link' with a marker to the target
    1.64+link. AKA the place you want the edge.
    1.65 
    1.66 `org-graph-edge-get-location' internally uses `org-refile-get-location'.")
    1.67 
    1.68@@ -197,36 +179,27 @@
    1.69   "Hook called before storing the link on the backlink side.
    1.70 This is called with point in the heading of the backlink.")
    1.71 
    1.72-(declare-function org-graph-edge-org-ql-link-search-interface "ext:org-graph-edge-org-ql")
    1.73-(declare-function org-graph-edge-org-rifle-link-search-interface "ext:org-graph-edge-org-rifle")
    1.74-
    1.75 (defun org-graph-edge-get-location ()
    1.76   "Default for function `org-graph-edge-search-function' that reuses the `org-refile' machinery."
    1.77-  (let ((target (org-refile-get-location "Super Link")))
    1.78+  (let ((target (org-refile-get-location "Node")))
    1.79     (org-graph-edge--insert-link (set-marker (make-marker) (car (cdddr target))
    1.80                                  (get-file-buffer (car (cdr target)))))))
    1.81 
    1.82 (defun org-graph-edge-search-function ()
    1.83   "Call the search interface specified in variable `org-graph-edge-search-function'."
    1.84-  (cond ((string= org-graph-edge-search-function "helm-org-ql")
    1.85-         (require 'org-graph-edge-org-ql)
    1.86-         (org-graph-edge-org-ql-link-search-interface))
    1.87-        ((string= org-graph-edge-search-function "helm-org-rifle")
    1.88-         (require 'org-graph-edge-org-rifle)
    1.89-         (org-graph-edge-org-rifle-link-search-interface))
    1.90-        (t (funcall org-graph-edge-search-function))))
    1.91+  (funcall org-graph-edge-search-function))
    1.92 
    1.93-(defun org-graph-edge-backlink-prefix ()
    1.94-  "Return an appropriate string based on variable `org-graph-edge-backlink-prefix'."
    1.95-  (cond ((equal org-graph-edge-backlink-prefix nil) "")
    1.96-        ((stringp org-graph-edge-backlink-prefix) org-graph-edge-backlink-prefix)
    1.97-        (t (funcall org-graph-edge-backlink-prefix))))
    1.98+(defun org-graph-edge-prefix ()
    1.99+  "Return an appropriate string based on variable `org-graph-edge-prefix'."
   1.100+  (cond ((equal org-graph-edge-prefix nil) "")
   1.101+        ((stringp org-graph-edge-prefix) org-graph-edge-prefix)
   1.102+        (t (funcall org-graph-edge-prefix))))
   1.103 
   1.104-(defun org-graph-edge-backlink-postfix ()
   1.105-  "Return an appropriate string based on variable `org-graph-edge-backlink-postfix'."
   1.106-  (cond ((equal org-graph-edge-backlink-postfix nil) "\n")
   1.107-        ((stringp org-graph-edge-backlink-postfix) org-graph-edge-backlink-postfix)
   1.108-        (t (funcall org-graph-edge-backlink-postfix))))
   1.109+(defun org-graph-edge-postfix ()
   1.110+  "Return an appropriate string based on variable `org-graph-edge-postfix'."
   1.111+  (cond ((equal org-graph-edge-postfix nil) "\n")
   1.112+        ((stringp org-graph-edge-postfix) org-graph-edge-postfix)
   1.113+        (t (funcall org-graph-edge-postfix))))
   1.114 
   1.115 (defun org-graph-edge-link-prefix ()
   1.116   "Return an appropriate string based on variable `org-graph-edge-link-prefix'."
   1.117@@ -240,8 +213,8 @@
   1.118         ((stringp org-graph-edge-link-postfix) org-graph-edge-link-postfix)
   1.119         (t (funcall org-graph-edge-link-postfix))))
   1.120 
   1.121-(defun org-graph-edge-backlink-prefix-timestamp ()
   1.122-  "Return the default prefix string for a backlink.
   1.123+(defun org-graph-edge-prefix-timestamp ()
   1.124+  "Return the default prefix string for an edge.
   1.125 Inactive timestamp formatted according to `org-time-stamp-formats' and
   1.126 a separator ' <- '."
   1.127   (concat (format-time-string (org-time-stamp-format t t) (current-time))
   1.128@@ -256,19 +229,19 @@
   1.129           ((fboundp p) (funcall p link desc))
   1.130           (t desc))))
   1.131 
   1.132-(defun org-graph-edge-backlink-into-drawer ()
   1.133-  "Name of the backlink drawer, as a string, or nil.
   1.134+(defun org-graph-edge-drawer ()
   1.135+  "Name of the edge drawer, as a string, or nil.
   1.136 This is the value of variable
   1.137-`org-graph-edge-backlink-into-drawer'.  However, if the current
   1.138-entry has or inherits a BACKLINK_INTO_DRAWER property, it will be
   1.139+`org-graph-edge-drawer'.  However, if the current
   1.140+entry has or inherits a EDGE_DRAWER property, it will be
   1.141 used instead of the default value."
   1.142-  (let ((p (org-entry-get nil "BACKLINK_INTO_DRAWER" 'inherit t)))
   1.143+  (let ((p (org-entry-get nil "EDGE_DRAWER" 'inherit t)))
   1.144     (cond ((equal p "nil") nil)
   1.145-          ((equal p "t") "BACKLINKS")
   1.146+          ((equal p "t") "LINKS")
   1.147           ((stringp p) p)
   1.148-          (p "BACKLINKS")
   1.149-          ((stringp org-graph-edge-backlink-into-drawer) org-graph-edge-backlink-into-drawer)
   1.150-          (org-graph-edge-backlink-into-drawer "BACKLINKS"))))
   1.151+          (p "LINKS")
   1.152+          ((stringp org-graph-edge-drawer) org-graph-edge-drawer)
   1.153+          (org-graph-edge-drawer "LINKS"))))
   1.154 
   1.155 ;; delete related functions
   1.156 (defun org-graph-edge--find-link (id)
   1.157@@ -348,7 +321,7 @@
   1.158     (insert (org-graph-edge-link-postfix))))
   1.159 
   1.160 (defun org-graph-edge-link-prefix-timestamp ()
   1.161-  "Return the default prefix string for a backlink.
   1.162+  "Return the default prefix string for an edge.
   1.163 Inactive timestamp formatted according to `org-time-stamp-formats' and
   1.164 a separator ' -> '."
   1.165   (concat (format-time-string (org-time-stamp-format t t) (current-time))
   1.166@@ -374,16 +347,16 @@
   1.167 ;; /EXPERIMENTAL related into drawer
   1.168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   1.169 
   1.170-(defun org-graph-edge-insert-backlink (link desc)
   1.171-  "Insert backlink to LINK with DESC.
   1.172-Where the backlink is placed is determined by the variable `org-graph-edge-backlink-into-drawer'."
   1.173-  (let* ((org-log-into-drawer (org-graph-edge-backlink-into-drawer))
   1.174+(defun org-graph-edge-insert (link desc)
   1.175+  "Insert edge to LINK with DESC.
   1.176+Where the edge is placed is determined by the variable `org-graph-edge-drawer'."
   1.177+  (let* ((org-log-into-drawer (org-graph-edge-drawer))
   1.178          (description (org-graph-edge-default-description-formatter link desc))
   1.179          (beg (org-log-beginning t)))
   1.180     (goto-char beg)
   1.181-    (insert (org-graph-edge-backlink-prefix))
   1.182+    (insert (org-graph-edge-prefix))
   1.183     (insert (org-link-make-string link description))
   1.184-    (insert (org-graph-edge-backlink-postfix))
   1.185+    (insert (org-graph-edge-postfix))
   1.186     (org-indent-region beg (point))))
   1.187 
   1.188 (defun org-graph-edge-links-action (marker hooks)
   1.189@@ -405,8 +378,8 @@
   1.190     (cons link-ref description)))
   1.191 
   1.192 (defun org-graph-edge--insert-link (target &optional no-forward)
   1.193-  "Insert link to marker TARGET at current `point`, and create backlink to here.
   1.194-Only create backlinks in files in `org-mode' or a derived mode, otherwise just
   1.195+  "Insert link to marker TARGET at current `point`, and create edge to here.
   1.196+Only create edges in files in `org-mode' or a derived mode, otherwise just
   1.197 act like a normal link.
   1.198 
   1.199 If NO-FORWARD is non-nil skip creating the forward link.  Currently
   1.200@@ -422,7 +395,7 @@
   1.201           (widen) ;; buffer could be narrowed
   1.202           (goto-char (marker-position target))
   1.203           (when (derived-mode-p 'org-mode)
   1.204-            (org-graph-edge-insert-backlink (car source-formatted-link) (cdr source-formatted-link))))))
   1.205+            (org-graph-edge-insert (car source-formatted-link) (cdr source-formatted-link))))))
   1.206     (unless no-forward
   1.207       (with-current-buffer (marker-buffer source)
   1.208         (save-excursion
   1.209@@ -468,7 +441,7 @@
   1.210           (let ((link-element (org-graph-edge--find-link id)))
   1.211             (if link-element
   1.212                 (org-graph-edge--delete-link link-element)
   1.213-              (message "No backlink found. Deleting active only.")))))))
   1.214+              (message "No edge found. Deleting active only.")))))))
   1.215   (org-graph-edge--delete-link (org-element-context)))
   1.216 
   1.217 ;;;###autoload
   1.218@@ -500,7 +473,7 @@
   1.219 
   1.220 ;;;###autoload
   1.221 (defun org-graph-edge-insert-link ()
   1.222-  "Insert a super link from the register."
   1.223+  "Insert an edge link from the register."
   1.224   (interactive)
   1.225   (let* ((target (get-register ?^)))
   1.226     (if target