Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split to each packages (ivy, helm and polymode) #386

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ Most of the configuration below isn't necessary, but showcases some options.
org-brain-file-entries-use-title nil))

;; Allows you to edit entries directly from org-brain-visualize
(use-package polymode
:config
(add-hook 'org-brain-visualize-mode-hook #'org-brain-polymode))
(use-package org-brain-polymode
:straight nil
:hook (org-brain-visualize-mode . org-brain-polymode))

(use-package org-brain-helm
:straight nil
:after helm)

(use-package org-brain-ivy
:straight nil
:after ivy)
#+END_SRC

1. =org-brain= requires Emacs 25 and org-mode 9. These need to be part of your
Expand Down
104 changes: 104 additions & 0 deletions org-brain-helm.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
;;; org-brain-helm.el --- Org-mode concept mapping -*- lexical-binding: t; -*-

;; Copyright (C) 2017--2020 Erik Sjöstrand
;; MIT License

;; Author: Erik Sjöstrand <[email protected]>
;; URL: http://github.com/Kungsgeten/org-brain
;; Keywords: outlines hypermedia
;; Package-Requires: ((emacs "25.1") (org "9.2"))
;; Version: 0.94

;;; Commentary:

;; org-brain implements a variant of concept mapping with org-mode, it is
;; inspired by The Brain software (http://thebrain.com). An org-brain is a
;; network of org-mode entries, where each entry is a file or a headline, and
;; you can get a visual overview of the relationships between the entries:
;; parents, children, siblings and friends. This visual overview can also be
;; used to browse your entries. You can think of entries as nodes in a mind map,
;; or pages in a wiki.

;; All org files put into your `org-brain-path' directory will be considered
;; entries in your org-brain. Headlines with an ID property in your entry file(s)
;; are also considered as entries.

;; Use `org-brain-visualize' to see the relationships between entries, quickly
;; add parents/children/friends/pins to an entry, and open them for editing.

;;; Code:

(require 'helm)
(require 'org-brain)

;;;; Helm integration

(defun helm-brain--add-children (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain-add-relationship
(org-brain-entry-at-pt) (or (org-brain-entry-from-id candidate) candidate)))
(org-brain--revert-if-visualizing))

(defun helm-brain--add-parents (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain-add-relationship
(or (org-brain-entry-from-id candidate) candidate) (org-brain-entry-at-pt)))
(org-brain--revert-if-visualizing))

(defun helm-brain--add-friends (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain--internal-add-friendship
(org-brain-entry-at-pt) (or (org-brain-entry-from-id candidate) candidate)))
(org-brain--revert-if-visualizing))

(defun helm-brain--delete-entries (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain-delete-entry (or (org-brain-entry-from-id candidate) candidate))))

(defun helm-brain--archive (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain-archive (or (org-brain-entry-from-id candidate) candidate))))

(defun helm-brain--select (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain-select (or (org-brain-entry-from-id candidate) candidate) 1)))

(defun helm-brain--unselect (_c)
(dolist (candidate (helm-marked-candidates))
(org-brain-select (or (org-brain-entry-from-id candidate) candidate) -1)))

