commit 8042e2cdca6629806222ab8fc792739951e2ee8c
parent 1c5aaa81f6a32f23b91fe10c15d9cb3eca98868b
Author: Alex Balgavy <alex@balgavy.eu>
Date: Tue, 21 Mar 2023 21:38:50 +0100
emacs: config changes
Diffstat:
M | emacs/config.org | | | 160 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- |
1 file changed, 132 insertions(+), 28 deletions(-)
diff --git a/emacs/config.org b/emacs/config.org
@@ -942,6 +942,45 @@ Hide some messages I don't need.
(setq inhibit-startup-message t)
#+end_src
+** Start buffer
+#+begin_src emacs-lisp
+ (define-minor-mode za/start-mode
+ "Minor mode for start page: ~/.config/emacs/start.org"
+ :lighter " start"
+ :keymap `((,(kbd "c") . (lambda () (interactive) (find-file (concat user-emacs-directory "config.org"))))
+ (,(kbd "a") . org-agenda)
+ (,(kbd "ii") . gtd-inbox)
+ (,(kbd "im") . gtd-inbox-mobile)
+ (,(kbd "g") . za/start-mode-update)
+ (,(kbd "ss") . za/st)
+ (,(kbd "sk") . za/st-kill)
+ (,(kbd "<tab>") . org-next-link)
+ (,(kbd "S-<tab>") . org-previous-link))
+ :after-hook (za/start-mode-update)
+ (setq-local view-read-only nil)
+ (setq buffer-read-only t))
+
+ (setq initial-buffer-choice (concat user-emacs-directory "start.org"))
+
+ (defun za/start-mode-update ()
+ "Update start dashboard."
+ (interactive)
+ (setq buffer-read-only nil)
+ (org-update-all-dblocks)
+ (setq buffer-read-only t))
+
+ (defun org-dblock-write:gtd-inbox-stats (params)
+ "Get GTD inbox stats for start screen."
+
+ (let ((lines-inbox (za/org-count-headlines-in-file 1 za/org-life-inbox))
+ (lines-mobile (za/org-count-headlines-in-file 1 za/org-life-inbox-mobile))
+ (count-docs (length (directory-files za/org-life-doc-inbox nil (rx bos (not ?.))))))
+ (insert (if (> lines-inbox 0) (format "- [[elisp:(find-file \"%s\")][%s: %s]]\n" za/org-life-inbox "Inbox" lines-inbox) "")
+ (if (> lines-mobile 0) (format "- [[elisp:(find-file \"%s\")][%s: %s]]\n" za/org-life-inbox-mobile "Mobile" lines-mobile) "")
+ (if (> count-docs 0) (format "- [[elisp:(find-file \"%s\")][%s: %s]]" za/org-life-doc-inbox"Scanned" count-docs) ""))))
+
+#+end_src
+
** Pixel scroll mode
#+begin_src emacs-lisp
(unless (version< emacs-version "29")
@@ -995,6 +1034,9 @@ Switched to this from Helm, it's more lightweight.
'dired
'(("f" (lambda (dir) (ivy-exit-with-action (counsel-fzf nil dir))) "Fzf in directory")
("g" (lambda (dir) (ivy-exit-with-action (counsel-ag nil dir))) "Ag in directory")))
+ (ivy-add-actions
+ 'counsel-describe-function
+ '(("d" (lambda (fun) (ivy-exit-with-action (edebug-instrument-function (intern fun)))) "Edebug instrument function")))
(ivy-mode)
(defun edit-script ()
@@ -1074,6 +1116,27 @@ Solution: ~brew tap daviderestivo/emacs-head && brew install emacs-head@28 --wit
#+end_src
[[https://github.com/tumashu/ivy-posframe/issues/123][See here]] for cursor going offscreen in the posframe. Currently 'solved' with ~ivy-truncate-lines~ nil.
+
+** DISABLED vertico + consult + marginalia + embark + posframe + prescient
+Alternative to counsel/ivy/swiper, will probably switch to this at some point.
+[[https://old.reddit.com/r/emacs/comments/qfrxgb/using_emacs_episode_80_vertico_marginalia_consult/hi6mfh7/][Here]] is a good comparison.
+
+#+begin_src emacs-lisp :tangle no
+ (dolist (pack '(vertico consult marginalia embark vertico-posframe vertico-prescient))
+ (unless (package-installed-p pack)
+ (package-install pack))
+ (require pack))
+
+ (vertico-mode 1)
+ (vertico-posframe-mode 1)
+ (marginalia-mode 1)
+ (vertico-prescient-mode 1)
+ (setq completion-styles '(basic substring partial-completion flex))
+
+ (global-set-key (kbd "M-o") #'embark-act)
+ (global-set-key (kbd "C-s") #'consult-line)
+
+#+end_src
** company: completion mechanism
#+begin_src emacs-lisp
(use-package company)
@@ -1368,6 +1431,7 @@ Install Org and require additional components that I use.
(org-catch-invisible-edits 'show-and-error
"Sometimes when text is folded away, I might accidentally edit text inside of it. This option prevents that. I wanted to do 'smart', but that has a 'fixme' so it might change in the future...Instead, show what's being edited, but don't perform the edit.")
(org-src-tab-acts-natively t "a tab in a code block indents the code as it should")
+ (org-attach-store-link-p 'attached)
:bind (("C-c a" . org-agenda)
("C-c n" . org-capture)
@@ -1381,18 +1445,21 @@ Install Org and require additional components that I use.
(org-mode . za/echo-area-tooltips)
(org-mode . org-superstar-mode)
(org-mode . org-indent-mode)
- (org-mode . za/settings-on-org-mode))
+ (org-mode . za/settings-on-org-mode)
+ (org-mode . org-pretty-table-mode))
:config
+ (za/package-vc-install :repo "Fuco1/org-pretty-table")
+ (delight 'org-pretty-table nil)
+ (require 'org-pretty-table)
+
+
(za/package-vc-install :repo "https://git.sr.ht/~bzg/org-contrib" :load "lisp/")
(require 'org-contrib)
(require 'org-checklist)
(delight 'org-indent-mode nil 'org-indent)
(defun za/settings-on-org-mode ()
"Settings on enabling org mode"
- (za/toggle-wrap t)
- (setq org-tags-column (- 10 (window-total-width)))
- ;; Realign tags
- (org-set-tags-command '(4)))
+ (za/toggle-wrap t))
(defcustom za/org-inline-images-desired-screen-proportion (/ (float 3) 4)
"Percentage of the window (as a float) that Org inline images should take up."
@@ -1407,6 +1474,22 @@ Install Org and require additional components that I use.
(advice-add 'org-display-inline-images :before #'za/org-display-inline-images-set-width)
+ (defun za/org-attach-tag (old/org-attach-tag &rest args)
+ "Wraps :around org-attach-tag (as OLD/ORG-ATTACH-TAG) with ARGS.
+ When inside capture for org-roam, attaching fails at
+ org-attach-tag. This function prevents that error interrupting
+ org-attach."
+ (if ; there's no heading
+ (not (org-element-lineage (org-element-at-point)
+ '(headline inlinetask)
+ 'include-self))
+ nil ; there's no point attaching a tag
+ ; otherwise, normal attach
+ (apply old/org-attach-tag args)))
+
+ (advice-add #'org-attach-tag :around #'za/org-attach-tag)
+
+
(require 'org-tempo)
(require 'org-habit)
(require 'org-id)
@@ -1474,7 +1557,7 @@ Fix tag display by dynamically calculating the column.
#+begin_src emacs-lisp
(defun za/settings-org-agenda-mode ()
"My settings for org agenda mode"
- (setq org-agenda-tags-column (- 10 (window-total-width))))
+ )
(add-hook 'org-agenda-mode-hook #'za/settings-org-agenda-mode)
#+end_src
@@ -1487,6 +1570,7 @@ Convenience functions to make opening the main file faster:
(find-file za/org-life-inbox)
(dired-other-window za/org-life-doc-inbox)
(dired-revert))
+ (defun gtd-inbox-mobile () "GTD: mobile inbox" (interactive) (find-file za/org-life-inbox-mobile))
(defun gtd-archive () "GTD: archive" (interactive) (find-file za/org-life-archive))
(defun gtd-someday () "GTD: someday" (interactive) (find-file za/org-life-someday))
(defun gtd-tickler () "GTD: tickler" (interactive) (find-file za/org-life-tickler))
@@ -1796,6 +1880,8 @@ I tried org-edna but I couldn't get it working after an hour of effort. So a bit
"Automatically mark project item as next."
(save-excursion
(org-back-to-heading)
+ (when (buffer-narrowed-p)
+ (widen))
(when (and (member org-state org-done-keywords)
(not (member "PROJECT" (org-get-tags nil 'local)))
(member "PROJECT" (let ((org-use-tag-inheritance t))
@@ -2069,13 +2155,9 @@ The default Markdown backend doesn't provide that, so need to customize it by ad
(concat "+++\n"
(format "title = \"%s\"\n" (string-replace "\"" "'" title))
- ;; If the note contains a #+MATH: t
- (when (org-element-map
- (plist-get info :parse-tree)
- 'keyword
- (lambda (k) (when (equal (org-element-property :key k) "MATH")
- (org-element-property :value k))))
- "template = \"page-math.html\"\n")
+ ;; If the note contains a math org-roam tag
+ (when (member "math" (plist-get info :filetags))
+ "template = \"page-math.html\"\n")
"+++\n"
(format "# %s\n" title)
@@ -2115,16 +2197,36 @@ And here's the custom publish function that adds/removes the necessary advice:
(defun za/org-gfm-publish-to-gfm-zola (plist filename pub-dir)
"Run `org-gfm-publish-to-gfm`, advising the necessary
functions to generate Zola-compatible markdown."
- (let ((advice '((org-gfm-inner-template :override za/org-md-template-zola)
- (org-md-link :filter-return za/org-md-link-zola)
- (org-html--format-image :filter-args za/org-html--format-image)
- (org-gfm-table :override org-md--convert-to-html)))) ; Zola uses CommonMark, so doesn't support Markdown tables
+ (let* ((org-export-output-file-name-locked (lambda (extension &rest _)
+ (concat (plist-get plist :publishing-directory)
+ "locked-"
+ (file-name-base filename)
+ extension)))
+ (node (car (seq-filter
+ (lambda (node) (file-equal-p (org-roam-node-file node) filename))
+ (org-roam-node-list))))
+ (locked-p (cond ((file-equal-p filename
+ (file-name-concat (plist-get plist :base-directory) (plist-get plist :sitemap-filename)))
+ nil)
+ (t
+ (member "locked" (org-roam-node-tags node)))))
+ (advice '((org-gfm-inner-template :override za/org-md-template-zola)
+ (org-md-link :filter-return za/org-md-link-zola)
+ (org-html--format-image :filter-args za/org-html--format-image)
+ (org-gfm-table :override org-md--convert-to-html)))) ; Zola uses CommonMark, so doesn't support Markdown tables
(dolist (orig-type-new advice) (apply #'advice-add orig-type-new))
- (org-gfm-publish-to-gfm plist filename pub-dir)
- (dolist (orig-type-new advice)
- (advice-remove (nth 0 orig-type-new)
- (nth 2 orig-type-new)))))
+ (unwind-protect
+ (cond (locked-p
+ (advice-add #'org-export-output-file-name :override org-export-output-file-name-locked)
+ (unwind-protect
+ (org-gfm-publish-to-gfm plist filename pub-dir)
+ (advice-remove #'org-export-output-file-name org-export-output-file-name-locked)))
+ (t
+ (org-gfm-publish-to-gfm plist filename pub-dir)))
+ (dolist (orig-type-new advice)
+ (advice-remove (nth 0 orig-type-new)
+ (nth 2 orig-type-new))))))
#+end_src
Finally, the list of things we can publish with their respective publishin functions:
@@ -2162,6 +2264,7 @@ And a function to rsync to my VPS:
(async-shell-command (format "cd %s && zola build && yes|publish" za/my-website-dir) "*Async Shell publish*"))
#+end_src
*** Rebuild org cache
+
#+begin_src emacs-lisp
(defun za/force-org-rebuild-cache ()
"Rebuild the `org-mode' and `org-roam' cache."
@@ -2187,6 +2290,7 @@ This way, I can just check my calendar.
(org-caldav-calendar-id za/caldav-org-calendar-id)
(org-caldav-inbox za/org-life-calendar-inbox)
(org-caldav-files (cons (car (split-string org-archive-location "::")) org-agenda-files))
+ (org-caldav-sync-todo t)
(org-icalendar-include-todo 'all)
(org-icalendar-use-deadline '(event-if-todo event-if-not-todo todo-due))
(org-icalendar-use-scheduled '(todo-start event-if-todo event-if-not-todo))
@@ -2200,6 +2304,8 @@ This way, I can just check my calendar.
(100 "DONE")
(100 "CANCELLED")))
:config
+ (defun za/caldav-after-sync-notify () (za/notify "org-caldav sync complete" "Finished syncing"))
+ (advice-add #'org-caldav-sync :after #'za/caldav-after-sync-notify)
(advice-add #'org-caldav-sync :around #'za/notify-on-interactivity))
#+end_src
@@ -2299,7 +2405,7 @@ Drag-and-drop images to Emacs Org mode.
(use-package org-download
:custom
(org-download-method 'attach)
- (org-download-backend "curl"))
+ (org-download-backend t))
#+end_src
*** org-sticky-header
@@ -2328,13 +2434,11 @@ Displays in the header-line the Org heading for the node that’s at the top of
Lets you draw stuff in org mode documents.
#+begin_src emacs-lisp
- (use-package edraw-org
- :init (za/package-vc-install :repo "misohena/el-easydraw" :name "edraw")
- :after org
- :ensure nil
- :config
+ (za/package-vc-install :repo "misohena/el-easydraw" :name "edraw")
+ (with-eval-after-load 'org
+ (require 'edraw-org)
(edraw-org-setup-default)
- :bind ("C-c q c" . edraw-color-picker-insert-color))
+ (bind-key "C-c q c" #'edraw-color-picker-insert-color))
#+end_src
*** TODO the path for org-roam export and data export should be configurable, not hard-coded