summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze2019-03-02 19:12:54 -0500
committerJakob L. Kreuze2019-03-02 19:12:54 -0500
commit4d7d584c297086ea92810aae06b61ed15b5a3b9c (patch)
treee31681552eb9485599820f4a97f388cd62aa4961
parent87ca72da3cedbb311775eb79bddafe846662588a (diff)
Favor interactive navigation over generating a hierarchical listing
-rw-r--r--jakob.org88
1 files changed, 55 insertions, 33 deletions
diff --git a/jakob.org b/jakob.org
index 10b83ff..81b2aa6 100644
--- a/jakob.org
+++ b/jakob.org
@@ -996,44 +996,66 @@ folder so that I can easily refer to other pages from subdirectories of
(org-link-set-parameters "note" :follow #'org-notes-follow)
#+END_SRC
-Code for generating hierarchical category listings.
+Code for interactively navigating the personal wiki.
#+BEGIN_SRC elisp
:config
- (defvar notes-directory-ignore
- '("." ".." ".git" ".gitignore" "Drill"
- "Finance" "GTD" "Interviewing" "Mind Dumps")
- "Files and directories in `notes-directory' to exclude from
- wiki interactions.")
+ (defun notes-file-is-page (filename)
+ "Returns whether or not FILENAME names a page rather than a category."
+ (string= (subseq filename (- (length filename) 4)) ".org"))
- (defun insert-notes-hierarchy (&optional current indent)
- "Inserts an unordered Org list filled with links representing
- the hierarchy of `current'. Useful for generating index pages."
+ (defun notes-file-should-ignore (filename)
+ "Returns whether or not a file in `notes-directory' should be ignored.
+ Members of `notes-directory-ignore' are ignored."
+ (member filename notes-directory-ignore))
+
+ (defun notes-hierarchy-paths (&optional category)
+ "Returns page and category paths relative to `notes-directory'.
+ The resultant list does not include files that satisfy the
+ `notes-file-should-ignore' predicate."
+ (let* ((path (if category
+ (concat notes-directory "/" category)
+ notes-directory))
+ (contents (remove-if #'notes-file-should-ignore
+ (directory-files path)))
+ (pages (remove-if-not #'notes-file-is-page contents))
+ (categories (remove-if #'notes-file-is-page contents))
+ (categories (if category
+ (map 'list
+ #'(lambda (subcategory) (concat category "/" subcategory))
+ categories)
+ categories)))
+ (append (if category
+ (map 'list #'(lambda (page) (concat category "/" page)) pages)
+ pages)
+ categories
+ (apply #'append (map 'list #'notes-hierarchy-paths categories)))))
+
+ (defun notes-hierarchy ()
+ "Returns every page and category in `notes-directory'.
+ The result contains lists of the form (NAME PATH IS-PAGE-P), and
+ does not include files that satisfy the
+ `notes-file-should-ignore' predicate."
+ (map 'list
+ #'(lambda (path) (list (if (notes-file-is-page path) (subseq path 0 -4) path)
+ (concat notes-directory "/" path)
+ (notes-file-is-page path)))
+ (notes-hierarchy-paths)))
+
+ (defun notes-page-goto ()
+ "Interactively find a page in `notes-directory'."
(interactive)
- (let* ((current (or current "."))
- (indent (or indent ""))
- (path (expand-file-name current notes-directory))
- (files (remove-if #'(lambda (file) (member file notes-directory-ignore))
- (directory-files path))))
- (dolist (file files)
- (when (not (string= file "Index.org"))
- (let* ((name (if (string= (subseq file (- (length file) 4)) ".org")
- (subseq file 0 (- (length file) 4))
- file))
- (name (if (string= current ".")
- name
- (concat current "/" name)))
- (path (expand-file-name name notes-directory)))
- (if (file-directory-p path)
- (let ((index-path (concat path "/Index.org")))
- (insert (if (file-exists-p index-path)
- (format "%s- [[note:%s/Index.org][%s]]" indent name name)
- (format "%s- %s" indent name)))
- (newline)
- (insert-notes-hierarchy name (concat " " indent)))
- (progn
- (insert (format "%s- [[note:%s][%s]]" indent name name))
- (newline))))))))
+ (let* ((hierarchy (notes-hierarchy))
+ (hierarchy (remove-if-not #'third hierarchy))
+ (name (ivy-read "Find file: " (map 'list #'first hierarchy)))
+ (item (find-if #'(lambda (item) (string= name (first item))) hierarchy)))
+ (if item
+ (find-file (second item))
+ (let ((path (concat notes-directory "/" name ".org")))
+ (find-file path)))))
+
+ :bind
+ ("C-c w" . notes-page-goto)
#+END_SRC
*** Capture

© 2015 - 2026 Jakob L. Kreuze