Skip to content

Instantly share code, notes, and snippets.

@shrysr
Created March 16, 2020 19:05
Show Gist options
  • Save shrysr/8d773b3da3f3081fa16be5960a486903 to your computer and use it in GitHub Desktop.
Save shrysr/8d773b3da3f3081fa16be5960a486903 to your computer and use it in GitHub Desktop.

deflayer

This will help with different settings for different brains. Eventually, I hope I can use the same settings.

(use-package deflayer
  :straight (deflayer :type git :host github :repo "dustinlacewell/deflayer.el")
  :config
  (require 'deflayer))

(deflayer sr-brain org-brain
  ((org-brain-path "~/my_org/brain/")))

(deflayer episteme org-brain
  ((org-brain-path "~/my_projects/episteme/brain/")))

org-brain

(use-package org-brain
  :straight (org-brain :type git :host github :repo "dustinlacewell/org-brain")
  :after org
  :config
  ;; this unbinds all default org-brain bindings
  (setcdr org-brain-visualize-mode-map nil)
  (setq
   ;; org-brain-path (f-join path-of-this-repo "brain")
   org-brain-visualize-default-choices 'root
   org-brain-include-file-entries t
   org-brain-scan-for-header-entries nil
   org-brain-file-entries-use-title nil
   org-brain-show-full-entry t
   org-brain-show-text t
   org-id-track-globally t
   org-brain-vis-current-title-append-functions '(org-brain-entry-tags-string)
   org-brain-title-max-length 24))

Navigation Helpers

(defun my/org-brain-visualize-parent ()
  (interactive)
  (when (org-brain-parents (org-brain-entry-at-pt)) (org-brain-visualize-parent (org-brain-entry-at-pt))))

(defun my/org-brain-visualize-child (entry &optional all)
  (interactive (list (org-brain-entry-at-pt)))
  (when (org-brain-children entry)
    (let* ((entries (if all (org-brain-children entry)
                    (org-brain--linked-property-entries
                     entry org-brain-children-property-name)))
         (child (cond
                 ((equal 1 (length entries)) (car-safe entries))
                 ((not entries) (error (concat entry " has no children")))
                 (t (org-brain-choose-entry "Goto child: " entries nil t)))))
      (org-brain-visualize child))))

(defun my/next-button-with-category (category)
  (let ((original-point (point))
        (first-result (text-property-search-forward 'brain-category category t t)))
    (when first-result
          (goto-char (prop-match-beginning first-result)))
    (when (eq original-point (point))
      (beginning-of-buffer)
      (let ((second-result (text-property-search-forward 'brain-category category t t)))
        (when second-result
          (goto-char (prop-match-beginning second-result))))
      (when (eq 0 (point))
        (goto-char original-point))
      )
    ))

(defun my/previous-button-with-category (category)
  (let ((result (text-property-search-backwards 'brain-category category nil t)))))

(defun my/next-brain-child ()
  (interactive)
  (my/next-button-with-category 'child))

(defun my/next-brain-history ()
  (interactive)
  (my/next-button-with-category 'history))

(defun my/avy-brain-jump (category)
  (avy-jump "\\<." :pred (lambda () (and (eq category (get-text-property (point) 'brain-category))
                                    (eq (- (point) 1) (button-start (button-at (point))))))
            :action (lambda (p) (goto-char (+ 1 p)) (push-button))))

(defun my/avy-brain-jump-history ()
  (interactive)
  (my/avy-brain-jump 'history))

(defun my/avy-brain-jump-child ()
  (interactive)
  (my/avy-brain-jump 'child))

(defun my/avy-brain-jump-parent ()
  (interactive)
  (my/avy-brain-jump 'parent))

(defun my/avy-brain-jump-friend ()
  (interactive)
  (my/avy-brain-jump 'friend))

(defun my/avy-brain-jump-sibling ()
  (interactive)
  (my/avy-brain-jump 'sibling))

polybrain

(use-package polybrain
  :defer nil
  :straight (polybrain :type git :host github :repo "dustinlacewell/polybrain")
  :bind (:map org-brain-visualize-mode-map
         ("m" . org-brain-visualize-mind-map)
         ("<tab>" . backward-button)
         ("S-<tab>" . forward-button)
         ("DEL" . org-brain-visualize-back)
         ("r" . org-brain-open-resource)
         ("v" . org-brain-visualize)

         ("i" . org-brain-pin)
         ("T" . org-brain-set-title)
         ("t" . org-brain-set-tags)
         ("d" . org-brain-delete-entry)
         ("R" . org-brain-visualize-add-resource)
         ("o" . org-brain-goto-current)
         ("O" . org-brain-goto)

         ("c" . org-brain-add-child)
         ("C" . org-brain-remove-child)

         ("p" . org-brain-add-parent)
         ("P" . org-brain-remove-parent)

         ("f" . org-brain-add-friendship)
         ("F" . org-brain-remove-friendship)

         ("e" . org-brain-annotate-edge)


         ("M-p" . my/avy-brain-jump-parent)
         ("M-c" . my/avy-brain-jump-child)
         ("M-s" . my/avy-brain-jump-sibling)
         ("M-f" . my/avy-brain-jump-friend)
         ("M-h" . my/avy-brain-jump-history)

         :map poly-brain-mode-map
         ("C-x C-s" . polybrain-save)
         ("<M-SPC>" . polybrain-switch)))

(require 'polybrain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment