lang/org: add +notebook submodule (quick access to project/major-mode notes)

This commit is contained in:
Henrik Lissner 2017-04-05 14:29:25 -04:00
parent 4cf0f0b8c7
commit 4372293c42
3 changed files with 59 additions and 3 deletions

View file

@ -0,0 +1,26 @@
;;; lang/org/+notebook.el
;; While I program, write or plan, I want easy access to notes of various kinds,
;; such as major-mode/language specific notes, or project-specific notes. They
;; can be accessed via `+org/browse-notes-for-major-mode' and
;; `+org/browse-notes-for-project'.
(add-hook '+org-init-hook '+org|init-notebook t)
(defvar +org-notes-dir (concat +org-dir "notes/")
"The directory where the notes are kept.")
(defvar +org-code-notes-dir (concat +org-notes-dir "code/")
"The directory where programming notes and snippets are kept.")
(defvar +org-project-notes-dir (concat +org-notes-dir "projects/")
"The directory where project notes are kept.")
(defvar +org-notes-code-alist
'((js2-mode . "javascript"))
"An alist mapping certain modes (symbols) to their org notes directory name.
If a mode isn't here, it's guessed by stripping out the -mode suffix and
replacing '+' characters with 'p's.")
;; (defun +org|init-notebook ())

View file

@ -0,0 +1,32 @@
;;; lang/org/autoload/notebook.el
;;;###autoload
(defun +org-mode-notes-dir ()
"Return the directory were `major-mode's org notes files are."
(if-let (name (cdr (assq major-mode +org-notes-code-alist)))
(expand-file-name (concat name "/") +org-code-notes-dir)
(let ((mode-name (s-replace "+" "p" (s-chop-suffix "-mode" (symbol-name major-mode)))))
(expand-file-name (concat mode-name "/") +org-code-notes-dir))))
(defun +org--explore-notes (dir)
(unless (file-directory-p dir)
(error "Directory doesn't exist: %s" dir))
(if (fboundp '+evil/neotree)
(neotree-dir dir)
(let ((default-directory dir))
(call-interactively (command-remapping 'find-file)))))
;;;###autoload
(defun +org/browse-notes-for-major-mode ()
(interactive)
(let ((dir (+org-mode-notes-dir)))
(unless (file-in-directory-p dir +org-code-notes-dir)
(error "Invalid location for %s notes: %s" major-mode (abbreviate-file-name dir)))
(unless (file-directory-p dir)
(make-directory dir t))
(+org--explore-notes dir)))
;;;###autoload
(defun +org/browse-notes-for-project ()
(interactive)
(+org--explore-notes +org-project-notes-dir))

View file

@ -22,9 +22,6 @@
"The directory where org files are kept.")
(defvaralias 'org-directory '+org-dir)
(defvar +org-notes-dir (concat +org-dir "notes")
"The directory where the notes are kept")
(defvar +org-attachment-dir ".attach/"
"Where to store attachments (relative to current org file).")
@ -39,6 +36,7 @@
(load! +attach)
(load! +capture)
(load! +export)
(load! +notebook)
;;