Skip to content

Commit a9e8246

Browse files
committed
factored out functions in a new file
1 parent 843d108 commit a9e8246

File tree

2 files changed

+146
-144
lines changed

2 files changed

+146
-144
lines changed

lisp/larsen-orgmode-functions.el

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
(defun my-org-confirm-babel-evaluate (lang body)
2+
(not (string= lang "emacs-elisp")))
3+
4+
;; Special functions to insert week-based object entries
5+
6+
(defun current-year ()
7+
(nth 5 (decode-time (current-time))))
8+
9+
(defun my-calendar-iso-day-to-gregorian (week-number week-day)
10+
"Return gregorian day corresponding to WEEK-NUMBER and WEEK-DAY.
11+
WEEK-DAY is expressed as an integer in the range 0..6:
12+
1 = Monday, 2 = Tuesday, ..., 0 = Sunday."
13+
(calendar-gregorian-from-absolute
14+
(calendar-iso-to-absolute (list week-number week-day (current-year)))))
15+
16+
(defun my-gregorian-date-as-string (date)
17+
(cl-destructuring-bind (month day year) date
18+
(format "%4d-%02d-%02d" year month day)))
19+
20+
(defun my-current-week-number ()
21+
"Return ISO8601 week number for today."
22+
(format-time-string "%V" (current-time)))
23+
24+
(defvar day-properties-string ":PROPERTIES:\n:COLUMNS: %25ITEM %TAGS %PRIORITY %TODO\n:END:")
25+
26+
(defun my-week-heading (week-number)
27+
"Return a string representing the heading for WEEK-NUMBER todo entries subtree."
28+
(let ((week-begin-date (my-calendar-iso-day-to-gregorian week-number 1))
29+
(week-end-date (my-calendar-iso-day-to-gregorian week-number 5)))
30+
(format "Week %d (%s - %s)"
31+
week-number
32+
(my-gregorian-date-as-string week-begin-date)
33+
(my-gregorian-date-as-string week-end-date))))
34+
35+
(defun my-today-heading ()
36+
"Return a string representing the heading for today's todo entries subtree."
37+
(format-time-string "%A" (current-time)))
38+
39+
(defun one-week-from-today ()
40+
(format-time-string "%Y-%m-%d"
41+
(+ (time-convert nil 'integer)
42+
(* 3600 24 7))))
43+
44+
(org-babel-do-load-languages
45+
'org-babel-load-languages
46+
'((perl . t)
47+
(shell . t)
48+
(python . t)
49+
(sql . t)
50+
(sqlite . t)
51+
(gnuplot . t)
52+
(R . t)
53+
(plantuml . t)
54+
(http . t)
55+
(lisp . t)
56+
(dot . t)))
57+
58+
(defun my-insert-current-week-item (week-number)
59+
"Insert 1-week-worth structure for entering todo entries for WEEK-NUMBER."
60+
(interactive "P")
61+
(insert (format "* %s\n" (my-week-heading week-number)))
62+
(dolist (week-day-name '(Monday
63+
Tuesday
64+
Wednesday
65+
Thursday
66+
Friday
67+
Saturday
68+
Sunday))
69+
(insert (format "** %s\n%s\n" week-day-name day-properties-string))))
70+
71+
(defun my-org-set-item-deadline (week-number)
72+
(let ((week-end-date (my-calendar-iso-day-to-gregorian week-number 5)))
73+
(org-deadline nil (my-gregorian-date-as-string week-end-date))))
74+
75+
(defun my-org-set-tree-deadline (week-number)
76+
(interactive "P")
77+
(org-map-entries (lambda () (my-org-set-item-deadline week-number)) nil 'tree))
78+
79+
;; Experimental
80+
;; a more natural way to use indirect buffers
81+
;; not sure about the keybinding
82+
83+
(defun open-subtree-in-another-window ()
84+
"Open subtree at point into another window."
85+
(interactive)
86+
(org-tree-to-indirect-buffer)
87+
(windmove-right))
88+
89+
(defun my-find-today-heading ()
90+
(let ((m (org-find-olp `(,(my-week-heading
91+
(string-to-number (my-current-week-number)))
92+
,(my-today-heading))
93+
;; In current buffer, because we're using file+function
94+
t)))
95+
(set-buffer (marker-buffer m))
96+
(org-capture-put-target-region-and-position)
97+
(widen)
98+
(goto-char m)
99+
(set-marker m nil)))
100+
101+
(defun my-org-jump-to-today ()
102+
"Move cursor to the heading corresponding to today."
103+
(interactive)
104+
(my-find-today-heading))
105+
106+
(defun orgzly-files ()
107+
(file-expand-wildcards "~/Dropbox/orgzly/*.org"))
108+
109+
(add-to-list 'org-latex-classes
110+
'("tufte-handout"
111+
"\\documentclass{tufte-handout}"
112+
("\\section{%s}" . "\\section*{%s}")
113+
("\\subsection{%s}" . "\\subsection*{%s}")
114+
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
115+
("\\paragraph{%s}" . "\\paragraph*{%s}")
116+
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
117+
118+
119+
(setq-default org-download-method 'attach ;; Screenshots are stored in data/ directory by ID. Easier to manage
120+
org-download-heading-lvl nil
121+
org-download-delete-image-after-download t
122+
org-download-screenshot-method "echo"
123+
org-download-screenshot-file "/tmp/screenshot.png"
124+
org-download-image-org-width 800
125+
;; Don't annotate
126+
org-download-annotate-function (lambda (link) ""))
127+
128+
;; My customized org-download to incorporate flameshot gui Workaround to setup flameshot, which enables annotation.
129+
;; In flameshot, set filename as "screenshot", and the command as "flameshot gui -p /tmp", so that we always ends up
130+
;; with /tmp/screenshot.png. Nullify org-download-screenshot-method by setting it to `echo', so that essentially we
131+
;; are only calling (org-download-image org-download-screenshot-file).
132+
(defun my-org-download-screenshot ()
133+
"Capture screenshot and insert the resulting file.
134+
The screenshot tool is determined by `org-download-screenshot-method'."
135+
(interactive)
136+
(let ((tmp-file "/tmp/screenshot.png"))
137+
(delete-file tmp-file)
138+
(call-process-shell-command "flameshot gui -p /tmp/")
139+
;; Because flameshot exit immediately, keep polling to check file existence
140+
(while (not (file-exists-p tmp-file))
141+
(sleep-for 2))
142+
(org-download-image tmp-file)))
143+
(global-set-key (kbd "<C-print>") 'my-org-download-screenshot)
144+
145+
(provide 'larsen-orgmode-functions)

lisp/larsen-orgmode.el

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
(org-agenda-start-day nil) ;; i.e. today
9494
(org-agenda-span 14)
9595
(org-agenda-files '("~/org/personal/"
96+
"~/org/orgzly/errand.org"
9697
"~/org/work/"))
9798
(org-agenda-custom-commands '(("w" "Weekly Agenda"
9899
((agenda "" ((org-super-agenda-groups
@@ -134,148 +135,4 @@
134135
(use-package cl-lib)
135136
(use-package ox)
136137

137-
(defun my-org-confirm-babel-evaluate (lang body)
138-
(not (string= lang "emacs-elisp")))
139-
140-
;; Special functions to insert week-based object entries
141-
142-
(defun current-year ()
143-
(nth 5 (decode-time (current-time))))
144-
145-
(defun my-calendar-iso-day-to-gregorian (week-number week-day)
146-
"Return gregorian day corresponding to WEEK-NUMBER and WEEK-DAY.
147-
WEEK-DAY is expressed as an integer in the range 0..6:
148-
1 = Monday, 2 = Tuesday, ..., 0 = Sunday."
149-
(calendar-gregorian-from-absolute
150-
(calendar-iso-to-absolute (list week-number week-day (current-year)))))
151-
152-
(defun my-gregorian-date-as-string (date)
153-
(cl-destructuring-bind (month day year) date
154-
(format "%4d-%02d-%02d" year month day)))
155-
156-
(defun my-current-week-number ()
157-
"Return ISO8601 week number for today."
158-
(format-time-string "%V" (current-time)))
159-
160-
(defvar day-properties-string ":PROPERTIES:\n:COLUMNS: %25ITEM %TAGS %PRIORITY %TODO\n:END:")
161-
162-
(defun my-week-heading (week-number)
163-
"Return a string representing the heading for WEEK-NUMBER todo entries subtree."
164-
(let ((week-begin-date (my-calendar-iso-day-to-gregorian week-number 1))
165-
(week-end-date (my-calendar-iso-day-to-gregorian week-number 5)))
166-
(format "Week %d (%s - %s)"
167-
week-number
168-
(my-gregorian-date-as-string week-begin-date)
169-
(my-gregorian-date-as-string week-end-date))))
170-
171-
(defun my-today-heading ()
172-
"Return a string representing the heading for today's todo entries subtree."
173-
(format-time-string "%A" (current-time)))
174-
175-
(defun one-week-from-today ()
176-
(format-time-string "%Y-%m-%d"
177-
(+ (time-convert nil 'integer)
178-
(* 3600 24 7))))
179-
180-
(org-babel-do-load-languages
181-
'org-babel-load-languages
182-
'((perl . t)
183-
(shell . t)
184-
(python . t)
185-
(sql . t)
186-
(sqlite . t)
187-
(gnuplot . t)
188-
(R . t)
189-
(plantuml . t)
190-
(http . t)
191-
(lisp . t)
192-
(dot . t)))
193-
194-
(defun my-insert-current-week-item (week-number)
195-
"Insert 1-week-worth structure for entering todo entries for WEEK-NUMBER."
196-
(interactive "P")
197-
(insert (format "* %s\n" (my-week-heading week-number)))
198-
(dolist (week-day-name '(Monday
199-
Tuesday
200-
Wednesday
201-
Thursday
202-
Friday
203-
Saturday
204-
Sunday))
205-
(insert (format "** %s\n%s\n" week-day-name day-properties-string))))
206-
207-
(defun my-org-set-item-deadline (week-number)
208-
(let ((week-end-date (my-calendar-iso-day-to-gregorian week-number 5)))
209-
(org-deadline nil (my-gregorian-date-as-string week-end-date))))
210-
211-
(defun my-org-set-tree-deadline (week-number)
212-
(interactive "P")
213-
(org-map-entries (lambda () (my-org-set-item-deadline week-number)) nil 'tree))
214-
215-
;; Experimental
216-
;; a more natural way to use indirect buffers
217-
;; not sure about the keybinding
218-
219-
(defun open-subtree-in-another-window ()
220-
"Open subtree at point into another window."
221-
(interactive)
222-
(org-tree-to-indirect-buffer)
223-
(windmove-right))
224-
225-
(defun my-find-today-heading ()
226-
(let ((m (org-find-olp `(,(my-week-heading
227-
(string-to-number (my-current-week-number)))
228-
,(my-today-heading))
229-
;; In current buffer, because we're using file+function
230-
t)))
231-
(set-buffer (marker-buffer m))
232-
(org-capture-put-target-region-and-position)
233-
(widen)
234-
(goto-char m)
235-
(set-marker m nil)))
236-
237-
(defun my-org-jump-to-today ()
238-
"Move cursor to the heading corresponding to today."
239-
(interactive)
240-
(my-find-today-heading))
241-
242-
(defun orgzly-files ()
243-
(file-expand-wildcards "~/Dropbox/orgzly/*.org"))
244-
245-
(add-to-list 'org-latex-classes
246-
'("tufte-handout"
247-
"\\documentclass{tufte-handout}"
248-
("\\section{%s}" . "\\section*{%s}")
249-
("\\subsection{%s}" . "\\subsection*{%s}")
250-
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
251-
("\\paragraph{%s}" . "\\paragraph*{%s}")
252-
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
253-
254-
255-
(setq-default org-download-method 'attach ;; Screenshots are stored in data/ directory by ID. Easier to manage
256-
org-download-heading-lvl nil
257-
org-download-delete-image-after-download t
258-
org-download-screenshot-method "echo"
259-
org-download-screenshot-file "/tmp/screenshot.png"
260-
org-download-image-org-width 800
261-
;; Don't annotate
262-
org-download-annotate-function (lambda (link) ""))
263-
264-
;; My customized org-download to incorporate flameshot gui Workaround to setup flameshot, which enables annotation.
265-
;; In flameshot, set filename as "screenshot", and the command as "flameshot gui -p /tmp", so that we always ends up
266-
;; with /tmp/screenshot.png. Nullify org-download-screenshot-method by setting it to `echo', so that essentially we
267-
;; are only calling (org-download-image org-download-screenshot-file).
268-
(defun my-org-download-screenshot ()
269-
"Capture screenshot and insert the resulting file.
270-
The screenshot tool is determined by `org-download-screenshot-method'."
271-
(interactive)
272-
(let ((tmp-file "/tmp/screenshot.png"))
273-
(delete-file tmp-file)
274-
(call-process-shell-command "flameshot gui -p /tmp/")
275-
;; Because flameshot exit immediately, keep polling to check file existence
276-
(while (not (file-exists-p tmp-file))
277-
(sleep-for 2))
278-
(org-download-image tmp-file)))
279-
(global-set-key (kbd "<C-print>") 'my-org-download-screenshot)
280-
281138
(provide 'larsen-orgmode)

0 commit comments

Comments
 (0)