(defvar helm-brain--actions
(helm-make-actions
"Visualize" (lambda (x)
(org-brain-visualize (or (org-brain-entry-from-id x) x)))
"Add children" 'helm-brain--add-children
"Add parents" 'helm-brain--add-parents
"Add friends" 'helm-brain--add-friends
"Delete" 'helm-brain--delete-entries
"Archive" 'helm-brain--archive
"Select" 'helm-brain--select
"Unselect" 'helm-brain--unselect))

(defvar helm-brain--source
(helm-make-source "Brain" 'helm-source-sync
:candidates #'org-brain--all-targets
:action 'helm-brain--actions))

(defvar helm-brain--fallback-source
(helm-make-source "New entry" 'helm-source-dummy
:action (helm-make-actions
"Visualize" (lambda (x)
(org-brain-visualize (org-brain-get-entry-from-title x)))
"Add children" 'helm-brain--add-children
"Add parents" 'helm-brain--add-parents
"Add friends" 'helm-brain--add-friends)))

(defun helm-brain ()
"Use `helm' to choose among your org-brain entries.
Provides actions for visualizing, adding/removing relations, etc.
Supports selecting multiple entries at once."
(interactive)
(helm :sources '(helm-brain--source helm-brain--fallback-source)))

(provide 'org-brain-helm)
;;; org-brain-helm.el ends here
95 changes: 95 additions & 0 deletions org-brain-ivy.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
;;; org-brain-ivy.el --- Org-mode concept mapping -*- lexical-binding: t; -*-

;; Copyright (C) 2017--2020 Erik Sjöstrand
;; MIT License

;; Author: Erik Sjöstrand <[email protected]>
;; URL: http://github.com/Kungsgeten/org-brain
;; Keywords: outlines hypermedia
;; Package-Requires: ((emacs "25.1") (org "9.2") (ivy "0.13.4"))
;; Version: 0.94

;;; Commentary:

;; org-brain implements a variant of concept mapping with org-mode, it is
;; inspired by The Brain software (http://thebrain.com). An org-brain is a
;; network of org-mode entries, where each entry is a file or a headline, and
;; you can get a visual overview of the relationships between the entries:
;; parents, children, siblings and friends. This visual overview can also be
;; used to browse your entries. You can think of entries as nodes in a mind map,
;; or pages in a wiki.

;; All org files put into your `org-brain-path' directory will be considered
;; entries in your org-brain. Headlines with an ID property in your entry file(s)
;; are also considered as entries.

;; Use `org-brain-visualize' to see the relationships between entries, quickly
;; add parents/children/friends/pins to an entry, and open them for editing.

;;; Code:

(require 'ivy)
(require 'org-brain)

;;;; Ivy integration

(defun counsel-brain ()
"Use Ivy to choose among your org-brain entries.
Provides actions for visualizing, adding/removing relations, etc."
(interactive)
(let ((targets (org-brain--all-targets)))
(ivy-read "Org-brain: "
targets
:action (lambda (x)
(org-brain-visualize
(if (stringp x)
(org-brain-get-entry-from-title x)
(or (org-brain-entry-from-id (cdr x))
(cdr x)))))
:preselect (ignore-errors
(org-brain-entry-name
(org-brain-entry-at-pt)))
:caller 'counsel-brain)))

(defun counsel-brain--add-child (child)
(org-brain-add-relationship (org-brain-entry-at-pt)
(or (org-brain-entry-from-id (cdr child))
(cdr child)))
(org-brain--revert-if-visualizing))

(defun counsel-brain--add-parent (parent)
(org-brain-add-relationship (or (org-brain-entry-from-id (cdr parent))
(cdr parent))
(org-brain-entry-at-pt))
(org-brain--revert-if-visualizing))

(defun counsel-brain--add-friend (friend)
(org-brain--internal-add-friendship (org-brain-entry-at-pt)
(or (org-brain-entry-from-id (cdr friend))
(cdr friend)))
(org-brain--revert-if-visualizing))

(defun counsel-brain--delete (x)
(org-brain-delete-entry (or (org-brain-entry-from-id (cdr x)) (cdr x))))

(defun counsel-brain--archive (x)
(org-brain-archive (or (org-brain-entry-from-id (cdr x)) (cdr x))))

(defun counsel-brain--select (x)
(org-brain-select (or (org-brain-entry-from-id (cdr x)) (cdr x)) 1))

(defun counsel-brain--unselect (x)
(org-brain-select (or (org-brain-entry-from-id (cdr x)) (cdr x)) -1))

(ivy-set-actions
'counsel-brain
'(("c" counsel-brain--add-child "add as child")
("p" counsel-brain--add-parent "add as parent")
("f" counsel-brain--add-friend "add as friend")
("d" counsel-brain--delete "delete")
("a" counsel-brain--archive "archive")
("s" counsel-brain--select "select")
("S" counsel-brain--unselect "unselect")))

(provide 'org-brain-ivy)
;;; org-brain-ivy.el ends here
77 changes: 77 additions & 0 deletions org-brain-polymode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
;;; org-brain-polymode.el --- Org-mode concept mapping -*- lexical-binding: t; -*-

;; Copyright (C) 2017--2020 Erik Sjöstrand
;; MIT License

;; Author: Erik Sjöstrand <[email protected]>
;; URL: http://github.com/Kungsgeten/org-brain
;; Keywords: outlines hypermedia
;; Package-Requires: ((emacs "25.1") (org "9.2") (polymode "0.2.2"))
;; Version: 0.94

;;; Commentary:

;; org-brain implements a variant of concept mapping with org-mode, it is
;; inspired by The Brain software (http://thebrain.com). An org-brain is a
;; network of org-mode entries, where each entry is a file or a headline, and
;; you can get a visual overview of the relationships between the entries:
;; parents, children, siblings and friends. This visual overview can also be
;; used to browse your entries. You can think of entries as nodes in a mind map,
;; or pages in a wiki.

;; All org files put into your `org-brain-path' directory will be considered
;; entries in your org-brain. Headlines with an ID property in your entry file(s)
;; are also considered as entries.

;; Use `org-brain-visualize' to see the relationships between entries, quickly
;; add parents/children/friends/pins to an entry, and open them for editing.

;;; Code:

(require 'polymode)
(require 'org-brain)

;;;; Polymode integration

;; This code has been adapted from Dustin Lacewell's project polybrain
;; Have a look at: https://github.com/dustinlacewell/polybrain.el/

(define-hostmode org-brain-poly-hostmode
:mode 'org-brain-visualize-mode)

(define-innermode org-brain-poly-innermode
:mode 'org-mode
:head-matcher "^[─-]\\{3\\} Entry [─-]+\n"
:tail-matcher "\\'"
:head-mode 'host
:tail-mode 'host)

(define-polymode org-brain-polymode
:hostmode 'org-brain-poly-hostmode
:innermodes '(org-brain-poly-innermode)
(setq-local polymode-move-these-vars-from-old-buffer
(delq 'buffer-read-only polymode-move-these-vars-from-old-buffer)))

(defun org-brain-polymode-save ()
"Save entry text to the entry's file."
(interactive)
(when (buffer-modified-p)
(let ((text (save-excursion
(goto-char org-brain--vis-entry-text-marker)
(end-of-line)
(buffer-substring (point) (point-max)))))
(find-file (org-brain-entry-path org-brain--vis-entry))
(seq-let (entry-min entry-max) (org-brain-text-positions org-brain--vis-entry)
(goto-char entry-min)
(delete-region entry-min entry-max)
(insert text)
(unless (looking-at-p "\n")
(insert "\n\n"))
(save-buffer)
(switch-to-buffer (other-buffer (current-buffer) 1))
(set-buffer-modified-p nil)))))

(define-key org-brain-polymode-map "\C-x\C-s" 'org-brain-polymode-save)

(provide 'org-brain-polymode)
;;; org-brain-polymode.el ends here
Loading