aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2021-08-27 11:04:23 +0200
committerYann Herklotz <git@yannherklotz.com>2021-08-27 11:04:23 +0200
commit56f16a6ea3a36042ecc431322c0b6786f3507d7b (patch)
treeaffb930bbc9efdc32dce5996cb490a5d7e63054b
parent96a000fb27a5e8726f23423e970c6eb99f3575fe (diff)
downloademacs-zettelkasten-56f16a6ea3a36042ecc431322c0b6786f3507d7b.tar.gz
emacs-zettelkasten-56f16a6ea3a36042ecc431322c0b6786f3507d7b.zip
Fix package warnings and errors for melpa
-rw-r--r--org-zettelkasten.el63
-rw-r--r--zettelkasten.el52
2 files changed, 73 insertions, 42 deletions
diff --git a/org-zettelkasten.el b/org-zettelkasten.el
index f343a9f..735b2b0 100644
--- a/org-zettelkasten.el
+++ b/org-zettelkasten.el
@@ -1,9 +1,10 @@
-;;; org-zettelkasten.el --- Helper functions to use Zettelkasten in Org.
+;;; org-zettelkasten.el --- Helper functions to use Zettelkasten in `org-mode' -*- lexical-binding: t; -*-
-;; Author: Yann Herklotz
-;; Keywords: notes
-;; Package-Requires: ((emacs "24.1"))
+;; Author: Yann Herklotz <yann@ymhg.org>
+;; URL: https://github.com/ymherklotz/emacs-zettelkasten
;; Version: 1.0.0
+;; Package-Requires: ((emacs "24.3") (org "9.0"))
+;; Keywords: files, hypermedia, Org, notes
;;; Commentary:
@@ -11,8 +12,10 @@
;;
;; It uses the CUSTOM_ID property to store a permanent ID to the note,
;; which are organised in the same fashion as the notes by Luhmann.
-;;
-;; Copyright (C) 2020 Yann Herklotz
+
+;;; License:
+
+;; Copyright (C) 2020-2021 Yann Herklotz
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -41,7 +44,14 @@
:type 'string
:group 'org-zettelkasten)
-(defun ymhg/incr-id (ident)
+(defcustom org-zettelkasten-prefix [(control ?c) ?y]
+ "Prefix key to use for Zettelkasten commands in Zettelkasten minor mode.
+The value of this variable is checked as part of loading Zettelkasten mode.
+After that, changing the prefix key requires manipulating keymaps."
+ :type 'key-sequence
+ :group 'zettelkasten)
+
+(defun org-zettelkasten-incr-id (ident)
"Simple function to increment any IDENT.
This might result in duplicate IDs though."
@@ -50,7 +60,7 @@ This might result in duplicate IDs though."
(setcar last-ident (+ (car last-ident) 1))
(concat ident-list)))
-(defun ymhg/incr-id-total (ident)
+(defun org-zettelkasten-incr-id-total (ident)
"A better way to incement numerical IDENT.
This might still result in duplicate IDENTs for an IDENT that
@@ -61,15 +71,15 @@ ends with a letter."
(let ((pre (match-string 1 ident))
(post (match-string 2 ident)))
(concat pre (number-to-string (+ 1 (string-to-number post))))))
- (ymhg/incr-id ident)))
+ (org-zettelkasten-incr-id ident)))
-(defun ymhg/branch-id (ident)
+(defun org-zettelkasten-branch-id (ident)
"Create a branch ID from IDENT."
(if (string-match-p ".*[0-9]$" ident)
(concat ident "a")
(concat ident "1")))
-(defun ymhg/org-zettelkasten-create (incr newheading)
+(defun org-zettelkasten-org-zettelkasten-create (incr newheading)
"Creat a new heading according to INCR and NEWHEADING.
INCR: function to increment the ID by.
@@ -82,13 +92,13 @@ NEWHEADING: function used to create the heading and set the current
(defun org-zettelkasten-create-next ()
"Create a heading at the same level as the current one."
- (ymhg/org-zettelkasten-create
- 'ymhg/incr-id 'org-insert-heading))
+ (org-zettelkasten-org-zettelkasten-create
+ #'org-zettelkasten-incr-id #'org-insert-heading))
(defun org-zettelkasten-create-branch ()
"Create a branching heading at a level lower than the current."
- (ymhg/org-zettelkasten-create
- 'ymhg/branch-id '(lambda () (org-insert-subheading ""))))
+ (org-zettelkasten-org-zettelkasten-create
+ #'org-zettelkasten-branch-id #'(lambda () (org-insert-subheading ""))))
(defun org-zettelkasten-create-dwim ()
"Create the right type of heading based on current position."
@@ -104,13 +114,30 @@ NEWHEADING: function used to create the heading and set the current
(org-zettelkasten-create-branch))))
(defun org-zettelkasten-search-current-id ()
- "Use counsel-rg to search for the current ID in all files."
+ "Use `counsel-rg' to search for the current ID in all files."
(interactive)
(let ((current-id (org-entry-get nil "CUSTOM_ID")))
(counsel-rg (concat "#" current-id) org-zettelkasten-directory "-g *.org" "ID: ")))
-(define-key org-mode-map (kbd "C-c y n") #'org-zettelkasten-create-dwim)
-(define-key org-mode-map (kbd "C-c y s") #'org-zettelkasten-search-current-id)
+(defvar org-zettelkasten-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "n" #'org-zettelkasten-create-dwim)
+ (define-key map "s" #'org-zettelkasten-search-current-id)
+ map))
+
+(defvar org-zettelkasten-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map org-zettelkasten-prefix org-zettelkasten-mode-map)
+ map)
+ "Keymap used for binding footnote minor mode.")
+
+;;;###autoload
+(define-minor-mode org-zettelkasten-mode
+ "Enable the keymaps to be used with zettelkasten."
+ :lighter " org-zettelkasten"
+ :keymap org-zettelkasten-minor-mode-map)
+
+(add-hook 'org-mode-hook #'org-zettelkasten-mode)
(provide 'org-zettelkasten)
;;; org-zettelkasten.el ends here
diff --git a/zettelkasten.el b/zettelkasten.el
index 10e4639..9625e88 100644
--- a/zettelkasten.el
+++ b/zettelkasten.el
@@ -1,15 +1,18 @@
-;;; zettelkasten.el --- Helper functions to organise notes.
+;;; zettelkasten.el --- Helper functions to organise notes in a Zettelkasten style -*- lexical-binding: t; -*-
-;; Author: Yann Herklotz
-;; Keywords: notes
-;; Package-Requires: ((emacs "24.1"))
+;; Author: Yann Herklotz <yann@ymhg.org>
+;; URL: https://github.com/ymherklotz/emacs-zettelkasten
;; Version: 1.0.0
+;; Package-Requires: ((emacs "24.3"))
+;; Keywords: files, hypermedia, notes
;;; Commentary:
;; Used to organise notes using the Zettelkasten method.
-;;
-;; Copyright (C) 2020 Yann Herklotz
+
+;;; License:
+
+;; Copyright (C) 2020-2021 Yann Herklotz
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -112,7 +115,7 @@ Return the NUMth match. If NUM is nil, return the 0th match."
(match-string (if num num 0)))))
(defun zettelkasten--note-regexp-multiple (note regexp &optional num)
- "Return the REGEXP matches in the NOTE.
+ "Return the REGEXP matched in the NOTE.
Return the NUMth match. If NUM is nil, return the 0th match."
(with-temp-buffer
@@ -137,7 +140,7 @@ Return the NUMth match. If NUM is nil, return the 0th match."
(defun zettelkasten--list-notes-by-id ()
"Return all the ids that are currently available."
- (mapcar 'zettelkasten--filename-to-id
+ (mapcar #'zettelkasten--filename-to-id
(directory-files
(expand-file-name zettelkasten-directory) nil
(format "[0-9]+\\.%s$" zettelkasten-extension) t)))
@@ -170,14 +173,14 @@ This is deprecated in favour for `zettelkasten-list-notes'."
(defun zettelkasten--list-notes ()
"Return all the ids and titles of notes in the `zettelkasten-directory'."
- (mapcar 'zettelkasten--display-for-search
+ (mapcar #'zettelkasten--display-for-search
(zettelkasten--list-notes-by-id)))
(defun zettelkasten--list-links (note)
"List all notes that the current NOTE links to."
(sort
(cl-remove-duplicates
- (mapcar 'zettelkasten--get-id
+ (mapcar #'zettelkasten--get-id
(zettelkasten--note-regexp-multiple
note
(let ((zk-link-format (replace-regexp-in-string
@@ -185,7 +188,7 @@ This is deprecated in favour for `zettelkasten-list-notes'."
(regexp-quote zettelkasten-link-format))))
(format zk-link-format
".*" ".*"
- zettelkasten-extension))))) 'string<))
+ zettelkasten-extension))))) #'string<))
;;; ------------------
;;; CREATING NEW NOTES
@@ -246,7 +249,7 @@ If PARENT is nil, it will not add a link from a PARENT."
(let ((tags (zettelkasten--note-regexp
note "#\\+TAGS: \\(.*\\)" 1)))
(when tags
- (mapcar 's-trim (s-split "," tags)))))
+ (mapcar #'s-trim (s-split "," tags)))))
(defun zettelkasten--get-tags-and-ids ()
"Return a mapping from TAGS to ids for NOTE."
@@ -300,7 +303,7 @@ If PARENT is nil, it will not add a link from a PARENT."
(defun zettelkasten-generate-site-map (title files)
"Generate the site map for the Zettelkasten using TITLE and FILES."
(let* ((ti (zettelkasten--get-tags-and-ids))
- (tags (sort (car ti) 'string<)))
+ (tags (sort (car ti) #'string<)))
(concat
"#+TITLE: " title "\n\n"
(apply
@@ -312,7 +315,7 @@ If PARENT is nil, it will not add a link from a PARENT."
"\n\n* Index\n\n"
(apply
#'concat
- (zettelkasten--generate-list-for-note-nc (sort (zettelkasten--list-notes-without-parents) 'string>)))
+ (zettelkasten--generate-list-for-note-nc (sort (zettelkasten--list-notes-without-parents) #'string>)))
"\n* Tags\n\n"
(apply
#'concat
@@ -325,7 +328,7 @@ If PARENT is nil, it will not add a link from a PARENT."
(set-buffer-file-coding-system 'utf-8)
(insert (concat "#+TITLE: " (capitalize tag) "\n\n"
(apply
- 'concat
+ #'concat
(mapcar
#'(lambda (note)
(concat "- " (zettelkasten--format-link note) "\n"))
@@ -333,7 +336,7 @@ If PARENT is nil, it will not add a link from a PARENT."
(save-buffer))
(concat "** " (capitalize tag) "\n :PROPERTIES:\n :CUSTOM_ID: " tag "\n :END:\n\n"
(apply
- 'concat
+ #'concat
(mapcar
#'(lambda (note)
(concat "- " (zettelkasten--format-link note) "\n"))
@@ -362,7 +365,7 @@ publishing."
(when notes
(goto-char (point-max))
(insert
- (mapconcat 'identity (append
+ (mapconcat #'identity (append
'("\n* Backlinks\n")
(mapcar
#'(lambda
@@ -407,7 +410,7 @@ The format of the NOTE is anything that can be ready by
(zettelkasten--filename-to-id (buffer-file-name))))
(selected (completing-read
"Notes: "
- (mapcar 'zettelkasten--display-for-search
+ (mapcar #'zettelkasten--display-for-search
(zettelkasten--find-parents act-note))
nil 'match)))
(find-file (zettelkasten--make-filename (zettelkasten--get-id selected)))))
@@ -433,7 +436,7 @@ The format of the NOTE is anything that can be ready by
(let ((ismember (member chosentag tags)))
(completing-read
"Note: "
- (mapcar 'zettelkasten--display-for-search (car (cdr ismember)))
+ (mapcar #'zettelkasten--display-for-search (car (cdr ismember)))
nil 'match))))
(find-file (zettelkasten--make-filename (zettelkasten--get-id chosennote)))))
@@ -443,11 +446,11 @@ The format of the NOTE is anything that can be ready by
(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)
- (define-key map "t" 'zettelkasten-open-note-by-tag)
+ (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)
+ (define-key map "t" #'zettelkasten-open-note-by-tag)
map))
(defvar zettelkasten-minor-mode-map
@@ -456,6 +459,7 @@ The format of the NOTE is anything that can be ready by
map)
"Keymap used for binding footnote minor mode.")
+;;;###autoload
(define-minor-mode zettelkasten-mode
"Enable the keymaps to be used with zettelkasten."
:lighter " zettelkasten"