-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.el
More file actions
453 lines (408 loc) · 15.9 KB
/
Copy pathinit.el
File metadata and controls
453 lines (408 loc) · 15.9 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
;;; init.el --- Emacs configuration file -*- lexical-binding: t -*-
;; No splash message
(setq inhibit-splash-screen t)
;; No backup files
(setq make-backup-files nil)
;; No toolbar
(progn (if (fboundp 'tool-bar-mode) (tool-bar-mode -1)))
;; Show column number
(column-number-mode 1)
;; Highlight current line
(global-hl-line-mode 1)
;; Store Customs in different place
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file 'noerror)
;; Enable Which Function Mode
(which-function-mode 1)
;; Wrap lines
(global-visual-line-mode 1)
;; Calendar starts on Moday
(setq calendar-week-start-day 1)
;; Shortkey to comment region
(global-set-key (kbd "C-c C-c") 'comment-region)
;; Install use-package if not already installed
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(eval-when-compile
(require 'use-package)
(require 'use-package-ensure)
(setq use-package-always-ensure t))
;; Quelpa handler for use-package
(use-package quelpa-use-package
:init
(setq quelpa-update-melpa-p nil)
(setq quelpa-self-upgrade-p nil))
;; Diminished modes are minor modes with no modeline display
(use-package diminish)
;; Major-mode for editing CMake sources
(use-package cmake-mode
:mode "\\.cmake\\'")
;; Major mode for editing Docker's Dockerfiles
(use-package dockerfile-mode)
;; Incremental Vertical completYon
(use-package ivy
:diminish
:config
(ivy-mode 1))
;; Various completion functions using Ivy
(use-package counsel
:diminish
:after ivy
:config
(counsel-mode 1))
;; EditorConfig Emacs plugin
(use-package editorconfig
:diminish
:config
(editorconfig-mode 1))
;; Define and query search engines from within Emacs
(use-package engine-mode
:config
(engine-mode t)
(defengine github
"https://github.com/search?q=%s&type=code"
:keybinding "g")
(defengine duckduckgo
"https://duckduckgo.com/?q=%s"
:keybinding "d"))
;; Major mode for Markdown-formatted text
(use-package markdown-mode
:mode "\\.md\\'")
;; Major mode for the Meson build system files
(use-package meson-mode)
;; Outline-based notes management and organizer
(use-package org
:config
(setq org-directory "~/Misc/orgfiles")
(setq org-agenda-files (list org-directory))
(setq org-refile-use-outline-path 'file)
(setq org-refile-targets '((org-agenda-files :maxlevel . 1)))
(setq org-export-backends '(ascii html md odt))
(setq org-capture-templates
'(("t" "Todo [Inbox]" entry
(file "~/Misc/orgfiles/inbox.org")
"* TODO %i%?")))
(setq org-clock-persist t)
(setq org-clock-in-resume t)
(setq org-clock-persist-query-resume nil)
(setq org-clock-out-remove-zero-time-clocks t)
(setq org-startup-indented t)
(setq org-indent-indentation-per-level 1)
(org-clock-persistence-insinuate)
:bind
(("C-c c" . org-capture)))
;; A simple org-mode based journaling mode
(use-package org-journal
:after org
:config
(setq org-journal-dir "~/Misc/orgfiles/journal")
(setq org-journal-file-type 'weekly)
(setq org-journal-file-format "%Y/w%V_%Y%m%d.org")
(setq org-journal-date-format "%A (%d %b %Y)")
(setq org-journal-time-format "")
(setq org-journal-time-prefix "- ")
(setq org-journal-carryover-items "")
(setq org-journal-file-header
(concat
"#+Title: Week %V\n"
"#+OPTIONS: toc:nil tags:nil todo:nil h:2 num:1 ^:{}\n"
"#+COLUMNS: %%ITEM(Task) %%CLOCKSUM(Clocked) %%EFFORT(Estimated)\n"
"\n"
"\n"))
(progn
(defun org-journal-aux/search-effort ()
(if (org-entry-get (point) "Effort")
(point)
(if (org-up-heading-safe)
(org-journal-aux/search-effort)
nil)))
(defun org-journal-aux/get-remaining-effort ()
(let ((actual-clocked (org-clock-sum-current-item)))
(save-excursion
(if (org-journal-aux/search-effort)
(org-minutes-to-clocksum-string
(- (org-hh:mm-string-to-minutes (org-entry-get (point) "Effort"))
(- (org-clock-sum-current-item) actual-clocked)))
nil))))
(defun org-journal/add-derived-effort ()
(if (not (org-entry-get (point) "Effort"))
(let ((remaining-effort (org-journal-aux/get-remaining-effort)))
(if remaining-effort
(progn
(org-entry-put (point) "Effort" remaining-effort)
(org-entry-put (point) "DerivedEffort" "true"))))))
(defun org-journal/remove-derived-effort ()
(if (org-entry-get (point) "DerivedEffort")
(progn
(org-entry-delete (point) "Effort")
(org-entry-delete (point) "DerivedEffort"))))
(defun org-journal/goto-head ()
(point-to-register 1)
(while (org-up-heading-safe) ()))
(defun org-journal/goto-back ()
(register-to-point 1))
(defun org-journal/clock-on-top ()
(interactive)
(let ((org-clock-in-prepare-hook '(org-journal/goto-head))
(org-clock-in-hook '(org-journal/goto-back)))
(org-clock-in)))
(defun org-journal/clock-in-current ()
(interactive)
(let ((org-clock-in-prepare-hook '(org-journal/add-derived-effort))
(org-clock-in-hook '(org-journal/remove-derived-effort)))
(org-clock-in)))
(defun org-journal/carryover-todos ()
"Carry over items from previous date section to current date section.
TODO items are moved with full content; no-state items are copied as
heading only (no body text). DONE items are skipped.
When the previous entry is in a different file, items are always copied
instead of moved (source is left unchanged)."
(let* ((org-journal-find-file 'find-file)
(current-file (buffer-file-name))
(date-level (save-excursion
(org-back-to-heading t)
(org-outline-level)))
output-text
seen-positions
regions-to-delete
different-file)
(save-excursion
(save-restriction
(when (org-journal--open-entry t t)
(setq different-file (not (string= (buffer-file-name) current-file)))
(unless (org-journal--daily-p)
(org-narrow-to-subtree))
(org-map-entries
(lambda ()
(let* ((level (org-outline-level))
(todo-state (org-get-todo-state))
(item-start (point))
(item-end (save-excursion (org-end-of-subtree t t) (point)))
parent-texts)
(cond
;; Skip the date heading itself
((<= level date-level) nil)
;; Skip completed items and their entire subtrees
((member todo-state org-done-keywords)
(setq org-map-continue-from item-end))
;; TODO items: move full subtree with parent context
;; (copy only if from a different file)
((equal todo-state "TODO")
(save-excursion
(while (and (org-up-heading-safe)
(> (org-outline-level) date-level))
(let ((pos (point)))
(unless (member pos seen-positions)
(push pos seen-positions)
(push (buffer-substring-no-properties
pos
(save-excursion (outline-next-heading) (point)))
parent-texts)))))
(push item-start seen-positions)
(unless different-file
(push (cons item-start item-end) regions-to-delete))
(setq output-text
(concat output-text
(apply #'concat (nreverse parent-texts))
(buffer-substring-no-properties item-start item-end)))
(setq org-map-continue-from item-end))
;; No state: copy heading+body if has content, move if empty
;; (always copy if from a different file)
(t
(let* ((body-start (save-excursion (forward-line 1) (point)))
(has-content (string-match-p "\\S-"
(buffer-substring-no-properties
body-start item-end))))
(save-excursion
(while (and (org-up-heading-safe)
(> (org-outline-level) date-level))
(let ((pos (point)))
(unless (member pos seen-positions)
(push pos seen-positions)
(push (buffer-substring-no-properties
pos
(save-excursion (outline-next-heading) (point)))
parent-texts)))))
(push item-start seen-positions)
(if (or has-content different-file)
;; Has content or different file: copy heading line only
(setq output-text
(concat output-text
(apply #'concat (nreverse parent-texts))
(buffer-substring-no-properties item-start (line-end-position))
"\n"))
;; Empty and same file: move heading, remove from source
(push (cons item-start item-end) regions-to-delete)
(setq output-text
(concat output-text
(apply #'concat (nreverse parent-texts))
(buffer-substring-no-properties item-start (line-end-position))
"\n"))
(setq org-map-continue-from item-end)))))))
nil)
(dolist (r (sort regions-to-delete (lambda (a b) (> (car a) (car b)))))
(delete-region (car r) (cdr r)))
(save-buffer))))
(when output-text
(save-excursion
(org-back-to-heading t)
(outline-end-of-subtree)
(unless (bolp) (insert "\n"))
(insert output-text)))))
(defun org-journal/show-current-date (&rest _)
"Expand the full current date section after creating a new entry."
(save-excursion
(while (org-up-heading-safe))
(org-show-subtree)))
(advice-add 'org-journal-new-entry :after #'org-journal/show-current-date))
:bind
(("C-c C-x C-M-i" . org-journal/clock-in-current))
:hook
((org-clock-in-prepare . org-journal/goto-head)
(org-clock-in . org-journal/goto-back)
(org-journal-after-header-create . org-journal/carryover-todos)))
(global-set-key (kbd "C-c C-j") 'org-journal-new-entry)
;; Insert org-mode links from the clipboard
(use-package org-cliplink
:after org
:config
(progn
(defun org-cliplink-gh (&optional link)
(interactive)
(org-cliplink-insert-transformed-title
(or link (org-cliplink-clipboard-content))
(lambda (url title)
(let* ((parsed-url (url-generic-parse-url url))
(clean-title
(cond
((string-match "\\([^·]*\\) · Issue #\\([0-9]+\\) · " title) ; GitHub Issue
(concat "#" (match-string 2 title) " \"" (match-string 1 title) "\""))
((string-match "\\([^·]*\\) by [^·]+ · Pull Request #\\([0-9]+\\) · " title) ; GitHub Pull Request
(concat "!" (match-string 2 title) " \"" (match-string 1 title) "\""))
((string-match "\\([^·]*\\) · [^@]*@\\([^·]*\\) · " title) ; GitHub Commit
(concat (match-string 2 title) " (\"" (match-string 1 title) "\")"))
((string-match "\\([^(]*\\) (#\\([0-9a-z]+\\)) · Issues" title) ; GitLab Issue
(concat "#" (match-string 2 title) " \"" (match-string 1 title) "\""))
((string-match "\\(.*\\) (!\\([0-9a-z]+\\)) · Merge requests" title) ; GitLab Merge Request
(concat "!" (match-string 2 title) " \"" (match-string 1 title) "\""))
((string-match "\\([^(]*\\) (\\([0-9a-z]+\\)) · Commits" title) ; GitLab Commit
(concat (match-string 2 title) " (\"" (match-string 1 title) "\")"))
(t title)
)))
;; forward the title to the default org-cliplink transformer
(org-cliplink-org-mode-link-transformer url clean-title))))))
:bind
(("C-c C-x l" . org-cliplink-gh)))
;; Modern looks for Org
(use-package org-modern
:after org
:hook (org-mode . org-modern-mode))
;; Org Twiki and Foswiki export
;; Add function that fits better with the format we need for reports
(use-package ox-twiki
:after org
:config
(defun org-twiki-export-report ()
(interactive)
(org-twiki-export-as-twiki)
(goto-char (point-min))
(kill-whole-line)
(kill-whole-line)
(while (search-forward "---+" nil t)
(replace-match "--"))
(goto-char (point-min))))
;; A database abstraction layer for Org-mode
(use-package org-roam
:after org
:custom
(org-roam-directory (file-truename "~/Misc/orgfiles/roam"))
(org-roam-completion-everywhere t)
:config
(setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
(org-roam-db-autosync-mode)
:bind
(("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert)
("C-c n c" . org-roam-capture)
:map org-mode-map
("C-M-i" . completion-at-point)))
;; Adds document titles to Markdown files generated with ox-md and derivatives
(use-package ox-md-title
:after org
:quelpa
(ox-md-title
:fetcher github
:repo "jeffkreeftmeijer/ox-md-title.el")
:config
(org-md-title-add)
(setq org-md-title t))
;; Modern block styling with org-indent.
(use-package org-modern-indent
:quelpa
(org-modern-indent
:fetcher github
:repo "jdtsmith/org-modern-indent")
:config
(add-hook 'org-mode-hook #'org-modern-indent-mode 90))
;; Manage and navigate projects in Emacs easily
(use-package projectile
:diminish
:config
(projectile-mode +1)
:custom
(projectile-indexing-method 'hybrid)
:bind-keymap
("C-c p" . projectile-command-map))
;; Ivy integration for Projectile
(use-package counsel-projectile
:config
(counsel-projectile-mode 1))
;; Automatic insertion, wrapping and paredit-like navigation with user
;; defined pairs
(use-package smartparens
:config
(require 'smartparens-config)
(smartparens-global-mode t)
(show-smartparens-global-mode t))
;; A tree style file explorer package
(use-package treemacs
:bind
(("<f8>" . treemacs)))
;;Projectile integration for treemacs
(use-package treemacs-projectile
:after projectile treemacs)
;; Major mode for editing Twiki pages
(use-package twiki
:quelpa
(twiki
:fetcher github
:repo "christopherjwhite/emacs-twiki-mode")
:mode ("\\.twiki\\'" . twiki-mode))
;; Major mode for editing YAML files
(use-package yaml-mode
:mode "\\.yml\\'")
(use-package yasnippet
:diminish
:config
(yas-global-mode t))
;; A low contrast color theme for Emacs
(use-package zenburn-theme
:config
(load-theme 'zenburn t))
;; Better experience with icons for ivy
(use-package all-the-icons-ivy-rich
:config
(all-the-icons-ivy-rich-mode 1))
;; More friendly display transformer for ivy
(use-package ivy-rich
:config
(ivy-rich-mode 1))
;; Better sorting and filtering
(use-package ivy-prescient
:config
(ivy-prescient-mode 1))