Kungsgeten / org-brain

Org-mode wiki + concept-mapping
MIT License
1.72k stars 102 forks source link

Multiple org brains #359

Closed borgauf closed 3 years ago

borgauf commented 3 years ago

I am having difficulty figuring out how to actually have multiple org brains. If I include in my config

(setq org-brain-path "~/.../org/mybrain")

then ~/.../org/mybrain is my org brain. If I leave this path out of my config, ~/.../org/brain becomes by default my org brain. But if I try to have subdirectories under either of these paths, they're not seen as separate org brains, rather, they're all a part of that org brain root directory . . . or am I missing something? What I'd like to have is a ~/.../org/mybrains main directory with subdirectories containing independent brains that don't necessarily know (or interact) with one another. Or just separate directories. Obviously, I could simply restart Emacs with the brain I want to work on

(setq org-brain-path "~/.../org/thisParticularBrain")

but that seems an ugly kludge. . . .

BTW, is this the place for usage questions? If not, where?

Kungsgeten commented 3 years ago

Hi! There's no official place for usage questions. Sometimes people ask questions here, I've seen questions on Reddit and on the Emacs Stack Exchange.

This answer became a bit longer than I intended. TL;DR: Use M-x org-brain-switch-brain to switch between brains, and do not put one brain inside an already existing one.

There are three things which define a "brain":

  1. The directory indicated by the org-brain-path.
  2. A file in that directory named .org-brain-data.el.
  3. All .org files inside org-brain-path and its sub-directories are scanned for entries.

If you have a directory set as org-brain-path and there's no data file there, it will be created by org-brain upon running most commands.

If you want to create a new brain you can use M-x org-brain-switch-brain to choose another directory, this also sets the org-brain-path. The same command is used to switch between existing brains. org-brain will also try to automatically switch brains if you're currently editing a file in a brain that isn't currently your org-brain-path.

In your case you can create your mybrains directory and place your brain folders inside it. Then set one of them as your main org-brain-path in your init.el and use org-brain-switch-brain to switch between them. I'd recommend not to use "brains inside of brains" since the "outer" brain will include the inner one (all subdirectories are scanned) - it is a use case that I haven't tested myself.

One thing that may happen is that you've accidentaly set a folder as org-brain-path and a .org-brain-data.el has been created inside of it. In that case you can remove the data file and it will no longer be considered a brain.

borgauf commented 3 years ago

Thanks for the info. I actually figured it out once I got past my mental block about initializing with a single brain directory in my org-brain-path. IOW, there is no initialization where you can tell org-brain about your separate brains, rather, you simply change brains while using Emacs. So you give an initial org-brain brain, then change to others.

Question: What did you intend with the whole edge notation idea? Did you mean RDF semantic triples where the edge is a "predicate" with a URI identifier?

Lawrence Bottorff Grand Marais, MN @.***

On Tue, May 18, 2021 at 2:46 PM Erik Sjöstrand @.***> wrote:

Hi! There's no official place for usage questions. Sometimes people ask questions here, I've seen questions on Reddit and on the Emacs Stack Exchange.

This answer became a bit longer than I intended. TL;DR: Use M-x org-brain-switch-brain to switch between brains, and do not put one brain inside an already existing one.

There are three things which define a "brain":

  1. The directory indicated by the org-brain-path.
  2. A file in that directory named .org-brain-data.el.
  3. All .org files inside org-brain-path and its sub-directories are scanned for entries.

If you have a directory set as org-brain-path and there's no data file there, it will be created by org-brain upon running most commands.

If you want to create a new brain you can use M-x org-brain-switch-brain to choose another directory, this also sets the org-brain-path. The same command is used to switch between existing brains. org-brain will also try to automatically switch brains if you're currently editing a file in a brain that isn't currently your org-brain-path.

In your case you can create your mybrains directory and place your brain folders inside it. Then set one of them as your main org-brain-path in your init.el and use org-brain-switch-brain to switch between them. I'd recommend not to use "brains inside of brains" since the "outer" brain will include the inner one (all subdirectories are scanned) - it is a use case that I haven't tested myself.

One thing that may happen is that you've accidentaly set a folder as org-brain-path and a .org-brain-data.el has been created inside of it. In that case you can remove the data file and it will no longer be considered a brain.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Kungsgeten/org-brain/issues/359#issuecomment-843503756, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABA73W5TEDD7HDS32DGSYJDTOK725ANCNFSM444XD7RA .

Kungsgeten commented 3 years ago

I'm sorry but I'm not familiar with RDF. I can't remember if the edge annotations were a feature request or if it was an idea of mine. I haven't used them much myself, but the way I think about them is to add annotations of how entries connect to each other. This may help when using org-brain-visualize to get a better description of how entries relate.

epeters-jrmngndr commented 3 years ago

Hey @Kungsgeten - Thanks for brain!

@borgauf - Maybe you'll find this useful. I use some custom code to manage my multiple org-brains. I am using use-package and general for configuration.

I use this to auto switch org brains my with perspectives:

  (setq my/projectile-brain-directories (make-hash-table :test 'equal))

  (defun my/brain-activate-project (arg)
    (interactive "P")
    (setq
     org-brain-path
     (cond ((not (eq arg nil))
            (read-directory-name "Brain dir: "))
           ((string= (car (last (delete "" (split-string (my/cwd) "/")))) "brain")
            (my/cwd))
           ((file-directory-p (concat (my/cwd) "brain/"))
            (concat  (my/cwd) "brain/"))))
    (puthash (projectile-project-name) org-brain-path my/projectile-brain-directories))

  (defun my/use-project-brain ()
    (let ((project-brain (gethash (projectile-project-name) my/projectile-brain-directories)))
      (if (not (eq nil project-brain))
          (setq org-brain-path project-brain))))

  (add-hook 'persp-switch-hook #'my/use-project-brain)

And then I have a custom shortcut for the brain activate function. I am planning to automatically invoke that when opening a project (projectile) that has a brain directory in it, but it's on the to do list for now.

This way, once I've opened my projects and perspectives, I can jump to a perspective, and have all my org-brain shortcuts apply to only the brain inside that perspective. With just a little setup (that I plan to automate), I have a great way to handle it.

Only issue is if you have brain visualize open in multiple projects at once. Still need to figure a solution for that.