blob: 6ef501b85abce09de38451350892e5532300f9ac (
plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
(require 'consult)
(require 'beframe)
(require 'calendar)
(require 'org-roam-node)
(require 'denote)
(defvar bard/consult--source-notes
`(:name "Note Buffers"
:narrow ?n
:category buffer
:face consult-buffer
:history buffer-name-history
:items ,(lambda ()
(mapcar #'buffer-name
(seq-filter
(lambda (buf)
(string-prefix-p "[Note]" (buffer-name buf)))
(beframe-buffer-list))))
:action ,#'switch-to-buffer
:state ,#'consult--buffer-state)
"Consult source for note buffers (limited to beframe buffers).")
(defun bard/consult-buffer-notes ()
"Show `consult-buffer` limited to buffers starting with [Note]."
(interactive)
(consult-buffer '(bard/consult--source-notes)))
(defun bard/ibuffer-notes ()
"Open `ibuffer` limited to buffers starting with [Note]."
(interactive)
(ibuffer nil "*Ibuffer-Notes*"
'((name . "^\\[Note\\]"))))
(use-package consult-denote
:ensure t
:bind
("C-c n g" . consult-denote-grep)
("C-c n f" . consult-denote-find))
(defvar bard/class-dirs
'(("COMM 111" . "~/Documents/Uni/SUMMER2026-COMM 111/")
("CSE 220" . "~/Documents/Uni/SUMMER2026-CSE 220/")
("PHYS 296" . "~/Documents/Uni/SUMMER2026-PHYS 296/")
("PHYS 299" . "~/Documents/Uni/SUMMER2026-PHYS 299/"))
"Mapping of class names to their document directories.")
(defvar bard/uni-notes-file "~/Notes/denote/uni.org"
"Path to the main university org file.")
(defun bard/jump-to-class (class &optional with-dired)
"Jump to CLASS heading in bard/uni-notes-file, can open its dir in Dired."
(interactive
(list
(completing-read "Class: " (mapcar #'car bard/class-dirs))
current-prefix-arg))
(let ((dir (cdr (assoc class bard/class-dirs))))
(delete-other-windows)
(find-file bard/uni-notes-file)
(widen)
(goto-char (point-min))
(search-forward class nil nil)
(when with-dired
(let ((dired-window (split-window-right)))
(with-selected-window dired-window
(dired dir))))))
(defun bard/jump-to-class-new-frame (class &optional with-dired)
"Open CLASS notes and dir in a new frame titled after CLASS, optionally WITH-DIRED."
(interactive
(list
(completing-read "Class: " (mapcar #'car bard/class-dirs))
current-prefix-arg))
(let* ((dir (cdr (assoc class bard/class-dirs)))
(frame (make-frame `((frame-title-format . ,class)))))
(select-frame-set-input-focus frame)
(delete-other-windows)
(find-file bard/uni-notes-file)
(widen)
(goto-char (point-min))
(search-forward class nil nil)
(when with-dired
(let ((dired-window (split-window-right)))
(with-selected-window dired-window
(dired dir)
(beframe-rename-current-frame))))))
;; Optional: bind to a key
(global-set-key (kbd "C-c u") #'bard/jump-to-class)
(global-set-key (kbd "C-c U") #'bard/jump-to-class-new-frame)
(defun bard/denote-todo-template ()
"Return string for daily tasks heading in `denote-journal' entries."
(with-temp-buffer
(org-mode)
(insert (format "* Tasks for %s\n** Время я потратил бездельничая\n\n* Notes for today\n\n* Clocktable\n"
(format-time-string "%Y-%m-%d (%a)")))
(let ((org-clock-clocktable-default-properties
'(:scope file :maxlevel 3 :link nil :compact t)))
(org-clock-report))
(buffer-string)))
;; Taken from: https://stackoverflow.com/a/75314192
(defun add-multiple-into-list (lst items)
"Add each item from ITEMS into LST."
(dolist (item items)
(add-to-list lst item)))
(defun bard/cdlatex-add-math-symbols ()
"Add functions into list."
(add-multiple-into-list
'cdlatex-math-symbol-alist-comb
'((?V "\\vec")
(?s "\\sigma" "\\text{ s.t. }" "\\sin")
(?= "\\implies" "\\Leftrightarrow" "\\Longleftrightarrow"))))
(use-package xenops
:ensure t
:config
(setq xenops-math-image-scale-factor 1.2))
(define-minor-mode bard/org-math-mode
"Enable features to write math in `org-mode'."
:init-value nil
:lighter " S="
:global nil
(xenops-mode t)
(org-cdlatex-mode t)
(electric-pair-local-mode t)
(bard/cdlatex-add-math-symbols)
;; sending math to calc from latex doc
(define-key org-mode-map (kbd "C-S-e") #'latex-math-from-calc))
;; latex into calc
(defun latex-math-from-calc ()
"Evaluate `calc' on the contents of line at point."
(interactive)
(cond ((region-active-p)
(let* ((beg (region-beginning))
(end (region-end))
(string (buffer-substring-no-properties beg end)))
(kill-region beg end)
(insert (calc-eval `(,string calc-language latex
calc-prefer-frac t
calc-angle-mode rad)))))
(t (let ((l (thing-at-point 'line)))
(end-of-line 1) (kill-line 0)
(insert (calc-eval `(,l
calc-language latex
calc-prefer-frac t
calc-angle-mode rad)))))))
(provide 'bard-writing)
|