-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelfos-sidebar.el
More file actions
83 lines (67 loc) · 2.61 KB
/
Copy pathdelfos-sidebar.el
File metadata and controls
83 lines (67 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;;; delfos-sidebar.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 namespace
;;
;; Author: namespace <src.namespace@gmail.com>
;; Maintainer: namespace <src.namespace@gmail.com>
;;; Commentary:
;; Delfos sidebar implementation.
;;; Code:
(require 'f)
(require 'delfos-thread)
;; TODO implement sidebar updates
(defvar delfos-sidebar-buffer-name "*Delfos Sidebar*")
(defun delfos-sidebar--get-threads ()
(f-files delfos-thread-directory
(lambda (file)
(string= (f-ext file) "delfos"))
t))
(defun delfos-sidebar--open-thread (thread)
(let ((current-point (point)))
(message (format "point: %s" current-point))
(with-selected-window (delfos-sidebar-find-main-window)
(delfos-switch-to-thread thread)
(delfos-sidebar-open))
(goto-char current-point)))
(defun delfos-sidebar--render-thread-button (thread)
(let ((button (insert-button thread 'action (lambda (_button) (delfos-sidebar--open-thread thread)))))
(button-put button 'face 'default)
button))
(defun delfos-sidebar-render ()
"Render the sidebar."
(setq buffer-read-only t)
(org-mode)
(setq display-line-numbers nil)
(insert "Delfos Sidebar\n")
(insert (make-string (window-body-width (get-buffer-window)) ?=) "\n\n")
(let ((button (insert-button "[Clear threads]" 'action (lambda (_button) (delfos-thread-delete-all)))))
(button-put button 'face '(:background "#666")))
;; TODO: Main first
(insert "\n\n* Threads\n")
(let ((threads (delfos-sidebar--get-threads)))
(dolist (thread threads)
(let ((thread-name (replace-regexp-in-string ".delfos" "" (f-filename thread)) ))
(insert "** ")
(when (string= thread-name delfos-current-thread)
(insert "="))
(delfos-sidebar--render-thread-button thread-name)
(when (string= thread-name delfos-current-thread)
(insert "="))
(insert "\n")))))
(defun delfos-sidebar-open ()
"Open the Delfos sidebar buffer in a side window on the right."
(let ((buffer (get-buffer-create delfos-sidebar-buffer-name)))
(display-buffer-in-side-window buffer '((side . right)))
(with-current-buffer buffer
(let ((inhibit-read-only t))
(erase-buffer)
(delfos-sidebar-render)))))
(defun delfos-sidebar-find-main-window ()
"Find the main window in the current frame, excluding the Delfos sidebar."
(let ((main-window nil))
(dolist (window (window-list))
(unless (string= (buffer-name (window-buffer window)) delfos-sidebar-buffer-name)
(setq main-window window)))
main-window))
(provide 'delfos-sidebar)
;;; delfos-sidebar.el ends here