org-roam v2

This commit is contained in:
Jethro Kuan
2021-02-27 23:06:28 +08:00
parent 8ad57b1218
commit 53dcf687ef
32 changed files with 2080 additions and 5220 deletions

View File

@ -4,11 +4,11 @@
;; Copyright © 2020 Leo Vivier <leo.vivier+dev@gmail.com>
;; Author: Jethro Kuan <jethrokuan95@gmail.com>
;; Leo Vivier <leo.vivier+dev@gmail.com>
;; Leo Vivier <leo.vivier+dev@gmail.com>
;; URL: https://github.com/org-roam/org-roam
;; Keywords: org-mode, roam, convenience
;; Version: 1.2.3
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.3") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2"))
;; Version: 2.0.0
;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (org "9.4") (emacsql "3.0.0") (emacsql-sqlite3 "1.0.2") (magit-section "2.90.1"))
;; This file is NOT part of GNU Emacs.
@ -36,16 +36,19 @@
;;; Library Requires
(require 'org-capture)
(require 'org-roam-capture)
(require 'org-roam-macs)
(require 'f)
;;;; Declarations
(defvar org-roam-mode)
(defvar org-roam-directory)
(defvar org-roam-file-extensions)
(declare-function org-roam--org-file-p "org-roam")
(declare-function org-roam--find-file "org-roam")
(declare-function org-roam-mode "org-roam")
;;;; Faces
(defface org-roam-dailies-calendar-note
'((t :inherit (org-link) :underline nil))
"Face for dates with a daily-note in the calendar"
:group 'org-roam-faces)
;;;; Customizable variables
(defcustom org-roam-dailies-directory "daily/"
@ -71,55 +74,55 @@
(choice :value ("d" "default" plain (function org-roam-capture--get-point)
"%?"
:file-name ,(concat org-roam-dailies-directory
"%<%Y-%m-%d>")
"%<%Y-%m-%d>")
:head "#+title: %<%Y-%m-%d>\n"
:unnarrowed t)
(list :tag "Multikey description"
(string :tag "Keys ")
(string :tag "Description"))
(list :tag "Template entry"
(string :tag "Keys ")
(string :tag "Description ")
(choice :tag "Type "
(const :tag "Plain" plain)
(const :tag "Entry (for creating headlines)" entry))
(const :format "" #'org-roam-capture--get-point)
(choice :tag "Template "
(string :tag "String"
:format "String:\n \
(list :tag "Multikey description"
(string :tag "Keys ")
(string :tag "Description"))
(list :tag "Template entry"
(string :tag "Keys ")
(string :tag "Description ")
(choice :tag "Type "
(const :tag "Plain" plain)
(const :tag "Entry (for creating headlines)" entry))
(const :format "" #'org-roam-capture--get-point)
(choice :tag "Template "
(string :tag "String"
:format "String:\n \
Template string :\n%v")
(list :tag "File"
(const :format "" file)
(file :tag "Template file "))
(list :tag "Function"
(const :format "" function)
(function :tag "Template function ")))
(const :format "File name format :" :file-name)
(string :format " %v" :value ,(concat org-roam-dailies-directory
"%<%Y-%m-%d>"))
(const :format "Header format :" :head)
(string :format " %v" :value "#+title: ${title}\n")
(plist :inline t
:tag "Options"
;; Give the most common options as checkboxes
:options
(((const :tag "Outline path" :olp)
(repeat :tag "Headings"
(string :tag "Heading")))
((const :format "%v " :unnarrowed) (const t))
((const :format "%v " :prepend) (const t))
((const :format "%v " :immediate-finish) (const t))
((const :format "%v " :jump-to-captured) (const t))
((const :format "%v " :empty-lines) (const 1))
((const :format "%v " :empty-lines-before) (const 1))
((const :format "%v " :empty-lines-after) (const 1))
((const :format "%v " :clock-in) (const t))
((const :format "%v " :clock-keep) (const t))
((const :format "%v " :clock-resume) (const t))
((const :format "%v " :time-prompt) (const t))
((const :format "%v " :tree-type) (const week))
((const :format "%v " :table-line-pos) (string))
((const :format "%v " :kill-buffer) (const t))))))))
(list :tag "File"
(const :format "" file)
(file :tag "Template file "))
(list :tag "Function"
(const :format "" function)
(function :tag "Template function ")))
(const :format "File name format :" :file-name)
(string :format " %v" :value ,(concat org-roam-dailies-directory
"%<%Y-%m-%d>"))
(const :format "Header format :" :head)
(string :format " %v" :value "#+title: ${title}\n")
(plist :inline t
:tag "Options"
;; Give the most common options as checkboxes
:options
(((const :tag "Outline path" :olp)
(repeat :tag "Headings"
(string :tag "Heading")))
((const :format "%v " :unnarrowed) (const t))
((const :format "%v " :prepend) (const t))
((const :format "%v " :immediate-finish) (const t))
((const :format "%v " :jump-to-captured) (const t))
((const :format "%v " :empty-lines) (const 1))
((const :format "%v " :empty-lines-before) (const 1))
((const :format "%v " :empty-lines-after) (const 1))
((const :format "%v " :clock-in) (const t))
((const :format "%v " :clock-keep) (const t))
((const :format "%v " :clock-resume) (const t))
((const :format "%v " :time-prompt) (const t))
((const :format "%v " :tree-type) (const week))
((const :format "%v " :table-line-pos) (string))
((const :format "%v " :kill-buffer) (const t))))))))
;;;; Utilities
(defun org-roam-dailies-directory--get-absolute-path ()
@ -129,7 +132,7 @@ Template string :\n%v")
(defun org-roam-dailies-find-directory ()
"Find and open `org-roam-dailies-directory'."
(interactive)
(org-roam--find-file (org-roam-dailies-directory--get-absolute-path)))
(find-file (org-roam-dailies-directory--get-absolute-path)))
(defun org-roam-dailies--daily-note-p (&optional file)
"Return t if FILE is an Org-roam daily-note, nil otherwise.
@ -149,9 +152,8 @@ If FILE is not specified, use the current buffer's file-path."
"Capture an entry in a daily-note for TIME, creating it if necessary.
When GOTO is non-nil, go the note without creating an entry."
(unless org-roam-mode (org-roam-mode))
(let ((org-roam-capture-templates (--> org-roam-dailies-capture-templates
(if goto (list (car it)) it)))
(if goto (list (car it)) it)))
(org-roam-capture--info (list (cons 'time time)))
(org-roam-capture--context 'dailies))
(org-roam-capture--capture (when goto '(4)))))
@ -281,7 +283,7 @@ Prefer past dates, unless PREFER-FUTURE is non-nil."
"List all files in `org-roam-dailies-directory'.
EXTRA-FILES can be used to append extra files to the list."
(let ((dir (org-roam-dailies-directory--get-absolute-path))
(regexp (rx-to-string `(and "." (or ,@org-roam-file-extensions)))))
(regexp (rx-to-string `(and "." (or ,@org-roam-file-extensions)))))
(append (--remove (let ((file (file-name-nondirectory it)))
(when (or (auto-save-file-name-p file)
(backup-file-name-p file)
@ -305,18 +307,18 @@ negative, find note N days in the past."
(string= (buffer-file-name (buffer-base-buffer)) candidate))
dailies))
note)
(unless position
(user-error "Can't find current note file - have you saved it yet?"))
(pcase n
((pred (natnump))
(when (eq position (- (length dailies) 1))
(user-error "Already at newest note")))
((pred (integerp))
(when (eq position 0)
(user-error "Already at oldest note"))))
(setq note (nth (+ position n) dailies))
(find-file note)
(run-hooks 'org-roam-dailies-find-file-hook)))
(unless position
(user-error "Can't find current note file - have you saved it yet?"))
(pcase n
((pred (natnump))
(when (eq position (- (length dailies) 1))
(user-error "Already at newest note")))
((pred (integerp))
(when (eq position 0)
(user-error "Already at oldest note"))))
(setq note (nth (+ position n) dailies))
(find-file note)
(run-hooks 'org-roam-dailies-find-file-hook)))
(defun org-roam-dailies-find-previous-note (&optional n)
"Find previous daily-note.