0

I have an issue with org-roam graph https://github.com/org-roam/org-roam/issues/2427 .

How do I write my config so that I do not have to patch the org roam code each time the org-roam gets update or I move my config to another machine?

I do not understand advising functions. I need an example. https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html

2

1 Answer 1

0

I needed the :override option in advice-add.

;;; fix graph drawing

(defun org-roam-graph--format-node-fix (node type)
  "Return a graphviz NODE with TYPE.
Handles both Org-roam nodes, and string nodes (e.g. urls)."
  (let (node-id node-properties)
    (if (org-roam-node-p node)
        (let* ((title (org-roam-quote-string (org-roam-node-title node)))
               (shortened-title
                (org-roam-quote-string
                 (pcase org-roam-graph-shorten-titles
                   (`truncate (truncate-string-to-width title org-roam-graph-max-title-length nil nil "..."))
                   (`wrap (org-roam-word-wrap org-roam-graph-max-title-length title))
                   (_ title)))))
          (setq node-id (org-roam-node-id node)
                node-properties `(("label"   . ,shortened-title)
                                  ("URL"     . ,(funcall org-roam-graph-link-builder node))
                                  ("tooltip" . ,(xml-escape-string title)))))
      (setq node-id node
            node-properties (append `(("label" . ,(concat type ":" ;node
                                                          (truncate-string-to-width node 15)
                                                          )))
                                    (when (member type (list "http" "https"))
                                      `(("URL" . ,(xml-escape-string (concat type ":" node))))))))
    (format "\"%s\" [%s];\n"
            node-id
            (mapconcat (lambda (n)
                         (org-roam-graph--dot-option n nil "\""))
                       (append (cdr (assoc type org-roam-graph-node-extra-config))
                               node-properties) ","))))

;;; the advice I need
(advice-add 'org-roam-graph--format-node
            :override
            #'org-roam-graph--format-node-fix)
 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.