|
@@ -0,0 +1,69 @@
|
|
|
|
|
+;"Generate an aligned, fontified buffer of all Denote files using fd."
|
|
|
|
|
+
|
|
|
|
|
+(defvar denote-browser-map
|
|
|
|
|
+ (let ((map (make-sparse-keymap)))
|
|
|
|
|
+ (define-key map (kbd "RET") 'denote-browser-open-file)
|
|
|
|
|
+ map)
|
|
|
|
|
+ "Keymap for the custom Denote browser.")
|
|
|
|
|
+
|
|
|
|
|
+(defface denote-browser-dir '((t :inherit font-lock-comment-face)) "Face for subdirs.")
|
|
|
|
|
+(defface denote-browser-id '((t :inherit font-lock-constant-face)) "Face for IDs.")
|
|
|
|
|
+(defface denote-browser-title '((t :inherit font-lock-keyword-face :weight bold)) "Face for titles.")
|
|
|
|
|
+(defface denote-browser-tags '((t :inherit font-lock-type-face)) "Face for tags.")
|
|
|
|
|
+
|
|
|
|
|
+(defun denote-browser-open-file ()
|
|
|
|
|
+ "Open the file on the current line."
|
|
|
|
|
+ (interactive)
|
|
|
|
|
+ (if (get-text-property (point) 'denote-path)
|
|
|
|
|
+ (find-file (get-text-property (point) 'denote-path))
|
|
|
|
|
+ (message "No file on this line.")))
|
|
|
|
|
+
|
|
|
|
|
+(defun list-denote-files ()
|
|
|
|
|
+ "Generate an aligned, fontified buffer of all Denote files using fd."
|
|
|
|
|
+ (interactive)
|
|
|
|
|
+ (let* ((default-directory (expand-file-name "~/lyrinv/SOR/Notes/"))
|
|
|
|
|
+ (raw-output (shell-command-to-string "fd -t f"))
|
|
|
|
|
+ (lines (split-string raw-output "\n" t))
|
|
|
|
|
+ (buf (get-buffer-create "*Denote Browser*")))
|
|
|
|
|
+ (with-current-buffer buf
|
|
|
|
|
+ (let ((inhibit-read-only t))
|
|
|
|
|
+ (erase-buffer)
|
|
|
|
|
+ (use-local-map denote-browser-map)
|
|
|
|
|
+ (setq-local buffer-read-only t)
|
|
|
|
|
+
|
|
|
|
|
+ (dolist (line lines)
|
|
|
|
|
+ ;; Regex to break down: Subdir/ + ID + Title + Keywords
|
|
|
|
|
+ (if (string-match "^\\(.*\\/\\)?\\([0-9A-Za-z]+\\)--\\([^\n__]+\\)\\(__.*\\)?\\.\\([a-z]+\\)$" line)
|
|
|
|
|
+ (let* ((dir (or (match-string 1 line) ""))
|
|
|
|
|
+ (id (or (match-string 2 line) ""))
|
|
|
|
|
+ (title (or (match-string 3 line) ""))
|
|
|
|
|
+ (tags (or (match-string 4 line) ""))
|
|
|
|
|
+ (full-path (expand-file-name line default-directory))
|
|
|
|
|
+ (start (point)))
|
|
|
|
|
+
|
|
|
|
|
+ ;; Clean up trailing slash and tag underscores for legibility
|
|
|
|
|
+ (setq dir (if (string-empty-p dir) "." (directory-file-name dir)))
|
|
|
|
|
+ (setq tags (if (string-empty-p tags) "" (replace-regexp-in-string "__" " " tags)))
|
|
|
|
|
+
|
|
|
|
|
+ ;; Insert padded, aligned string components
|
|
|
|
|
+ (insert (propertize (format "%-20s " dir) 'face 'denote-browser-dir))
|
|
|
|
|
+ (insert (propertize (format "%-16s " id) 'face 'denote-browser-id))
|
|
|
|
|
+ (insert (propertize (format "%-45s " title) 'face 'denote-browser-title))
|
|
|
|
|
+ (insert (propertize tags 'face 'denote-browser-tags))
|
|
|
|
|
+ (insert "\n")
|
|
|
|
|
+
|
|
|
|
|
+ ;; Attach the raw file path to the entire line for RET to use
|
|
|
|
|
+ (add-text-properties start (point) (list 'denote-path full-path)))
|
|
|
|
|
+
|
|
|
|
|
+ ;; Fallback layout for non-standard files (e.g., gereedschap.ods)
|
|
|
|
|
+ (let* ((dir (or (file-name-directory line) "."))
|
|
|
|
|
+ (file (file-name-nondirectory line))
|
|
|
|
|
+ (full-path (expand-file-name line default-directory))
|
|
|
|
|
+ (start (point)))
|
|
|
|
|
+ (insert (propertize (format "%-20s " (directory-file-name dir)) 'face 'denote-browser-dir))
|
|
|
|
|
+ (insert (propertize (format "%-16s " "No-ID") 'face 'denote-browser-id))
|
|
|
|
|
+ (insert (propertize file 'face 'denote-browser-title))
|
|
|
|
|
+ (insert "\n")
|
|
|
|
|
+ (add-text-properties start (point) (list 'denote-path full-path)))))))
|
|
|
|
|
+
|
|
|
|
|
+ (pop-to-buffer buf)))
|