summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2020-03-17 22:35:19 +0000
committerYann Herklotz <git@yannherklotz.com>2020-03-17 22:35:19 +0000
commit62f26ddcda0f03de5b34158b4cd124cf758ee13e (patch)
tree306904d4e8602bbcae4f52049e0912113b3dbc0e
parent4524800d9ad777a41030838095650d5557b7c690 (diff)
downloadorg-zettelkasten-62f26ddcda0f03de5b34158b4cd124cf758ee13e.tar.gz
org-zettelkasten-62f26ddcda0f03de5b34158b4cd124cf758ee13e.zip
Add function to add backlinks in html export
-rw-r--r--README.md4
-rw-r--r--zettelkasten.el53
2 files changed, 50 insertions, 7 deletions
diff --git a/README.md b/README.md
index f818f1f..5bb86e5 100644
--- a/README.md
+++ b/README.md
@@ -65,3 +65,7 @@ The default keymap for the mode is `C-c k`, this can easily be changed though by
## Alternatives
An alternative to use Zettelkasten in emacs is [Zetteldeft](https://github.com/EFLS/zetteldeft), which uses Deft as a backend to search files.
+
+Another beefier alternative is [org-roam](https://github.com/jethrokuan/org-roam/), which is a fully integrated note taking system based on a wiki-system.
+
+Finally, [org-brain](https://github.com/Kungsgeten/org-brain) is a similar note-taking system that is meant for concept mapping in Emacs.
diff --git a/zettelkasten.el b/zettelkasten.el
index c13f0f8..17affeb 100644
--- a/zettelkasten.el
+++ b/zettelkasten.el
@@ -36,7 +36,7 @@ After that, changing the prefix key requires manipulating keymaps."
:type 'string
:group 'zettelkasten)
-(defcustom zettelkasten-file-format "%y%W%u%%02d"
+(defcustom zettelkasten-file-format "%y%W%u%%02d-%%s"
"Format for new zettelkasten files.
For supported options, please consult `format-time-string'."
@@ -75,8 +75,7 @@ Return the NUMth match. If NUM is nil, return the 0th match."
(defun zettelkasten-display-id-title (note)
"Dispaly the NOTE's title and id."
- (format "%s: %s" note (zettelkasten-note-regexp
- note "#\\+TITLE: \\(.*\\)" 1)))
+ (format "%s: %s" note (zettelkasten--get-note-title note)))
(defun zettelkasten-match-link (current note)
"Return t if the link to CURRENT is in NOTE."
@@ -88,7 +87,7 @@ Return the NUMth match. If NUM is nil, return the 0th match."
(format zk-link-format
".*" current
zettelkasten-extension)))
- (zettelkasten-display-id-title note)))
+ note))
(defun zettelkasten-list-notes-by-id ()
"Return all the ids that are currently available."
@@ -149,7 +148,7 @@ Return the NUMth match. If NUM is nil, return the 0th match."
(defun zettelkasten-format-link (note)
"Format a link to a NOTE."
(format zettelkasten-link-format
- note
+ (zettelkasten--get-note-title note)
(zettelkasten-get-id note)
zettelkasten-extension))
@@ -194,6 +193,37 @@ Also see `zettelkasten-create-new-note-ni' for more information."
(zettelkasten-list-notes) nil 'match)))
(insert (zettelkasten-format-link note)))
+(defun zettelkasten-find-parents (note)
+ "Find the parents of the NOTE."
+ (delete
+ nil
+ (mapcar #'(lambda (el) (zettelkasten-match-link
+ note el))
+ (zettelkasten-list-notes-by-id))))
+
+(defun zettelkasten--get-note-title (note)
+ "Return the title of the NOTE."
+ (zettelkasten-note-regexp note "#\\+TITLE: \\(.*\\)" 1))
+
+(defun zettelkasten-org-export-preprocessor (backend)
+ "A preprocessor for zettelkasten directories, using the BACKEND.
+
+Adds information such as backlinks to the `org-mode' files before
+publishing."
+ (let ((notes (zettelkasten-find-parents
+ (zettelkasten-filename-to-id (buffer-file-name)))))
+ (when notes
+ (save-excursion
+ (goto-char (point-max))
+ (insert
+ (mapconcat 'identity (append
+ '("\n* Backlinks\n")
+ (mapcar
+ #'(lambda
+ (el)
+ (concat "- " (zettelkasten-format-link el) "\n"))
+ notes)) ""))))))
+
(defun zettelkasten-open-parent (&optional note)
"Find the parent notes to the NOTE that is given.
@@ -207,17 +237,26 @@ The format of the NOTE is anything that can be ready by
"Notes: "
(delete
nil
- (mapcar #'(lambda (el) (zettelkasten-match-link
- act-note el))
+ (mapcar #'(lambda (el)
+ (zettelkasten-display-id-title
+ (zettelkasten-match-link act-note el)))
(zettelkasten-list-notes-by-id)))
nil 'match)))
(find-file (zettelkasten-make-filename (zettelkasten-get-id selected)))))
+(defun zettelkasten-open-note (note)
+ "Open an existing NOTE, searching by title and id."
+ (interactive
+ (list (completing-read "Notes: "
+ (zettelkasten-list-notes) nil 'match)))
+ (find-file (zettelkasten-make-filename (zettelkasten-get-id note))))
+
(defvar zettelkasten-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "i" 'zettelkasten-insert-link)
(define-key map "n" 'zettelkasten-create-new-note)
(define-key map "p" 'zettelkasten-open-parent)
+ (define-key map "o" 'zettelkasten-open-note)
map))
(defvar zettelkasten-minor-mode-map