diff --git a/modules/lang/org/+notebook.el b/modules/lang/org/+notebook.el new file mode 100644 index 000000000..605122489 --- /dev/null +++ b/modules/lang/org/+notebook.el @@ -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 ()) + diff --git a/modules/lang/org/autoload/notebook.el b/modules/lang/org/autoload/notebook.el new file mode 100644 index 000000000..1b40efaf2 --- /dev/null +++ b/modules/lang/org/autoload/notebook.el @@ -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)) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 978832f2c..e3aea9466 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -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) ;;