aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules5
-rw-r--r--emacs/.emacs.d/init/ycp-dired.el1
-rw-r--r--emacs/.emacs.d/init/ycp-editing.el9
-rw-r--r--emacs/.emacs.d/init/ycp-emms.el3
-rw-r--r--emacs/.emacs.d/init/ycp-gnus.el9
-rw-r--r--emacs/.emacs.d/init/ycp-markup.el28
-rw-r--r--emacs/.emacs.d/init/ycp-org.el18
-rw-r--r--emacs/.emacs.d/init/ycp-prog.el31
-rw-r--r--emacs/.emacs.d/init/ycp-reading.el2
-rw-r--r--emacs/.emacs.d/init/ycp-system.el27
-rw-r--r--emacs/.emacs.d/init/ycp-vc.el16
-rw-r--r--emacs/.emacs.d/init/ycp-web.el1
m---------emacs/.emacs.d/lisp/buildbot.el0
m---------emacs/.emacs.d/lisp/emacs-libvterm0
-rw-r--r--emacs/.emacs.d/lisp/my/chatbot-mode.el376
-rw-r--r--emacs/.emacs.d/lisp/my/my-dired.el12
-rw-r--r--emacs/.emacs.d/lisp/my/my-gnus.el7
-rw-r--r--emacs/.emacs.d/lisp/my/my-libgen.el25
-rw-r--r--emacs/.emacs.d/lisp/my/my-magit.el4
-rw-r--r--emacs/.emacs.d/lisp/my/my-mariadb.el124
-rw-r--r--emacs/.emacs.d/lisp/my/my-markdown.el28
-rw-r--r--emacs/.emacs.d/lisp/my/my-media-segment.el3
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el99
-rw-r--r--emacs/.emacs.d/lisp/my/my-web.el2
-rw-r--r--emacs/.emacs.d/lisp/my/my-wget.el17
-rw-r--r--emacs/.emacs.d/lisp/org-nldate/nldate.el437
-rw-r--r--emacs/.emacs.d/lisp/org-nldate/org-nldate.el214
m---------emacs/.emacs.d/lisp/ox-jira.el0
-rw-r--r--mariadb-server/.dir-locals.el8
-rw-r--r--misc/.bashrc17
-rw-r--r--misc/.config/i3/config6
-rwxr-xr-xmisc/.config/i3/focus.sh33
-rwxr-xr-xmisc/.config/i3/rofi-pass.sh3
-rw-r--r--misc/.config/mpv/input.conf1
-rw-r--r--misc/.config/mpv/mpv.conf3
-rw-r--r--misc/.gdbinit26
-rwxr-xr-xmisc/bin/emms-audio-focus.sh45
-rwxr-xr-xmisc/bin/emms.sh3
-rwxr-xr-xmisc/bin/org-a-sync.el27
39 files changed, 1597 insertions, 73 deletions
diff --git a/.gitmodules b/.gitmodules
index dc001a5..5459d5c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -78,7 +78,7 @@
url = https://github.com/ahungry/org-jira
[submodule "emacs/.emacs.d/lisp/ox-jira.el"]
path = emacs/.emacs.d/lisp/ox-jira.el
- url = https://github.com/stig/ox-jira.el
+ url = https://g.ypei.me/ox-jira.el.git
[submodule "emacs/.emacs.d/lisp/dired-hist"]
path = emacs/.emacs.d/lisp/dired-hist
url = https://github.com/karthink/dired-hist
@@ -127,3 +127,6 @@
[submodule "emacs/.emacs.d/lisp/ttrss.el"]
path = emacs/.emacs.d/lisp/ttrss.el
url = https://g.ypei.me/ttrss.el.git
+[submodule "emacs/.emacs.d/lisp/emacs-libvterm"]
+ path = emacs/.emacs.d/lisp/emacs-libvterm
+ url = https://github.com/akermu/emacs-libvterm
diff --git a/emacs/.emacs.d/init/ycp-dired.el b/emacs/.emacs.d/init/ycp-dired.el
index 056bfce..e8364b1 100644
--- a/emacs/.emacs.d/init/ycp-dired.el
+++ b/emacs/.emacs.d/init/ycp-dired.el
@@ -46,6 +46,7 @@
"C-x C-j" #'dired-jump
;; to open a dir in dired, find-file is more than sufficient
"C-x d" #'dired-jump)
+ (add-hook 'dired-mode-hook (lambda () (recentf-add-file default-directory)))
)
(my-package my-dired
diff --git a/emacs/.emacs.d/init/ycp-editing.el b/emacs/.emacs.d/init/ycp-editing.el
index 031ae31..768e9bd 100644
--- a/emacs/.emacs.d/init/ycp-editing.el
+++ b/emacs/.emacs.d/init/ycp-editing.el
@@ -145,7 +145,14 @@
(my-package flyspell
(my-keybind flyspell-mode-map
"C-." nil
- ))
+ )
+ (define-advice flyspell-check-word-p
+ (:around (fn) skip-org-speed-commands)
+ (if (and (eq this-command 'org-self-insert-command)
+ (bound-and-true-p org-use-speed-commands)
+ (bound-and-true-p org-speed-command))
+ nil ; a speed key, not typing
+ (funcall fn))))
(my-package pyim
(:delay 30)
diff --git a/emacs/.emacs.d/init/ycp-emms.el b/emacs/.emacs.d/init/ycp-emms.el
index e49209f..65a121d 100644
--- a/emacs/.emacs.d/init/ycp-emms.el
+++ b/emacs/.emacs.d/init/ycp-emms.el
@@ -43,6 +43,7 @@
(my-keybind emms-playlist-mode-map "C-x C-f" #'emms-play-playlist)
(setq emms-player-list '(emms-player-mpv emms-player-vlc))
(setq emms-player-vlc-parameters '("--intf=qt" "--extraintf=rc"))
+ (add-to-list 'emms-player-mpv-parameters "--audio-client-name=emms" t)
(setq emms-playlist-buffer-name "*EMMS Playlist*")
(setq emms-source-file-directory-tree-function
'emms-source-file-directory-tree-find)
@@ -50,6 +51,8 @@
(setq emms-info-auto-update nil)
(add-hook 'emms-playlist-mode-hook #'hl-line-mode)
(add-hook 'emms-metaplaylist-mode-hook #'hl-line-mode)
+ (setq server-name "emms")
+ (server-start)
)
(my-package my-emms
diff --git a/emacs/.emacs.d/init/ycp-gnus.el b/emacs/.emacs.d/init/ycp-gnus.el
index 7275363..14dff9f 100644
--- a/emacs/.emacs.d/init/ycp-gnus.el
+++ b/emacs/.emacs.d/init/ycp-gnus.el
@@ -63,7 +63,9 @@
(my-keybind message-mode-map
"M-n" #'my-message-after-next-cited
"M-p" #'my-message-before-previous-cited
- "C-c M-e" #'my-message-elide-remaining)
+ "C-c M-e" #'my-message-elide-remaining
+ "C-c l" #'my-message-send-lock-mode)
+ (add-hook 'message-send-hook #'my-message-check-send-lock)
)
(my-package smtpmail
@@ -186,6 +188,7 @@
(setq gnus-thread-sort-functions
'(gnus-thread-sort-by-most-recent-date))
(setq gnus-summary-next-group-on-exit nil)
+ (setq gnus-summary-save-parts-default-mime ".")
)
(my-package gnus-art
@@ -230,7 +233,9 @@
(setq bbdb-mail-user-agent 'gnus-user-agent)
(setq bbdb-update-records-p 'create)
(setq bbdb-message-clean-mail-function 'my-bbdb-clean-mail)
- (my-setq-from-local bbdb-message-ignore-mail-re)
+ (setq bbdb-message-ignore-mail-re "not?[-_]?reply\\|:[ \t]*;\\'")
+ (setq bbdb-message-ignore-name-re
+ "\\`\\(undisclosed[- ]recipients?\\|recipient list not shown\\)\\'")
(setq bbdb-add-name nil)
(require 'my-bbdb)
(my-keybind bbdb-mode-map "C-c C-c" #'my-bbdb-done)
diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el
index a53d542..1697949 100644
--- a/emacs/.emacs.d/init/ycp-markup.el
+++ b/emacs/.emacs.d/init/ycp-markup.el
@@ -62,11 +62,25 @@
;;; markdown
(my-package markdown-mode
(:delay 60)
- (my-keybind markdown-mode-map "C-c C-l" 'markdown-insert-link)
- (setq markdown-hide-urls t)
+ (my-keybind markdown-mode-map
+ "C-c C-l" 'markdown-insert-link
+ "C-c M-w" 'my-markdown-copy-block
+ )
+ (setq-default markdown-hide-urls t)
(put 'markdown-translate-filename-function 'safe-local-variable 'functionp)
+ (add-hook 'markdown-mode-hook 'turn-off-auto-fill)
(require 'my-markdown)
- (my-keybind markdown-mode-map "<ret>" 'my-markdown-maybe-follow-thing-at-point))
+ (my-keybind markdown-mode-map
+ "<RET>" 'my-markdown-maybe-follow-thing-at-point
+ "C-`" 'markdown-view-mode
+ "C-M-n" 'my-markdown-next-block
+ "C-M-p" 'my-markdown-prev-block)
+ (my-keybind markdown-view-mode-map
+ "C-`" 'markdown-mode
+ "o" 'markdown-follow-thing-at-point))
+
+(my-package chatbot-mode
+ (:delay 60))
(my-package wiki
(my-keybind wiki-mode-map
@@ -146,10 +160,10 @@
;;; lilypond
(add-to-list 'load-path "/usr/share/emacs/site-lisp")
-(autoload 'LilyPond-mode "lilypond-mode" "LilyPond Editing Mode" t)
-(add-to-list 'auto-mode-alist '("\\.ly\\'" . LilyPond-mode))
-(add-to-list 'auto-mode-alist '("\\.ily\\'" . LilyPond-mode))
-(add-hook 'LilyPond-mode-hook (lambda () (turn-on-font-lock)))
+(autoload 'lilypond-mode "lilypond-mode" "LilyPond Editing Mode" t)
+(add-to-list 'auto-mode-alist '("\\.ly\\'" . lilypond-mode))
+(add-to-list 'auto-mode-alist '("\\.ily\\'" . lilypond-mode))
+(add-hook 'lilypond-mode-hook (lambda () (turn-on-font-lock)))
(provide 'ycp-markup)
;;; ycp-markup.el ends here
diff --git a/emacs/.emacs.d/init/ycp-org.el b/emacs/.emacs.d/init/ycp-org.el
index 140b54d..69abc47 100644
--- a/emacs/.emacs.d/init/ycp-org.el
+++ b/emacs/.emacs.d/init/ycp-org.el
@@ -30,6 +30,7 @@
;;; the glorious org mode
(my-package org
+ (calendar-set-date-style 'iso)
(my-keybind global-map
"M-u" #'org-store-link
"C-c a" #'org-agenda
@@ -191,7 +192,7 @@
(setq org-agenda-custom-commands
`(("A" "Agenda and next"
((agenda ""
- ((org-agenda-span 32)
+ ((org-agenda-span 63)
;; only works when `org-agenda-start-on-weekday'
;; is nil
(org-agenda-start-day "-2d")))
@@ -467,7 +468,6 @@
(my-keybind global-map
"<f6>" #'my-org-open-or-cycle-notes)
(my-keybind org-mode-map
- "C-c 1" #'my-org-insert-date-range
"C-c ns" #'my-org-substitute-gnus-link-after-archiving
"C-x w" #'my-org-copy-link-at-point
"C-'" #'my-org-store-link-and-return
@@ -541,7 +541,19 @@
"o" #'org-remark-view
"d" #'org-remark-delete)
(with-eval-after-load 'nov
- (org-remark-nov-mode +1)))
+ (org-remark-nov-mode +1))
+ (require 'diff-mode)
+ (my-keybind diff-mode-shared-map
+ "M-n" #'org-remark-next
+ "M-p" #'org-remark-prev
+ "M" #'my-org-remark-open-or-create
+ "d" #'org-remark-delete))
+
+(my-package org-nldate
+ (:delay 60)
+ (my-keybind org-mode-map
+ "C-c 1" #'org-nldate-time-stamp)
+ )
(provide 'ycp-org)
;;; ycp-org.el ends here
diff --git a/emacs/.emacs.d/init/ycp-prog.el b/emacs/.emacs.d/init/ycp-prog.el
index f74e339..c601ada 100644
--- a/emacs/.emacs.d/init/ycp-prog.el
+++ b/emacs/.emacs.d/init/ycp-prog.el
@@ -32,14 +32,17 @@
;;; comint, shell, eshell
(my-package comint
(setq ansi-color-for-comint-mode t)
+ (add-hook 'comint-mode-hook 'turn-off-auto-fill)
(setq-default comint-scroll-to-bottom-on-input t)
(setq-default comint-scroll-to-bottom-on-output nil)
(setq-default comint-input-autoexpand 'input)
(setq comint-prompt-read-only t)
(setq comint-buffer-maximum-size 9999)
(setq comint-completion-autolist t)
- (define-key comint-mode-map (kbd "C-<up>") 'windmove-up)
- (define-key comint-mode-map (kbd "C-<down>") 'windmove-down)
+ (my-keybind comint-mode-map
+ "C-<up>" 'windmove-up
+ "C-<down>" 'windmove-down
+ )
(setq comint-input-ring-size 5000)
(setq comint-input-ignoredups t)
(setq comint-terminfo-terminal "dumb")
@@ -92,6 +95,7 @@
"d" 'my-gdb-frames-remove-breakpoint
"o" 'gdb-select-frame
"s" 'my-gdb-switch-to-source-buffer
+ "t" 'my-gdb-frames-add-temp-breakpoint
"n" 'my-gdb-frames-select-next
"p" 'my-gdb-frames-select-previous)
(my-keybind gdb-breakpoints-mode-map
@@ -112,6 +116,7 @@
)
(add-hook 'gud-mode-hook 'my-gud-comint-set-prompt-regexp)
(add-hook 'gud-mode-hook 'company-mode)
+ (add-hook 'gud-mode-hook (lambda () (setq-local company-idle-delay nil)))
;; Don't make this a general comint-mode hook, as it will overwrite
;; bash history rather than append to it.
(add-hook 'gud-mode-hook 'my-comint-add-write-history-hook)
@@ -122,11 +127,13 @@
(:delay 10)
;; tab-width 8 for ls etc.
(add-hook 'shell-mode-hook 'my-set-tab-width-to-8)
- (my-keybind comint-mode-map "C-<return>"
- #'my-comint-send-input-and-return-prompt)
+ (my-keybind comint-mode-map
+ "C-<return>" #'my-comint-send-input-and-return-prompt
+ "<f2>" #'my-comint-restart
+ "C-c M-w" #'my-comint-copy-last-turn
+ )
(add-to-list 'my-buffer-create-functions
'(shell-mode . my-shell-with-directory))
- (my-keybind comint-mode-map "<f2>" #'my-comint-restart)
(add-hook 'shell-mode-hook 'my-shell-disable-company-if-remote)
(my-keybind global-map "<f7>" #'my-shell-open-or-cycle)
)
@@ -201,10 +208,15 @@
(c++-mode . "user")
(other . "gnu")))
(setq-default c-electric-flag t)
+ (setq-default c-block-comment-prefix "")
;; prevent backspace from untabifying
(setq c-backspace-function 'delete-backward-char)
(require 'my-mariadb)
(add-to-list 'c-style-alist my-c-style-maria-spider)
+ (add-hook 'c-mode-hook
+ (lambda () (setq show-trailing-whitespace nil)))
+ (add-hook 'c++-mode-hook
+ (lambda () (setq show-trailing-whitespace nil)))
)
(my-package my-prog
@@ -529,6 +541,8 @@
(:install t)
(add-to-list 'auto-mode-alist '("\\.yy\\'" . bison-mode))
(define-key bison-mode-map (kbd "C-c C-c") 'project-compile)
+ (add-hook 'bison-mode-hook 'turn-off-auto-fill)
+ (setq bison-rule-enumeration-column 10)
(require 'my-prog)
(add-hook 'bison-mode-hook
'my-bison-set-imenu-create-index-function)
@@ -561,5 +575,12 @@
(my-package nroff-mode
(add-to-list 'auto-mode-alist '("\\.mdoc\\'" . nroff-mode)))
+(my-package vterm
+ (:delay 60)
+ (my-keybind vterm-mode-map
+ "C-`" 'vterm-copy-mode)
+ (my-keybind vterm-copy-mode-map
+ "C-`" 'vterm-copy-mode))
+
(provide 'ycp-prog)
;;; ycp-prog.el ends here
diff --git a/emacs/.emacs.d/init/ycp-reading.el b/emacs/.emacs.d/init/ycp-reading.el
index 5c0284e..e8575b9 100644
--- a/emacs/.emacs.d/init/ycp-reading.el
+++ b/emacs/.emacs.d/init/ycp-reading.el
@@ -26,6 +26,8 @@
;;; Code:
+(setq text-scale-mode-step 1.1)
+
(my-package belf
(my-setq-from-local belf-dir belf-locate-dirs)
(add-hook 'find-file-hook 'belf-recent-add-current)
diff --git a/emacs/.emacs.d/init/ycp-system.el b/emacs/.emacs.d/init/ycp-system.el
index 5670eed..e68b5ef 100644
--- a/emacs/.emacs.d/init/ycp-system.el
+++ b/emacs/.emacs.d/init/ycp-system.el
@@ -55,28 +55,31 @@
'((explicit-shell-file-name . "/data/data/com.termux/files/usr/bin/bash")
(shell-file-name . "/data/data/com.termux/files/usr/bin/bash")
(tramp-remote-path . ("/data/data/com.termux/files/usr/bin"))))
- (connection-local-set-profiles
- `(:application tramp :protocol "ssh"
- :machine ,(my-get-from-local my-tramp-termux-machine))
- 'termux-bash)
+ (when-let ((machine (my-get-from-local my-tramp-termux-machine)))
+ (connection-local-set-profiles
+ `(:application tramp :protocol "ssh"
+ :machine ,machine)
+ 'termux-bash))
(connection-local-set-profile-variables
'ghcup-bash
'((tramp-remote-path . ("~/.ghcup/bin" "~/.local/bin" tramp-default-remote-path))))
- (connection-local-set-profiles
- `(:application tramp :protocol "ssh"
- :machine ,(my-get-from-local my-tramp-ghcup-machine))
- 'ghcup-bash)
+ (when-let ((machine (my-get-from-local my-tramp-ghcup-machine)))
+ (connection-local-set-profiles
+ `(:application tramp :protocol "ssh"
+ :machine ,machine)
+ 'ghcup-bash))
(connection-local-set-profile-variables
'guix-bash
'((explicit-shell-file-name . "/run/current-system/profile/bin/sh")
(shell-file-name . "/run/current-system/profile/bin/sh")
(tramp-remote-path . ("/run/current-system/profile/bin" "/run/current-system/profile/sbin"))))
- (connection-local-set-profiles
- `(:application tramp :protocol "ssh"
- :machine ,(my-get-from-local my-tramp-guix-machine))
- 'guix-bash)
+ (when-let ((machine (my-get-from-local my-tramp-guix-machine)))
+ (connection-local-set-profiles
+ `(:application tramp :protocol "ssh"
+ :machine ,machine)
+ 'guix-bash))
(connection-local-set-profile-variables
'adb-shell
diff --git a/emacs/.emacs.d/init/ycp-vc.el b/emacs/.emacs.d/init/ycp-vc.el
index e3399be..61989e0 100644
--- a/emacs/.emacs.d/init/ycp-vc.el
+++ b/emacs/.emacs.d/init/ycp-vc.el
@@ -116,6 +116,12 @@
(require 'magit-diff)
(setq magit-diff-refine-hunk t)
(setq magit-diff-adjust-tab-width t)
+ (transient-set-default-level 'magit-diff:--color-moved 4)
+ (transient-set-default-level 'magit-diff:--color-moved-ws 4)
+ (put 'magit-revision-mode 'magit-diff-default-arguments
+ '("--stat" "--no-ext-diff"
+ "--color-moved=zebra"
+ "--color-moved-ws=allow-indentation-change"))
(add-hook 'magit-diff-mode-hook #'my-turn-off-truncate-lines)
(require 'magit-repos)
@@ -127,6 +133,11 @@
(require 'magit-branch)
(advice-add 'magit-checkout :filter-args #'my-magit-ignore-other-worktrees)
+
+ (require 'magit-log)
+ (transient-suffix-put 'magit-log "-i" :level 4)
+ (put 'magit-log-mode 'magit-log-default-arguments
+ '("-n256" "--regexp-ignore-case" "--graph" "--decorate"))
)
(my-package my-magit
@@ -134,6 +145,11 @@
(my-keybind global-map
"C-x pM" #'my-project-magit-at
"C-x g" #'my-magit-status)
+ (eval-after-load 'magit
+ '(progn
+ (define-key magit-mode-map "'" 'my-magit-show-head)
+ (transient-append-suffix 'magit-dispatch '(0 -1 -1)
+ '("'" "Show HEAD commit" my-magit-show-head))))
)
(my-package git-email
diff --git a/emacs/.emacs.d/init/ycp-web.el b/emacs/.emacs.d/init/ycp-web.el
index 89099d9..407b2f6 100644
--- a/emacs/.emacs.d/init/ycp-web.el
+++ b/emacs/.emacs.d/init/ycp-web.el
@@ -53,6 +53,7 @@
(my-package osm
(:install t)
(:delay 30)
+ (setq osm-server 'de)
(require 'my-osm)
(my-keybind osm-mode-map
"C-<left>" nil
diff --git a/emacs/.emacs.d/lisp/buildbot.el b/emacs/.emacs.d/lisp/buildbot.el
-Subproject d614eea91ca5717c2b0019dae8c85e6a24873f3
+Subproject fb0660ee2e8223be1bbedb591ea1ffa27eedd74
diff --git a/emacs/.emacs.d/lisp/emacs-libvterm b/emacs/.emacs.d/lisp/emacs-libvterm
new file mode 160000
+Subproject 6d715a93fa0e5182bc137d4db09f376e06938aa
diff --git a/emacs/.emacs.d/lisp/my/chatbot-mode.el b/emacs/.emacs.d/lisp/my/chatbot-mode.el
new file mode 100644
index 0000000..7d56c09
--- /dev/null
+++ b/emacs/.emacs.d/lisp/my/chatbot-mode.el
@@ -0,0 +1,376 @@
+;;; chatbot-mode.el --- Major mode for chatbot chat logs -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2026 Free Software Foundation.
+
+;; Version: 0.1
+;; Package-Requires: ((emacs "27.1") (markdown-mode "2.5"))
+;; Keywords: convenience, text
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU Affero General Public License as
+;; published by the Free Software Foundation, either version 3 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public
+;; License along with this program. If not, see
+;; <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; chatbot-mode keeps a log of a conversation with a chatbot that runs
+;; in a browser tab. You write your messages in Emacs and paste the
+;; bot's replies back in, so the whole conversation ends up in one plain
+;; Markdown file.
+;;
+;; * File format
+;;
+;; A log is an ordinary Markdown file. Each message begins with one of
+;; two exact level-1 headings:
+;;
+;; # User
+;;
+;; How do I reverse a list in Elisp?
+;;
+;; # Assistant
+;;
+;; Use `reverse' or `nreverse'...
+;;
+;; Only those two exact lines count as dividers. Any other headings in
+;; a reply, including h1s, are part of the message. The heading is the
+;; only thing that gives a message its role: nothing is worked out from
+;; the order. If you forget to paste a reply and write another message,
+;; you just get two "# User" messages in a row.
+;;
+;; * Installation
+;;
+;; Put this file somewhere on your `load-path', then add:
+;;
+;; (require 'chatbot-mode)
+;;
+;; Files named *.chat.md then open in `chatbot-mode'. In any other
+;; buffer, use M-x chatbot-mode.
+;;
+;; * Usage
+;;
+;; The log is read-only and the Markdown markup is hidden, as in
+;; `markdown-view-mode', which chatbot-mode is derived from.
+;;
+;; M-n/M-p Go to the next / previous message. The plain n and p
+;; keys keep their markdown-view-mode heading navigation.
+;; M-<up>, M-<down>
+;; Move the message at point up or down past its neighbour,
+;; and save.
+;; e Edit the message at point. At the end of the buffer
+;; (reached with M->), before the first message, or with
+;; C-u, write a new "# User" message instead.
+;; m Write a new "# User" message, wherever point is.
+;; >, M-; Quote the region, or the whole message at point, into the
+;; compose buffer, starting a new "# User" message if there
+;; is none. Every line gets "> ", with a blank line before
+;; and after the quote. (This replaces markdown-view-mode's
+;; > for end of buffer; M-> still does that.)
+;; C-y, M-y Paste the clipboard as a new "# Assistant" message.
+;; c Toggle `chatbot-catch-up-mode' (" Catch-up" in the mode
+;; line). While it is on, C-y and M-y paste the clipboard
+;; with the role opposite to the last message's, so you can
+;; catch up on several turns you forgot to copy over.
+;; M-w Copy the message at point, without its heading. With an
+;; active region, copy the region as usual.
+;; C-/ Undo the last addition or edit, and save. Repeat to undo
+;; further. Also on C-_ and C-x u.
+;; C-x C-q Switch to the editable Markdown source in `markdown-mode'.
+;; C-x C-q there switches back to `chatbot-mode'. Changes
+;; made in the source are not saved automatically.
+;; q Kill the buffer (inherited from `markdown-view-mode').
+;;
+;; Pressing e opens a *chatbot-compose* buffer in `markdown-mode'. In
+;; that buffer:
+;;
+;; C-c C-c Write the text into the log, save the file, and copy the
+;; text to the kill ring so you can paste it into the
+;; browser.
+;; C-c C-k Discard the text and leave the log unchanged.
+;;
+;; The log file is saved after every paste and every confirm.
+;;
+;; In the compose buffer, these two bindings take the place of
+;; markdown-mode's C-c C-c prefix and its C-c C-k command.
+;;
+;; M-y refuses to paste text identical to the last message. This
+;; catches the case where you press M-y before copying the reply, when
+;; the kill ring still holds your own message.
+
+;;; Code:
+
+(require 'markdown-mode)
+(require 'subr-x)
+(require 'seq)
+
+(defconst chatbot-divider-regexp "^# \\(User\\|Assistant\\)[ \t]*$"
+ "Regexp matching a message divider; group 1 is the role.")
+
+(defun chatbot--message-at-point ()
+ "Return (ROLE BEG END BODY) for the message at point, or nil.
+BEG is the start of its heading, END the start of the next divider."
+ (save-excursion
+ (end-of-line)
+ (when (re-search-backward chatbot-divider-regexp nil t)
+ (let ((role (match-string-no-properties 1)) (beg (point)) body-beg)
+ (forward-line 1)
+ (setq body-beg (point))
+ (let ((end (if (re-search-forward chatbot-divider-regexp nil t)
+ (match-beginning 0)
+ (point-max))))
+ (list role beg end (string-trim
+ (buffer-substring-no-properties body-beg end))))))))
+
+(defun chatbot--write (role text &optional beg end)
+ "Insert a ROLE message with TEXT, replacing BEG..END or appending.
+Save the buffer and return the position of the message."
+ (let ((inhibit-read-only t)
+ (msg (concat "# " role "\n\n" (string-trim text) "\n")))
+ (undo-boundary)
+ (if beg
+ (progn (delete-region beg end)
+ (goto-char beg)
+ (insert msg (if (eobp) "" "\n")))
+ (goto-char (point-max))
+ (skip-chars-backward " \t\n")
+ (delete-region (point) (point-max))
+ (unless (bobp) (insert "\n\n"))
+ (setq beg (point))
+ (insert msg))
+ (when buffer-file-name (save-buffer))
+ beg))
+
+(defun chatbot-undo (&optional arg)
+ "Undo the last addition or edit to the chat log, then save it.
+Repeat to undo further. ARG is passed to `undo'."
+ (interactive "P")
+ (let ((inhibit-read-only t))
+ (undo arg))
+ (when buffer-file-name (save-buffer)))
+
+(defun chatbot-next-message (&optional n)
+ "Go to the start of the Nth next message."
+ (interactive "p")
+ (dotimes (_ (or n 1))
+ (end-of-line)
+ (if (re-search-forward chatbot-divider-regexp nil t)
+ (beginning-of-line)
+ (goto-char (point-max))))
+ (unless (eobp) (recenter 0)))
+
+(defun chatbot-previous-message (&optional n)
+ "Go to the start of the Nth previous message."
+ (interactive "p")
+ (dotimes (_ (or n 1))
+ (beginning-of-line)
+ (unless (re-search-backward chatbot-divider-regexp nil t)
+ (goto-char (point-min))))
+ (recenter 0))
+
+(defun chatbot-move-message-down (&optional up)
+ "Swap the message at point with the next one, or the previous if UP.
+Save the buffer and leave point on the moved message."
+ (interactive)
+ (let* ((cur (or (chatbot--message-at-point) (user-error "No message here")))
+ (other (save-excursion
+ (goto-char (if up (max (point-min) (1- (nth 1 cur)))
+ (nth 2 cur)))
+ (unless (if up (= (nth 1 cur) (point-min)) (eobp))
+ (chatbot--message-at-point))))
+ (a (if up other cur))
+ (b (if up cur other))
+ (fmt (lambda (m) (concat "# " (nth 0 m) "\n\n" (nth 3 m) "\n")))
+ (inhibit-read-only t))
+ (unless other (user-error "No message %s this one" (if up "above" "below")))
+ (let ((tail (if (= (nth 2 b) (point-max)) "" "\n"))
+ (moved-b (funcall fmt b)))
+ (undo-boundary)
+ (delete-region (nth 1 a) (nth 2 b))
+ (goto-char (nth 1 a))
+ (insert moved-b "\n" (funcall fmt a) tail)
+ (goto-char (if up (nth 1 a) (+ (nth 1 a) (length moved-b) 1))))
+ (when buffer-file-name (save-buffer))))
+
+(defun chatbot-move-message-up ()
+ "Swap the message at point with the previous one."
+ (interactive)
+ (chatbot-move-message-down t))
+
+(define-minor-mode chatbot-catch-up-mode
+ "Catch up on turns you forgot to copy over, by alternating roles.
+While on, the clipboard is pasted as User after an Assistant message,
+or before the first message, and as Assistant after a User message."
+ :lighter " Catch-up")
+
+(defun chatbot-paste-reply ()
+ "Append the clipboard as a new Assistant message.
+With `chatbot-catch-up-mode' on, use the role opposite to the last
+message's (User when there are none)."
+ (interactive)
+ (let ((text (string-trim (current-kill 0)))
+ (last (save-excursion (goto-char (point-max))
+ (chatbot--message-at-point))))
+ (when (string-empty-p text) (user-error "Clipboard is empty"))
+ (when (equal text (nth 3 last))
+ (user-error "Clipboard holds the last message; copy the reply first"))
+ (goto-char (chatbot--write (if (and chatbot-catch-up-mode
+ (not (equal (car last) "User")))
+ "User"
+ "Assistant")
+ text))
+ (recenter 0)))
+
+(defun chatbot-copy-message ()
+ "Copy the region if active, else the body of the message at point."
+ (interactive)
+ (if (use-region-p)
+ (call-interactively #'kill-ring-save)
+ (let ((msg (or (chatbot--message-at-point) (user-error "No message here"))))
+ (kill-new (nth 3 msg))
+ (message "Copied %s message" (nth 0 msg)))))
+
+(defvar-local chatbot--target nil
+ "List (LOG ROLE BEG END) the compose buffer writes back to.
+BEG and END are markers, or nil for a new message.")
+
+(defvar chatbot-compose-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-c C-c") #'chatbot-compose-confirm)
+ (define-key map (kbd "C-c C-k") #'chatbot-compose-cancel)
+ map)
+ "Keymap for `chatbot-compose-mode'.")
+
+(define-minor-mode chatbot-compose-mode
+ "Minor mode for composing a chatbot message.
+\\<chatbot-compose-mode-map>\\[chatbot-compose-confirm] to confirm, \
+\\[chatbot-compose-cancel] to cancel."
+ :lighter " Compose")
+
+(defun chatbot-compose (&optional new)
+ "Edit the message at point, or write a new one.
+A new User message is written at the end of the buffer, before the
+first message, or when NEW (the prefix argument) is non-nil."
+ (interactive "P")
+ (let* ((msg (unless (or new (eobp)) (chatbot--message-at-point)))
+ (target (if msg
+ (list (current-buffer) (nth 0 msg)
+ (copy-marker (nth 1 msg) t) (copy-marker (nth 2 msg)))
+ (list (current-buffer) "User" nil nil))))
+ (pop-to-buffer (generate-new-buffer "*chatbot-compose*"))
+ (markdown-mode)
+ (chatbot-compose-mode 1)
+ (setq chatbot--target target)
+ (when msg (insert (nth 3 msg)) (goto-char (point-min)))
+ (message "%s message: C-c C-c to confirm, C-c C-k to cancel"
+ (if msg (concat "Editing " (nth 0 msg)) "New User"))))
+
+(defun chatbot-append ()
+ "Write a new User message to append to the log, wherever point is."
+ (interactive)
+ (chatbot-compose t))
+
+(defun chatbot-quote ()
+ "Quote the region, or the message at point, into the compose buffer.
+Start a new User message if this log has no compose buffer."
+ (interactive)
+ (let* ((text (string-trim
+ (if (use-region-p)
+ (buffer-substring-no-properties (region-beginning)
+ (region-end))
+ (nth 3 (or (chatbot--message-at-point)
+ (user-error "No message here"))))))
+ (log (current-buffer))
+ (buf (seq-find (lambda (b)
+ (eq (car (buffer-local-value 'chatbot--target b)) log))
+ (buffer-list))))
+ (when (string-empty-p text) (user-error "Nothing to quote"))
+ (deactivate-mark)
+ (if buf (pop-to-buffer buf) (chatbot-compose t))
+ (delete-region (progn (skip-chars-backward " \t\n") (point))
+ (progn (skip-chars-forward " \t\n") (point)))
+ (unless (bobp) (insert "\n\n"))
+ (insert (mapconcat (lambda (line)
+ (if (string-blank-p line) ">" (concat "> " line)))
+ (split-string text "\n") "\n")
+ "\n\n")
+ (unless (eobp) (save-excursion (insert "\n\n")))))
+
+(defun chatbot-compose-confirm ()
+ "Write the message into the log, save it and copy it to the kill ring."
+ (interactive)
+ (let ((text (string-trim (buffer-string))) pos)
+ (pcase-let ((`(,log ,role ,beg ,end) chatbot--target))
+ (unless (buffer-live-p log) (user-error "The chat log buffer is gone"))
+ (when (string-empty-p text) (user-error "Message is empty"))
+ (with-current-buffer log
+ (setq pos (chatbot--write role text (and beg (marker-position beg))
+ (and end (marker-position end)))))
+ (kill-new text)
+ (quit-window t)
+ (when-let ((win (get-buffer-window log)))
+ (with-selected-window win (goto-char pos) (recenter 0)))
+ (message "Message saved and copied to the kill ring"))))
+
+(defun chatbot-compose-cancel ()
+ "Discard the message being composed."
+ (interactive)
+ (quit-window t)
+ (message "Message discarded"))
+
+(defvar chatbot-source-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-x C-q") #'chatbot-mode)
+ map)
+ "Keymap for `chatbot-source-mode'.")
+
+(define-minor-mode chatbot-source-mode
+ "Minor mode for editing a chat log as Markdown source.
+\\<chatbot-source-mode-map>\\[chatbot-mode] returns to `chatbot-mode'."
+ :lighter " Chat-Source")
+
+(defun chatbot-edit-source ()
+ "Switch to editable `markdown-mode' source of this chat log."
+ (interactive)
+ (markdown-mode)
+ (chatbot-source-mode 1)
+ (message "Editing source; C-x C-q to return to chatbot-mode"))
+
+(defvar chatbot-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "M-n") #'chatbot-next-message)
+ (define-key map (kbd "M-p") #'chatbot-previous-message)
+ (define-key map (kbd "M-<up>") #'chatbot-move-message-up)
+ (define-key map (kbd "M-<down>") #'chatbot-move-message-down)
+ (define-key map (kbd "e") #'chatbot-compose)
+ (define-key map (kbd "m") #'chatbot-append)
+ (define-key map (kbd ">") #'chatbot-quote)
+ (define-key map (kbd "M-;") #'chatbot-quote)
+ (define-key map (kbd "M-y") #'chatbot-paste-reply)
+ (define-key map (kbd "C-y") #'chatbot-paste-reply)
+ (define-key map (kbd "y") #'chatbot-paste-reply)
+ (define-key map (kbd "M-w") #'chatbot-copy-message)
+ (define-key map (kbd "w") #'chatbot-copy-message)
+ (define-key map (kbd "c") #'chatbot-catch-up-mode)
+ (define-key map [remap undo] #'chatbot-undo)
+ (define-key map (kbd "C-x C-q") #'chatbot-edit-source)
+ map)
+ "Keymap for `chatbot-mode'.")
+
+;;;###autoload
+(define-derived-mode chatbot-mode gfm-view-mode "Chatbot"
+ "Major mode for read-only chatbot logs.
+\\{chatbot-mode-map}")
+
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.chat\\.md\\'" . chatbot-mode))
+
+(provide 'chatbot-mode)
+;;; chatbot-mode.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-dired.el b/emacs/.emacs.d/lisp/my/my-dired.el
index 2fdbfa9..9435b44 100644
--- a/emacs/.emacs.d/lisp/my/my-dired.el
+++ b/emacs/.emacs.d/lisp/my/my-dired.el
@@ -198,5 +198,17 @@ Format: yyyymmdd_hhmmss_[N].ext"
'my-dired-rename-by-mtime
(dired-map-over-marks (dired-get-filename) nil)))
+(defun my-dired-append-timestamp ()
+ "Append a timestamp to marked files, before the extension.
+"
+ (interactive)
+ (dolist (f (dired-get-marked-files))
+ (let* ((time (file-attribute-modification-time (file-attributes f)))
+ (ts (format-time-string "%Y%m%d-%H%M%S" time))
+ (new (concat (file-name-sans-extension f) "_" ts
+ (file-name-extension f t))))
+ (dired-rename-file f new nil)))
+ (revert-buffer))
+
(provide 'my-dired)
;;; my-dired.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-gnus.el b/emacs/.emacs.d/lisp/my/my-gnus.el
index 7623548..36f440d 100644
--- a/emacs/.emacs.d/lisp/my/my-gnus.el
+++ b/emacs/.emacs.d/lisp/my/my-gnus.el
@@ -91,6 +91,13 @@
(while (looking-at-p citexp)
(beginning-of-line 2))))
+(define-minor-mode my-message-send-lock-mode
+ "Block sending of the current message buffer."
+ :lighter (:propertize " SEND-LOCKED" face warning))
+
+(defun my-message-check-send-lock ()
+ (when my-message-send-lock-mode (user-error "Sending locked")))
+
(defun my-gnus-summary-exit-like-mu4e () (interactive)
(if (get-buffer-window (gnus-buffer-live-p gnus-article-buffer))
(gnus-summary-expand-window)
diff --git a/emacs/.emacs.d/lisp/my/my-libgen.el b/emacs/.emacs.d/lisp/my/my-libgen.el
index a8e7dca..f1c4f7c 100644
--- a/emacs/.emacs.d/lisp/my/my-libgen.el
+++ b/emacs/.emacs.d/lisp/my/my-libgen.el
@@ -135,14 +135,22 @@
my-libgen-host
(alist-get 'coverurl info)))))
+(defvar my-libgen-max-filename-length 200)
+
(defun my-libgen-format-filename (info)
- (my-make-doc-file-name (format
- "%s - %s (%s) [%s].%s"
- (alist-get 'author info)
- (alist-get 'title info)
- (alist-get 'year info)
- (alist-get 'identifier info)
- (alist-get 'extension info))))
+ (let ((name (format
+ "%s - %s (%s) [%s]"
+ (alist-get 'author info)
+ (alist-get 'title info)
+ (alist-get 'year info)
+ (alist-get 'identifier info))))
+ (my-make-doc-file-name
+ (format
+ "%s.%s"
+ (if (length> name my-libgen-max-filename-length)
+ (substring name 0 my-libgen-max-filename-length)
+ name)
+ (alist-get 'extension info)))))
(defvar my-libgen-download-dir "~/Downloads")
@@ -187,7 +195,8 @@
my-libgen-plus-host
(dom-attr
(dom-search
- (my-wget-dom (alist-get 'ads (my-libgen-plus-urls info)))
+ (my-wget-dom (alist-get 'ads (my-libgen-plus-urls info)) nil
+ "--referer" my-libgen-plus-host)
(lambda (n)
(string-match (format "get\\.php\\?md5=%s" .md5)
(or (dom-attr n 'href) ""))))
diff --git a/emacs/.emacs.d/lisp/my/my-magit.el b/emacs/.emacs.d/lisp/my/my-magit.el
index eabed05..d4c28bb 100644
--- a/emacs/.emacs.d/lisp/my/my-magit.el
+++ b/emacs/.emacs.d/lisp/my/my-magit.el
@@ -78,5 +78,9 @@ For use as a :filter-args advice"
(list revision
(cons "--ignore-other-worktrees" args))))
+(defun my-magit-show-head ()
+ (interactive)
+ (magit-show-commit "HEAD" '("--stat" "--no-ext-diff")))
+
(provide 'my-magit)
;;; my-magit.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-mariadb.el b/emacs/.emacs.d/lisp/my/my-mariadb.el
index 1759af2..dec505e 100644
--- a/emacs/.emacs.d/lisp/my/my-mariadb.el
+++ b/emacs/.emacs.d/lisp/my/my-mariadb.el
@@ -65,7 +65,6 @@
(replace-regexp-in-string
"/src"
"/build/mysql-test/var/log/mysqld.1.1.rr/latest-trace"
- ;; "/build/mysql-test/var/log/mysqld.2.1.rr/latest-trace"
(project-root (project-current t))))
(expand-file-name "~/bin/gdb-mi.sh"))))
@@ -109,9 +108,10 @@
"mysql_parse"
(lambda (val prop) (equal (alist-get 'func prop) val)))
(beginning-of-line)
+ (gdb-select-frame)
(setq level (alist-get 'level (get-text-property (point) 'gdb-frame)))))
(with-current-buffer gud-comint-buffer
- (insert "f " level)
+ (insert "p thd->query_string.string.str")
(comint-send-input))
(with-current-buffer (gdb-stack-buffer-name)
(save-excursion
@@ -294,6 +294,34 @@ switches to the buffer."
'(mtr "^\\([^ ]+\\) +\\(w[0-9]+ \\)?\\[ fail \\]"
my-mtr-compilation-error-filename))
+(defun my-mtr-reannotate ()
+ "Reannotate each statement with its line number.
+
+Does not annotate the first statement"
+ (interactive)
+ (my-mtr-deannotate)
+ (my-mtr-annotate))
+
+(defun my-mtr-annotate ()
+ "Annotate each statement with its line number.
+
+Does not annotate the first statement"
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward ";$" nil t)
+ (when (re-search-forward "^ *[a-zA-Z]" nil t)
+ (beginning-of-line 1)
+ (insert "/* " (format "%s" (line-number-at-pos)) " */ ")))))
+
+(defun my-mtr-deannotate ()
+ "Remove annotations by `my-mtr-annotate'."
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "/\\* [0-9]+ \\*/ " nil t)
+ (replace-match ""))))
+
(defun my-mtr-compilation-error-filename ()
(save-excursion
(save-match-data
@@ -326,12 +354,36 @@ switches to the buffer."
(match-string 4 buffer-file-name))))))
(setq-local
compile-command
- (format "%s %s %s %s"
+ (format "%s %s %s %s %s %s %s"
"taskset -c 0-3"
(file-name-concat build-dir "mysql-test/mtr")
+ "--force"
+ "--max-test-fail=0"
+ "--mysqld=--loose-skip-innodb-use-native-aio"
test-name
"--rr")))))
+(defun my-mtr-reduce-if (var val)
+ (save-excursion
+ (goto-char (point-min))
+ (replace-regexp (rx-to-string
+ `(seq bol (0+ space)
+ "if" (0+ space) "(" (0+ space) ,var (0+ space) ")"
+ (0+ space) eol))
+ (format "if (%s)"
+ (if (equal val "0") "0" "1")))
+ (goto-char (point-min))
+ (replace-regexp (rx-to-string
+ `(seq bol (0+ space)
+ "if" (0+ space) "(" (0+ space) "!" ,var (0+ space) ")"
+ (0+ space) eol))
+ (format "if (%s)"
+ (if (equal val "0") "1" "0")))
+ (goto-char (point-min))
+ (my-mtr-remove-if-0)
+ (goto-char (point-min))
+ (my-mtr-remove-if-1)))
+
(defun my-mtr-remove-if-1 ()
"Remove if (1) blocks"
(interactive)
@@ -369,5 +421,71 @@ switches to the buffer."
(align-regexp (point-min) (point-max) "\\(\\s-*\\) ")
(message (buffer-string)))))
+(defun my-mariadb-open-docs-url ()
+ "Open docs url of a current buffer visiting a mariadb-docs .md file.
+
+e.g.
+server/ha-and-performance/optimization-and-tuning/query-optimizations/index-condition-pushdown.md
+->
+https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/query-optimizations/index-condition-pushdown"
+ (interactive)
+ (let* ((file-name (buffer-file-name))
+ (path (file-relative-name file-name (vc-git-root file-name))))
+ (browse-url (format "https://mariadb.com/docs/%s"
+ (file-name-sans-extension path)))))
+
+(defun my-mtr-output-to-org ()
+ "Transform mtr output buffer to an org buffer"
+ (interactive)
+ (let (beg
+ (buf (current-buffer))
+ (file (make-temp-file "/tmp/mtr-output." nil ".org")))
+ (with-temp-file file
+ (insert "* Prologue" "\n")
+ (insert
+ (with-current-buffer buf
+ (goto-char (point-min))
+ (setq beg (point))
+ (re-search-forward "^=+$")
+ (beginning-of-line)
+ (buffer-substring-no-properties beg (point))))
+ (insert "* Failed tests" "\n")
+ (while (with-current-buffer buf
+ (re-search-forward
+ "^[^ ]+ \\([^ ]+\\)? +\\(w[0-9]+ \\)?\\[ fail \\]$" nil t))
+ (insert "** ")
+ (insert
+ (with-current-buffer buf
+ (beginning-of-line)
+ (setq beg (point))
+ (re-search-forward "CURRENT_TEST" nil t)
+ (beginning-of-line 2)
+ (buffer-substring-no-properties beg (point))))
+ (if (with-current-buffer buf (not (looking-at-p "^--- ")))
+ (insert (with-current-buffer buf
+ (setq beg (point))
+ (re-search-forward "^ - saving .*" nil t)
+ (beginning-of-line 2)
+ (buffer-substring-no-properties beg (point))))
+ (insert "#+begin_src diff" "\n")
+ (insert (with-current-buffer buf
+ (setq beg (point))
+ (re-search-forward "^Result \\(content\\|length\\) mismatch$" nil t)
+ (beginning-of-line)
+ (buffer-substring-no-properties beg (point))))
+ (insert "#+end_src" "\n")
+ (insert (with-current-buffer buf
+ (setq beg (point))
+ (re-search-forward "^ - \\(saving\\|skipping\\) .*" nil t)
+ (beginning-of-line 2)
+ (buffer-substring-no-properties beg (point))))))
+ (insert "* Summary" "\n")
+ (insert
+ (with-current-buffer buf
+ (re-search-forward "^-+$")
+ (beginning-of-line 2)
+ (buffer-substring-no-properties (point) (point-max)))))
+ (find-file file)))
+
(provide 'my-mariadb)
;;; my-mariadb.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-markdown.el b/emacs/.emacs.d/lisp/my/my-markdown.el
index 8b12bc8..d3835b8 100644
--- a/emacs/.emacs.d/lisp/my/my-markdown.el
+++ b/emacs/.emacs.d/lisp/my/my-markdown.el
@@ -33,5 +33,33 @@
(markdown-follow-thing-at-point arg)
(user-error (newline))))
+(defun my-markdown-copy-block ()
+ (interactive)
+ (when-let* ((bounds (markdown-get-enclosing-fenced-block-construct))
+ (beg (car bounds))
+ (end (cadr bounds)))
+ (save-excursion
+ (goto-char beg)
+ (beginning-of-line 2)
+ (setq beg (point)))
+ (save-excursion
+ (goto-char end)
+ (beginning-of-line 1)
+ (setq end (point)))
+ (kill-new (buffer-substring beg end))
+ (message "markdown code block copied!")))
+
+(defun my-markdown-next-block ()
+ (interactive)
+ (markdown-forward-block)
+ (while (and (not (markdown-code-block-at-point-p)) (not (eobp)))
+ (markdown-forward-block)))
+
+(defun my-markdown-prev-block ()
+ (interactive)
+ (markdown-backward-block)
+ (while (and (not (markdown-code-block-at-point-p)) (not (bobp)))
+ (markdown-backward-block)))
+
(provide 'my-markdown)
;;; my-markdown.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-media-segment.el b/emacs/.emacs.d/lisp/my/my-media-segment.el
index e8ee5cc..4fca988 100644
--- a/emacs/.emacs.d/lisp/my/my-media-segment.el
+++ b/emacs/.emacs.d/lisp/my/my-media-segment.el
@@ -110,7 +110,8 @@ Much faster than my-segment-media-file or my-segment-media-file-1."
(when end `("-to" ,end))
`("-c" "copy"
,(format
- (format "%%s/%%0%dd-%%s.%%s" pad) dir idx title
+ (format "%%s/%%0%dd-%%s.%%s" pad) dir idx
+ (substring title 0 (min (length title) 100))
(file-name-extension media-file-name)))))
(message "Will cut %s-%s to %s (%d/%d)..."
start (or end "") title idx total)))
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index eead408..85fd876 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -42,6 +42,14 @@
(shell (generate-new-buffer-name "*shell*"))
(with-current-buffer old-buffer (setq default-directory tmp-dir))))
+(defun my-comint-copy-last-turn ()
+ (interactive)
+ (save-excursion
+ (comint-previous-prompt 1)
+ (forward-line 0)
+ (kill-new (buffer-substring (point) comint-last-output-start)))
+ (message "Copied comint last turn"))
+
(defun my-comint-send-input-and-return-prompt ()
(interactive)
(comint-send-input)
@@ -254,21 +262,69 @@ With a prefix arg, convert from bottom to top."
(unless current-prefix-arg (setq results (reverse results)))
(kill-new (string-join results (if current-prefix-arg " < " " > "))))))
+(defconst my--gdb-frame-re
+ "^ *[0-9]+ +in \\(.*\\) of \\(.*\\)$"
+ "gdb frames buffer line: 1 = function, 2 = file:line.")
+
+(defconst my--trace-frame-re
+ (concat "^[ \t]*#[0-9]+[ \t]+0x[0-9a-f]+[ \t]+in[ \t]+"
+ "\\(.+\\)[ \t]+" ; function (may contain spaces)
+ "\\(/[^ \t]+?:[0-9]+\\)" ; /path/file:line
+ "\\(?::[0-9]+\\)?[ \t]*$") ; optional :column, dropped
+ "Sanitizer/llvm-symbolizer trace line: 1 = function, 2 = file:line.")
+
+(defun my--strip-cxx-args (name)
+ "Strip the trailing argument list (and qualifiers) from C++ NAME."
+ (let ((i (and (string-match ")[^)]*\\'" name) (match-beginning 0)))
+ (depth 0)
+ start)
+ (when i
+ (while (and (>= i 0) (not start))
+ (pcase (aref name i)
+ (?\) (setq depth (1+ depth)))
+ (?\( (setq depth (1- depth))
+ (when (= depth 0) (setq start i))))
+ (setq i (1- i))))
+ (if start (substring name 0 start) name)))
+
+(defun my--collect-stack-frames (beg end)
+ "Return org links for stack frames between BEG and END, innermost first."
+ (let (results)
+ (save-excursion
+ (goto-char beg)
+ (while (< (point) end)
+ (cond
+ ((looking-at my--gdb-frame-re)
+ (push (org-link-make-string (match-string-no-properties 2)
+ (match-string-no-properties 1))
+ results))
+ ((looking-at my--trace-frame-re)
+ (push (org-link-make-string
+ (match-string-no-properties 2)
+ (my--strip-cxx-args (match-string-no-properties 1)))
+ results)))
+ (forward-line 1)))
+ (nreverse results)))
+
(defun my-stack-frame-to-org (rev)
- "Convert stack frame in gdb frames buffer to org.
-
-Conversion is in a similar fashion to `my-org-backtrace-region'."
- (let ((results))
- (with-current-buffer (gdb-stack-buffer-name)
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward "^\\ *[0-9]+\\ +in \\(.*\\) of \\(.*\\)$" nil t)
- (setq func-name (match-string-no-properties 1)
- file-location (match-string-no-properties 2))
- (push (concat "[[" file-location "][" func-name "]]") results))))
- (unless rev (setq results (reverse results)))
+ "Convert a stack trace to org.
+
+If the region is active, parse it (gdb frames or sanitizer-style
+\"#N 0xADDR in FUNC FILE:LINE:COL\" lines). Otherwise use the gdb
+frames buffer. Conversion is in a similar fashion to
+`my-org-backtrace-region'."
+ (let ((results
+ (if (use-region-p)
+ (my--collect-stack-frames (region-beginning) (region-end))
+ (with-current-buffer (gdb-stack-buffer-name)
+ (my--collect-stack-frames (point-min) (point-max))))))
+ (when rev (setq results (reverse results)))
(string-join results (if current-prefix-arg " < " " > "))))
+(defun my-copy-stack-frame-to-org (rev)
+ (interactive "P")
+ (kill-new (my-stack-frame-to-org rev)))
+
(defun my-insert-stack-frame-to-org (rev)
(interactive "P")
(insert (my-stack-frame-to-org rev)))
@@ -340,6 +396,12 @@ left and the source buffer on the right.
(kill-buffer gud-comint-buffer))
)
+(defun my-gdb-frames-add-temp-breakpoint ()
+ (interactive)
+ (gdb-select-frame)
+ (with-current-buffer (gdb-get-source-buffer)
+ (call-interactively 'gud-tbreak)))
+
(defun my-gdb-frames-add-breakpoint ()
(interactive)
(gdb-select-frame)
@@ -600,5 +662,18 @@ the children of class at point."
(bug-reference-prog-mode)
(flyspell-prog-mode))
+(defun my-c-lineup-block-comment (langelem)
+ "Indent C block comment continuation lines.
+A closing */ lines up with /*. If /* is alone on its line, the text
+is indented by +; otherwise it lines up with /*."
+ (save-excursion
+ (back-to-indentation)
+ (if (looking-at "\\*/")
+ 0
+ (goto-char (c-langelem-pos langelem))
+ (if (looking-at "/\\*[ \t]*$")
+ '+
+ 0))))
+
(provide 'my-prog)
;;; my-prog.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-web.el b/emacs/.emacs.d/lisp/my/my-web.el
index 87c319f..7564a71 100644
--- a/emacs/.emacs.d/lisp/my/my-web.el
+++ b/emacs/.emacs.d/lisp/my/my-web.el
@@ -183,7 +183,7 @@ e.g. https://news.ycombinator.com/item?id=42505454"
(browse-url-firefox (url-recreate-url urlobj))))
(defun my-newscorp-au-url-p (url)
- (string-match-p "^\\(www\\.\\)?\\(heraldsun\\|theaustralian\\)\\.com\\.au$"
+ (string-match-p "^\\(www\\.\\)?\\(heraldsun\\|theaustralian\\|weeklytimesnow\\|thechronicle\\|couriermail\\)\\.com\\.au$"
(url-host (url-generic-parse-url url))))
(defun my-stack-overflow-url-p (url)
diff --git a/emacs/.emacs.d/lisp/my/my-wget.el b/emacs/.emacs.d/lisp/my/my-wget.el
index f3f6771..0c3d447 100644
--- a/emacs/.emacs.d/lisp/my/my-wget.el
+++ b/emacs/.emacs.d/lisp/my/my-wget.el
@@ -86,19 +86,22 @@
no-tor move-if-video-or-large)
(setq i (1+ i)))))
-(defun my-wget-out-internal (url buffer-processor &optional no-tor)
+(defun my-wget-out-internal (url buffer-processor &optional no-tor &rest args)
"Run wget on url, dump the results in a temp buffer, then apply BUFFER-PROCESSOR"
(with-temp-buffer
- (my-call-process-with-torsocks no-tor "wget" nil '(t nil) nil "-O" "-" url)
+ (apply 'my-call-process-with-torsocks
+ `(,no-tor "wget" nil (t nil) nil "-O" "-" ,url ,@args))
(call-interactively 'delete-trailing-whitespace)
(funcall buffer-processor)
))
-(defun my-wget-dom (url &optional no-tor)
- (my-wget-out-internal
- url
- (lambda () (libxml-parse-html-region (point-min) (point-max)))
- no-tor))
+(defun my-wget-dom (url &optional no-tor &rest args)
+ (apply
+ 'my-wget-out-internal
+ `(,url
+ ,(lambda () (libxml-parse-html-region (point-min) (point-max)))
+ ,no-tor
+ ,@args)))
(defun my-wget-raw (url &optional no-tor)
(my-wget-out-internal url 'buffer-string no-tor))
diff --git a/emacs/.emacs.d/lisp/org-nldate/nldate.el b/emacs/.emacs.d/lisp/org-nldate/nldate.el
new file mode 100644
index 0000000..2f14709
--- /dev/null
+++ b/emacs/.emacs.d/lisp/org-nldate/nldate.el
@@ -0,0 +1,437 @@
+;;; nldate.el --- Parse natural-language dates and recurrences -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2026 Free Software Foundation.
+
+;; Version: 0.3
+;; Package-Requires: ((emacs "28.1") (peg "1.0"))
+;; Keywords: calendar
+
+;;; Commentary:
+
+;; `nldate-parse' turns an English description of dates into plain data:
+;;
+;; (nldate-parse "Friday to Sunday from 11am to 10pm over the weekends
+;; of 13-15 and 20-22 November 2026")
+;; => (:dates ((11 13 2026) (11 14 2026) (11 15 2026)
+;; (11 20 2026) (11 21 2026) (11 22 2026))
+;; :time (660 . 1320))
+;;
+;; (nldate-parse "last Saturday of each month")
+;; => (:recurrence (:float t 6 -1) :time nil)
+;;
+;; Dates are calendar.el's (MONTH DAY YEAR) lists; times are minutes past
+;; midnight. `nldate-diary-sexp' turns a recurrence into a diary sexp
+;; such as (diary-float t 6 -1), with date arguments ordered according to
+;; `calendar-date-style'. Nothing here depends on Org; see org-nldate.el
+;; for Org timestamps.
+;;
+;; The input is parsed with a PEG grammar (see `nldate--parse') into a
+;; flat list of items; words the grammar does not know are skipped.
+;; `nldate-parse' then interprets those items.
+
+;; TODO: A diary front end, e.g. `nldate-diary-insert-entry', which reads
+;; a description in the minibuffer and adds it to `diary-file' like
+;; `diary-insert-entry': one "Nov 13, 2026 11:00-22:00 TEXT" line per
+;; date (using `calendar-date-string'), or "%%(SEXP) TEXT" for a
+;; recurrence.
+
+;;; Code:
+
+(require 'calendar)
+(require 'cl-lib)
+(require 'peg)
+(require 'subr-x)
+
+(defconst nldate--weekdays
+ '(("sunday" . 0) ("sun" . 0) ("monday" . 1) ("mon" . 1)
+ ("tuesday" . 2) ("tues" . 2) ("tue" . 2) ("wednesday" . 3) ("wed" . 3)
+ ("thursday" . 4) ("thurs" . 4) ("thur" . 4) ("thu" . 4)
+ ("friday" . 5) ("fri" . 5) ("saturday" . 6) ("sat" . 6)))
+
+(defconst nldate--months
+ '(("january" . 1) ("jan" . 1) ("february" . 2) ("feb" . 2)
+ ("march" . 3) ("mar" . 3) ("april" . 4) ("apr" . 4) ("may" . 5)
+ ("june" . 6) ("jun" . 6) ("july" . 7) ("jul" . 7) ("august" . 8)
+ ("aug" . 8) ("september" . 9) ("sept" . 9) ("sep" . 9)
+ ("october" . 10) ("oct" . 10) ("november" . 11) ("nov" . 11)
+ ("december" . 12) ("dec" . 12)))
+
+;;;; Helpers
+
+(defun nldate--lookup (word table)
+ "Look WORD up in TABLE, also trying it without a plural \"s\"."
+ (or (cdr (assoc word table))
+ (and (string-suffix-p "s" word)
+ (cdr (assoc (substring word 0 -1) table)))))
+
+(defun nldate--word-in-p (table)
+ "Non-nil if the word at point is in TABLE. Used as a PEG guard."
+ (and (looking-at "[a-z]+")
+ (nldate--lookup (match-string 0) table)))
+
+(defun nldate--today () (calendar-absolute-from-gregorian (calendar-current-date)))
+(defun nldate--abs (m d y) (calendar-absolute-from-gregorian (list m d y)))
+(defun nldate--greg (abs) (calendar-gregorian-from-absolute abs))
+(defun nldate--dow (abs) (calendar-day-of-week (nldate--greg abs)))
+
+(defun nldate--ep (abs)
+ "Endpoint (DAY MONTH YEAR) for absolute date ABS."
+ (pcase-let ((`(,m ,d ,y) (nldate--greg abs))) (list d m y)))
+
+(defun nldate--valid-p (m d y)
+ (and (<= 1 m 12) (<= 1 d (calendar-last-day-of-month m y))))
+
+(defun nldate--weekday-span (a b)
+ "Weekdays from A to B inclusive, wrapping past Saturday."
+ (let (r (i a))
+ (while (progn (push i r) (/= i b)) (setq i (% (1+ i) 7)))
+ (nreverse r)))
+
+(defun nldate--hm (h m ampm)
+ "Minutes past midnight for H:M with AMPM (nil, `am' or `pm')."
+ (when (eq ampm 'pm) (unless (= h 12) (setq h (+ h 12))))
+ (when (and (eq ampm 'am) (= h 12)) (setq h 0))
+ (unless (and (< h 24) (< m 60)) (user-error "Invalid time %d:%02d" h m))
+ (+ (* 60 h) m))
+
+(defun nldate--bare-start (h end)
+ "Start time for bare hour H before END, as in \"7-10pm\" or \"11-10pm\"."
+ (if (and (< h 12) (>= end 720) (<= (* 60 (+ h 12)) end))
+ (* 60 (+ h 12))
+ (nldate--hm h 0 nil)))
+
+;;;; Grammar
+
+(defun nldate--parse (string)
+ "Parse STRING into a list of items.
+Items are (:time START END), (:wd DAYS), (:except DAYS), (:filter DAYS),
+\(:date EP), (:range EP EP), (:float MONTH WEEKDAY N), (:monthday DAY),
+\(:cycle DAYS) and (:every). EP is (DAY MONTH YEAR), MONTH and YEAR
+possibly nil."
+ (with-temp-buffer
+ (insert (replace-regexp-in-string "[–—]" "-" (downcase string)))
+ (goto-char (point-min))
+ (with-peg-rules
+ ((top (* [space]) (list (* (and item (* [space])))) (not (any))) ; (eob) upsets the byte compiler
+ (item (or rec-nth rec-monthday rec-cycle rec-every
+ time-span time-single
+ wd-range except wd-keyword
+ between date-term wd-single
+ skip))
+ (sp (+ [space]))
+ (s (* [space]))
+ (end (not [a-z 0-9]))
+ (skip (or (+ [a-z 0-9]) (any)))
+
+ ;; Words
+ (weekday (guard (nldate--word-in-p nldate--weekdays))
+ (substring (+ [a-z]))
+ `(w -- (nldate--lookup w nldate--weekdays)))
+ (month (guard (nldate--word-in-p nldate--months))
+ (substring (+ [a-z])) (opt ".")
+ `(w -- (nldate--lookup w nldate--months)))
+ (ordinal (or (and "second" sp "last" `(-- -2))
+ (and "penultimate" `(-- -2))
+ (and "first" `(-- 1)) (and "second" `(-- 2))
+ (and "third" `(-- 3)) (and "fourth" `(-- 4))
+ (and "fifth" `(-- 5)) (and "last" `(-- -1))
+ (and (substring [1-5]) (or "st" "nd" "rd" "th")
+ `(n -- (string-to-number n))))
+ end)
+ (count (or (and (substring (+ [0-9])) `(n -- (string-to-number n)))
+ (and (or "a" "one") end `(-- 1)) (and "two" end `(-- 2))
+ (and "three" end `(-- 3)) (and "other" end `(-- 2))))
+ (unit (or (and "day" `(-- 1)) (and "week" `(-- 7))
+ (and "fortnight" `(-- 14)))
+ (opt "s") end)
+ (each (or "each" "every") end)
+
+ ;; Recurrences
+ (rec-nth ordinal sp weekday sp (or "of" "in") sp
+ (or (and (or each (and "the" end)) s "month" end `(-- t))
+ (and month (opt sp each s "year" end)))
+ `(n w m -- (list :float m w n)))
+ (rec-monthday (opt "the" sp) day sp "of" sp each s "month" end
+ `(d -- (list :monthday d)))
+ (rec-cycle (or (and "every" sp (or (and count sp unit `(n u -- (* n u)))
+ unit))
+ (and "daily" end `(-- 1)) (and "weekly" end `(-- 7))
+ (and "fortnightly" end `(-- 14)))
+ `(n -- (list :cycle n)))
+ (rec-every "every" end `(-- (list :every)))
+
+ ;; Times
+ (hour (substring [0-9] (opt [0-9])) `(h -- (string-to-number h)))
+ (ampm (or (and "am" `(-- 'am)) (and "pm" `(-- 'pm))) end)
+ (time (or (and "noon" end `(-- 720))
+ (and "midday" end `(-- 720))
+ (and "midnight" end `(-- 0))
+ (and hour [":."] (substring [0-9] [0-9]) s (or ampm (and end `(-- nil)))
+ `(h m a -- (nldate--hm h (string-to-number m) a)))
+ (and hour s ampm `(h a -- (nldate--hm h 0 a)))
+ (and hour "h" end `(h -- (nldate--hm h 0 nil)))))
+ (time-sep s (or "-" (and (or "to" "till" "until") end)) s)
+ (time-span (or (and time time-sep time)
+ (and hour time-sep time
+ `(h e -- (nldate--bare-start h e) e)))
+ `(a b -- (list :time a b)))
+ (time-single time `(a -- (list :time a nil)))
+
+ ;; Weekdays
+ (wd-sep s (or "-" (and (or "to" "through" "thru" "till" "until") end)) s)
+ (wd-range weekday wd-sep weekday
+ `(a b -- (list :wd (nldate--weekday-span a b))))
+ (except (or "except" "excluding" (and "but" sp "not") "not") sp
+ (opt "on" sp)
+ (or (and weekday wd-sep weekday `(a b -- (nldate--weekday-span a b)))
+ (and weekday `(w -- (list w))))
+ `(ds -- (list :except ds)))
+ (wd-keyword (or (and "weekends" sp "of" end) ; filler, pushes nothing
+ (and "weekdays" end `(-- (list :filter '(1 2 3 4 5))))
+ (and "weekend" (opt "s") end `(-- (list :filter '(6 0))))))
+ (wd-single weekday `(w -- (list :wd (list w))))
+
+ ;; Dates
+ (day (substring [0-9] (opt [0-9])) (opt (or "st" "nd" "rd" "th"))
+ (not [":."] [0-9]) (not s ampm) end
+ `(d -- (string-to-number d)))
+ (year (substring [0-9] [0-9] [0-9] [0-9]) end `(y -- (string-to-number y)))
+ (short-year (substring [0-9] [0-9]) end `(y -- (+ 2000 (string-to-number y))))
+ (no-value `(-- nil))
+ ;; A weekday in front of a date, as in "Monday 4th", is checked
+ ;; against it rather than used as a filter.
+ (endpoint (or (and weekday s (opt "," s) plain-endpoint
+ `(w ep -- (append ep (list w))))
+ plain-endpoint))
+ (plain-endpoint
+ (or (and year "-" (substring [0-9] (opt [0-9])) "-" (substring [0-9] (opt [0-9]))
+ end `(y m d -- (list (string-to-number d) (string-to-number m) y)))
+ ;; Day/month[/year], British order.
+ (and (substring [0-9] (opt [0-9])) "/" (substring [0-9] (opt [0-9]))
+ (or (and "/" (or year short-year)) (and end no-value))
+ `(d m y -- (list (string-to-number d) (string-to-number m) y)))
+ (and "today" end `(-- (nldate--ep (nldate--today))))
+ (and "tomorrow" end `(-- (nldate--ep (1+ (nldate--today)))))
+ (and "in" sp count sp unit
+ `(n u -- (nldate--ep (+ (nldate--today) (* n u)))))
+ ;; "13 November 2026", "13th of Nov", "13"
+ (and day (or (and s (opt "of" sp) month) no-value)
+ (or (and s (opt "," s) year) no-value)
+ `(d m y -- (list d m y)))
+ ;; "November 13, 2026"
+ (and month s day (or (and s (opt "," s) year) no-value)
+ `(m d y -- (list d m y)))))
+ (date-sep s (or "-" (and (or "to" "till" "until" "through" "thru") end)) s)
+ (between "between" sp endpoint sp "and" sp endpoint
+ `(a b -- (list :range a b)))
+ (date-term (or (and endpoint date-sep endpoint `(a b -- (list :range a b)))
+ (and endpoint `(a -- (list :date a))))))
+ (car (peg-run (peg top)
+ (lambda (_) (user-error "Cannot parse \"%s\"" string)))))))
+
+;;;; Interpretation
+
+(defun nldate--fill (eps)
+ "Fill missing months and years in endpoints EPS from the right, in place.
+A year still missing afterwards means \"the next one\"."
+ (let (m y)
+ (dolist (ep (reverse eps))
+ (if (nth 1 ep) (setq m (nth 1 ep)) (setf (nth 1 ep) m))
+ (if (nth 2 ep) (setq y (nth 2 ep)) (setf (nth 2 ep) y))
+ (unless (nth 1 ep)
+ (user-error "No month given for day %d" (car ep))))))
+
+(defun nldate--resolve (ep &optional after)
+ "Absolute day of endpoint EP; when the year is unknown pick one >= AFTER."
+ (pcase-let ((`(,d ,m ,y . ,_) ep))
+ (if y
+ (if (nldate--valid-p m d y)
+ (nldate--abs m d y)
+ (user-error "Invalid date: %d/%d/%d" d m y))
+ (let* ((after (or after (nldate--today)))
+ (y (nth 2 (nldate--greg after))))
+ (while (not (and (nldate--valid-p m d y)
+ (>= (nldate--abs m d y) after)))
+ (setq y (1+ y))
+ (when (> y (+ 10 (nth 2 (nldate--greg after))))
+ (user-error "Invalid date: %d/%d" d m)))
+ (nldate--abs m d y)))))
+
+(defun nldate--check-weekday (ep abs)
+ "Signal an error unless ABS falls on endpoint EP's weekday, if it has one."
+ (let ((w (nth 3 ep)))
+ (when (and w (/= w (nldate--dow abs)))
+ (user-error "%s is a %s, not a %s"
+ (calendar-date-string (nldate--greg abs) t t)
+ (calendar-day-name (nldate--greg abs))
+ (aref calendar-day-name-array w)))))
+
+(defun nldate--terms (items)
+ "Resolve the date items in ITEMS into a list of (START . END) absolute days."
+ (let ((terms (cl-remove-if-not (lambda (i) (memq (car i) '(:date :range))) items)))
+ (let* ((eps (mapcan (lambda (i) (copy-sequence (cdr i))) terms))
+ (given (mapcar (lambda (ep) (cons ep (nth 2 ep))) eps)))
+ (nldate--fill eps)
+ (mapcar
+ (lambda (i)
+ (let* ((ea (nth 1 i)) (eb (nth 2 i))
+ (a (nldate--resolve ea))
+ (b (if eb (nldate--resolve eb a) a)))
+ ;; "28 Dec - 3 Jan 2027": the start year was copied from the end.
+ (when (and (< b a) (null (cdr (assq ea given))))
+ (setf (nth 2 ea) (1- (nth 2 ea))
+ a (nldate--resolve ea)))
+ (when (< b a) (user-error "Range ends before it starts"))
+ (nldate--check-weekday ea a)
+ (when eb (nldate--check-weekday eb b))
+ (cons a b)))
+ terms))))
+
+;;;; Diary sexps
+
+(defun nldate--date-args (date)
+ "Return calendar DATE's parts ordered for diary sexps per `calendar-date-style'."
+ (pcase-let ((`(,m ,d ,y) date))
+ (pcase calendar-date-style
+ ('european (list d m y))
+ ('iso (list y m d))
+ (_ (list m d y)))))
+
+(defun nldate--wd-cond (days)
+ (if (cdr days)
+ `(memq (calendar-day-of-week date) ',days)
+ `(= (calendar-day-of-week date) ,(car days))))
+
+(defun nldate--cyclic (n date)
+ `(diary-cyclic ,n ,@(nldate--date-args date)))
+
+(defun nldate--block (a b)
+ `(diary-block ,@(nldate--date-args a) ,@(nldate--date-args b)))
+
+(defun nldate-diary-sexp (recurrence)
+ "Return a diary sexp for RECURRENCE, as returned by `nldate-parse'.
+Date arguments follow `calendar-date-style'."
+ (pcase recurrence
+ (`(:float ,m ,w ,n) `(diary-float ,m ,w ,n))
+ (`(:monthday ,d) `(diary-date ,@(nldate--date-args (list t d t))))
+ (`(:cyclic ,n ,start ,end)
+ (if end `(and ,(nldate--cyclic n start) ,(nldate--block start end))
+ (nldate--cyclic n start)))
+ (`(:weekly ,days ,start ,end)
+ (let ((wc (nldate--wd-cond days)))
+ (cond
+ ((and start end) `(and ,(nldate--block start end) ,wc))
+ ((and start (null (cdr days)))
+ (let ((a (calendar-absolute-from-gregorian start)))
+ (nldate--cyclic 7 (nldate--greg
+ (+ a (mod (- (car days) (nldate--dow a)) 7))))))
+ (start `(and (>= (calendar-absolute-from-gregorian date)
+ ,(calendar-absolute-from-gregorian start))
+ ,wc))
+ (t wc))))
+ (_ (error "Unknown recurrence %S" recurrence))))
+
+;;;; Entry points
+
+(defvar nldate-warning-function
+ (lambda (message) (display-warning 'nldate message))
+ "Function called with a message when `nldate-parse' finds something odd.
+For example, a weekday that does not match the date given. Bind it to
+collect the messages instead, as a live preview does.")
+
+
+(defun nldate--recurrence (rec terms days)
+ "Recurrence for item REC, bounded by the first of TERMS, on weekdays DAYS."
+ (let* ((term (car terms))
+ (a (and term (nldate--greg (car term))))
+ (b (and term (/= (car term) (cdr term)) (nldate--greg (cdr term)))))
+ (pcase rec
+ (`(:float . ,_) rec)
+ (`(:monthday . ,_) rec)
+ (`(:cycle ,n) (list :cyclic n (or a (calendar-current-date)) b))
+ (`(:every)
+ (unless days (user-error "\"every\" needs weekdays or a period"))
+ (list :weekly days a b)))))
+
+(defun nldate-format-time (minutes)
+ "Format MINUTES past midnight as HH:MM."
+ (format "%02d:%02d" (/ minutes 60) (% minutes 60)))
+
+(defun nldate--merge-ranges (terms)
+ "Merge overlapping (START . END) absolute-day TERMS into calendar date pairs."
+ (let (merged)
+ (dolist (tm (sort (copy-sequence terms) (lambda (a b) (< (car a) (car b)))))
+ (if (and merged (<= (car tm) (cdar merged)))
+ (setcdr (car merged) (max (cdr tm) (cdar merged)))
+ (push (cons (car tm) (cdr tm)) merged)))
+ (mapcar (lambda (r) (cons (nldate--greg (car r)) (nldate--greg (cdr r))))
+ (nreverse merged))))
+
+(defun nldate-parse (string)
+ "Parse the English date description STRING.
+Return either (:dates DATES :ranges RANGES :time TIME)
+or (:recurrence REC :time TIME).
+
+DATES is a sorted list of calendar dates (MONTH DAY YEAR), every day
+described. RANGES gives the same days as a list of (START . END) date
+pairs, one per date or range in STRING, with overlapping ones merged; a
+single date is (DATE . DATE). RANGES is nil when a weekday filter such
+as \"Friday to Sunday\" or \"weekends\" picked days out of the ranges.
+TIME is nil or (START . END), minutes past midnight, END being nil for
+a single time.
+REC is one of
+ (:float MONTH WEEKDAY N) as for `diary-float', MONTH t for every month
+ (:monthday DAY) that day of every month
+ (:cyclic N START END) every N days from START, until END if non-nil
+ (:weekly WEEKDAYS START END) on WEEKDAYS (0 = Sunday), START and END
+ optional
+with START and END calendar dates or nil. Signal `user-error' if
+STRING cannot be understood."
+ (let* ((items (nldate--parse string))
+ (get (lambda (k) (cl-remove-if-not (lambda (i) (eq (car i) k)) items)))
+ (tm (car (funcall get :time)))
+ (time (and tm (cons (nth 1 tm) (nth 2 tm))))
+ (explicit (delete-dups (mapcan (lambda (i) (copy-sequence (nth 1 i)))
+ (funcall get :wd))))
+ (except (mapcan (lambda (i) (copy-sequence (nth 1 i))) (funcall get :except)))
+ (days (or explicit (nth 1 (car (funcall get :filter)))))
+ (days (if except
+ (cl-set-difference (or days '(0 1 2 3 4 5 6)) except)
+ days))
+ (rec (cl-find-if (lambda (i) (memq (car i) '(:float :monthday :cycle))) items))
+ (rec (or rec (car (funcall get :every))))
+ (terms (nldate--terms items)))
+ (if rec
+ (list :recurrence (nldate--recurrence rec terms days) :time time)
+ (let ((all (sort (delete-dups
+ (mapcan (lambda (tm)
+ (when (> (- (cdr tm) (car tm)) 3660)
+ (user-error "Range too long"))
+ (number-sequence (car tm) (cdr tm)))
+ terms))
+ #'<)))
+ (cond
+ ((and (null all) days)
+ ;; Bare weekdays: next occurrence of each, after today.
+ (let ((tod (nldate--today)))
+ (setq all (sort (mapcar (lambda (w)
+ (+ tod 1 (mod (- w (nldate--dow (1+ tod))) 7)))
+ days)
+ #'<))))
+ (days
+ (when explicit
+ (dolist (e (delete-dups (mapcan (lambda (tm) (list (car tm) (cdr tm))) terms)))
+ (unless (memq (nldate--dow e) days)
+ (funcall nldate-warning-function
+ (format "%s is not one of the weekdays given"
+ (calendar-date-string (nldate--greg e)))))))
+ (setq all (cl-remove-if-not (lambda (d) (memq (nldate--dow d) days)) all))
+ (unless all
+ (user-error "No date in \"%s\" falls on the weekdays given" string))))
+ (unless all (user-error "Could not find any date in \"%s\"" string))
+ (list :dates (mapcar #'nldate--greg all)
+ :ranges (and (null days) (nldate--merge-ranges terms))
+ :time time)))))
+
+(provide 'nldate)
+;;; nldate.el ends here
diff --git a/emacs/.emacs.d/lisp/org-nldate/org-nldate.el b/emacs/.emacs.d/lisp/org-nldate/org-nldate.el
new file mode 100644
index 0000000..dbc2feb
--- /dev/null
+++ b/emacs/.emacs.d/lisp/org-nldate/org-nldate.el
@@ -0,0 +1,214 @@
+;;; org-nldate.el --- Natural-language dates to Org timestamps -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2026 Free Software Foundation.
+
+;; Version: 0.3
+;; Package-Requires: ((emacs "28.1") (org "9.5") (nldate "0.3"))
+;; Keywords: calendar, outlines
+
+;;; Commentary:
+
+;; `org-nldate-time-stamp' reads an English description of dates in the
+;; minibuffer and inserts Org timestamps at point, one per line, e.g.
+;;
+;; Friday to Sunday from 11am to 10pm over the weekends of 13-15 and
+;; 20-22 November 2026
+;;
+;; becomes six timestamps <2026-11-13 Fri 11:00-22:00> ... and
+;;
+;; last Saturday of each month -> <%%(diary-float t 6 -1)>
+;; every 10 days from 13 Nov -> <%%(diary-cyclic 10 ...)>
+;;
+;; Parsing is done by nldate.el; this file only formats the result.
+;;
+;; Org before 9.7 does not understand a time inside a diary-sexp
+;; timestamp, so there the time goes at the start of the heading
+;; instead: "* 11:00-22:00 Market". See `org-nldate-time-in-sexp'.
+
+;; TODO: Org has variants of the diary functions that always take
+;; year, month, day in that order whatever `calendar-date-style' says:
+;; `org-cyclic', `org-block', `org-date' and `org-anniversary' (in
+;; org-agenda.el). `diary-cyclic' etc. read their arguments in the
+;; order set by `calendar-date-style', so <%%(diary-cyclic 10 11 13 2026)>
+;; written with the default American style means a different date for
+;; someone using the European style. Emitting <%%(org-cyclic 10 2026 11
+;; 13)> instead would make timestamps portable between setups. That
+;; needs a variant of `nldate-diary-sexp' here, as `diary-float' has no
+;; date arguments and needs no Org counterpart.
+
+;;; Code:
+
+(require 'nldate)
+(require 'org)
+(require 'subr-x)
+
+(defun org-nldate--date-format ()
+ "Org's date-only timestamp format, without brackets."
+ ;; Org 9.7 renamed `org-time-stamp-formats' and dropped the brackets.
+ (string-trim (car (if (boundp 'org-timestamp-formats)
+ org-timestamp-formats
+ org-time-stamp-formats))
+ "[<[]" "[]>]"))
+
+(defun org-nldate--time-string (time)
+ "Org time or time range for TIME, (START . END) as from `nldate-parse'."
+ (and time
+ (concat (nldate-format-time (car time))
+ (and (cdr time) (concat "-" (nldate-format-time (cdr time)))))))
+
+(defun org-nldate--stamp (date time)
+ "Org timestamp for calendar DATE with TIME (a string or nil)."
+ (pcase-let ((`(,m ,d ,y) date))
+ (format "<%s%s>"
+ (format-time-string (org-nldate--date-format) (encode-time 0 0 12 d m y))
+ (if time (concat " " time) ""))))
+
+(defun org-nldate--sexp-stamp (sexp time)
+ "Org diary-sexp timestamp for SEXP with TIME (a string or nil)."
+ (format "<%%%%%s%s>" (prin1-to-string sexp) (if time (concat " " time) "")))
+
+;;;; Times in diary-sexp timestamps
+
+(defcustom org-nldate-time-in-sexp 'auto
+ "Whether a time may go inside a diary-sexp timestamp.
+Org 9.7 added timestamps like <%%(diary-float t 6 -1) 11:00-22:00>.
+Older versions do not merely ignore the time: the agenda drops the
+whole entry. They do pick up a time at the start of the heading, so
+when this is nil, `org-nldate-time-stamp' writes the time there.
+
+t means always inside the timestamp, nil always in the heading, and
+`auto' decides by `org-version'."
+ :type '(choice (const :tag "Decide by Org version" auto)
+ (const :tag "Inside the timestamp" t)
+ (const :tag "At the start of the heading" nil))
+ :group 'org-time)
+
+(defun org-nldate--time-in-sexp-p ()
+ (if (eq org-nldate-time-in-sexp 'auto)
+ (version<= "9.7" (org-release))
+ org-nldate-time-in-sexp))
+
+(defun org-nldate--format (result)
+ "Format RESULT of `nldate-parse' as (STAMPS . HEADING-TIME).
+HEADING-TIME is a time string that belongs in the heading instead of
+the timestamp, or nil."
+ (let ((time (org-nldate--time-string (plist-get result :time))))
+ (if-let ((rec (plist-get result :recurrence)))
+ (let ((sexp (nldate-diary-sexp rec)))
+ (if (or (null time) (org-nldate--time-in-sexp-p))
+ (list (list (org-nldate--sexp-stamp sexp time)))
+ (cons (list (org-nldate--sexp-stamp sexp nil)) time)))
+ (let ((ranges (plist-get result :ranges)))
+ (list
+ (if (and ranges (null time))
+ ;; "4th to 9th January": one Org range, <...>--<...>. With a
+ ;; time, as in "13-15 Nov 11am-5pm", the hours are daily, which
+ ;; an Org range cannot say, so each day gets its own timestamp.
+ (mapcar (lambda (r)
+ (if (equal (car r) (cdr r))
+ (org-nldate--stamp (car r) nil)
+ (concat (org-nldate--stamp (car r) nil) "--"
+ (org-nldate--stamp (cdr r) nil))))
+ ranges)
+ (mapcar (lambda (date) (org-nldate--stamp date time))
+ (plist-get result :dates))))))))
+
+(defun org-nldate-parse (string)
+ "Return a list of Org timestamp strings described by STRING.
+A time that cannot go inside a diary-sexp timestamp (see
+`org-nldate-time-in-sexp') is left out."
+ (car (org-nldate--format (nldate-parse string))))
+
+(defconst org-nldate--leading-time-re
+ "\\`[0-9]\\{1,2\\}:[0-9]\\{2\\}\\(?:-[0-9]\\{1,2\\}:[0-9]\\{2\\}\\)?\\(?:\\s-+\\|\\'\\)"
+ "Matches a time or time range at the start of a heading title.")
+
+(defun org-nldate--put-time-in-heading (time)
+ "Put TIME at the start of the current entry's heading title.
+A time already there is replaced. Return nil if there is no heading."
+ (save-excursion
+ (unless (org-before-first-heading-p)
+ (org-back-to-heading t)
+ (let ((title (or (org-get-heading t t t t) "")))
+ (org-edit-headline
+ (string-trim-right
+ (concat time " " (replace-regexp-in-string
+ org-nldate--leading-time-re "" title t t)))))
+ t)))
+
+;;;; Minibuffer preview
+
+(defvar org-nldate-history nil)
+
+(defvar-local org-nldate--preview-overlay nil)
+
+(defun org-nldate--preview-stamps (stamps)
+ "Shorten STAMPS for display: at most three, with a count when more."
+ (if (<= (length stamps) 3)
+ (string-join stamps " ")
+ (format "%s %s ... %s (%d dates)"
+ (nth 0 stamps) (nth 1 stamps) (car (last stamps)) (length stamps))))
+
+(defun org-nldate-preview-text (string)
+ "Text previewing how STRING will be inserted, like Org's date prompt.
+Return nil for blank input."
+ (unless (string-blank-p string)
+ (let* ((warnings ())
+ (nldate-warning-function (lambda (msg) (push msg warnings)))
+ (text
+ (condition-case err
+ (pcase-let ((`(,stamps . ,heading-time)
+ (org-nldate--format (nldate-parse string))))
+ (concat (org-nldate--preview-stamps stamps)
+ (and heading-time
+ (format " (%s goes in the heading)" heading-time))))
+ (error (propertize (error-message-string err) 'face 'shadow)))))
+ (concat "=> " text
+ (mapconcat (lambda (w) (propertize (format " [%s]" w) 'face 'warning))
+ (nreverse warnings) "")))))
+
+(defun org-nldate--preview ()
+ "Show the interpretation of the minibuffer contents after the input."
+ (when org-nldate--preview-overlay
+ (delete-overlay org-nldate--preview-overlay))
+ (when-let ((text (org-nldate-preview-text (minibuffer-contents-no-properties))))
+ (setq org-nldate--preview-overlay (make-overlay (point-max) (point-max)))
+ (setq text (copy-sequence text))
+ (add-face-text-property 0 (length text) 'secondary-selection t text)
+ (overlay-put org-nldate--preview-overlay 'after-string
+ ;; The `cursor' property keeps the cursor at the end of
+ ;; the input, before the preview. Three spaces as in Org.
+ (concat (propertize " " 'cursor t) text))))
+
+(defun org-nldate-read-string (prompt)
+ "Read a date description with PROMPT, previewing it live.
+The preview follows `org-read-date-display-live'."
+ (minibuffer-with-setup-hook
+ (lambda ()
+ (when org-read-date-display-live
+ (add-hook 'post-command-hook #'org-nldate--preview nil t)))
+ (read-string prompt nil 'org-nldate-history)))
+
+;;;; Command
+
+;;;###autoload
+(defun org-nldate-time-stamp (string)
+ "Read a natural-language date description and insert Org timestamps at point.
+Several dates are inserted one per line, aligned with the current column.
+For a recurrence with a time on Org before 9.7, the time goes at the
+start of the heading instead; see `org-nldate-time-in-sexp'."
+ (interactive (list (org-nldate-read-string "Date(s): ")))
+ (pcase-let ((`(,stamps . ,heading-time) (org-nldate--format (nldate-parse string)))
+ (indent (make-string (current-column) ?\s)))
+ (insert (string-join stamps (concat "\n" indent)))
+ (when heading-time
+ (if (org-nldate--put-time-in-heading heading-time)
+ (message "Org %s cannot keep a time in a diary timestamp; put %s in the heading"
+ (org-release) heading-time)
+ (display-warning
+ 'org-nldate
+ (format "Org %s cannot keep a time in a diary timestamp, and there is no heading to put %s in"
+ (org-release) heading-time))))))
+
+(provide 'org-nldate)
+;;; org-nldate.el ends here
diff --git a/emacs/.emacs.d/lisp/ox-jira.el b/emacs/.emacs.d/lisp/ox-jira.el
-Subproject 00184f8fdef02a3a359a253712e8769cbfbea3b
+Subproject 6a0f1964aabfa433137767e8b8454088ed9763b
diff --git a/mariadb-server/.dir-locals.el b/mariadb-server/.dir-locals.el
index 2b4cff5..0ae6484 100644
--- a/mariadb-server/.dir-locals.el
+++ b/mariadb-server/.dir-locals.el
@@ -7,6 +7,9 @@
(c-offsets-alist
. (
(inline-open . 0)
+ (c . my-c-lineup-block-comment)
+ (statement-case-intro . +)
+ (statement-cont . +)
(substatement . +)
(statement-block-intro . +)
(arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist)
@@ -24,10 +27,15 @@
(c-offsets-alist
. (
(inline-open . 0)
+ (c . my-c-lineup-block-comment)
+ (statement-case-intro . +)
+ (statement-cont . +)
(substatement . +)
(statement-block-intro . +)
(arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist)
(inclass . +)
+ (defun-block-intro . +)
+ (statement-cont . +)
))
(comment-start . "/* ")
(comment-end . " */")
diff --git a/misc/.bashrc b/misc/.bashrc
index 2d44565..48bc504 100644
--- a/misc/.bashrc
+++ b/misc/.bashrc
@@ -140,7 +140,6 @@ alias which='alias | which -i'
alias chx="chmod +x"
# dedicated emacs instances for emms and erc, see `my-profile' in my
# emacs init files
-alias emms='EMACS_PROFILE=emms emacs'
alias erc='EMACS_PROFILE=erc emacs'
# Safer default for cp, mv, rm. These will print a verbose output of
@@ -283,5 +282,21 @@ gs-merge() {
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$@"
}
+_chime() {
+ "$@"
+ local rc=$?
+ local d=/usr/share/sounds/freedesktop/stereo
+ if [ $rc -eq 0 ]; then
+ # success jingle
+ play -q -n synth 0.12 pluck C5 : synth 0.12 pluck E5 : synth 0.12 pluck G5 : synth 0.45 pluck C6
+ else
+ # failure jingle
+ play -q -n synth 0.12 pluck C4 : synth 0.12 pluck G3 : synth 0.12 pluck Eb3 : synth 0.45 pluck C3
+ fi
+ return $rc
+}
+
+alias chime='_chime '
+
# dptrp1
alias quaderno="dptrp1 --addr $QUADERNO_IP"
diff --git a/misc/.config/i3/config b/misc/.config/i3/config
index 803dcd1..4928269 100644
--- a/misc/.config/i3/config
+++ b/misc/.config/i3/config
@@ -41,7 +41,7 @@ bindsym $mod+q exec "pkill firefox; sleep 2; firefox"
# start rofi
bindsym $mod+j exec "PATH=$HOME/.local/bin:$HOME/bin:$PATH rofi -show combi"
-bindsym $mod+slash exec rofi-pass
+bindsym $mod+slash exec --no-startup-id ~/.config/i3/rofi-pass.sh
# show PATH, for debugging
bindsym $mod+Shift+z exec "echo $PATH|sed -e 's/:/\n/g' | rofi -dmenu"
@@ -207,8 +207,12 @@ bindsym $mod+Shift+m focus parent; fullscreen; focus child
bindsym $mod+equal exec dunstctl history-pop
bindsym $mod+minus exec dunstctl close
+bindsym $mod+F1 exec --no-startup-id ~/.config/i3/focus.sh
+
# startup
+exec --no-startup-id xsetroot -solid "#000000"
exec ibus-daemon
exec redshift-gtk
exec --no-startup-id i3-msg 'workspace $ws1; exec urxvt'
exec xscreensaver -no-splash &
+exec xautolock -time 15 -locker 'i3lock -c 000000' &
diff --git a/misc/.config/i3/focus.sh b/misc/.config/i3/focus.sh
new file mode 100755
index 0000000..6dd7d46
--- /dev/null
+++ b/misc/.config/i3/focus.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+# toggle reading/focus mode on the current workspace
+
+WIDTH=1000 # desired window width in pixels
+
+ws=$(i3-msg -t get_tree | jq -c 'first(.. | objects
+ | select(.type=="workspace" and any(.. | objects; .focused == true)))')
+
+# Gap per side = (workspace width - desired width) / 2, minus any inner gap
+ws_width=$(echo "$ws" | jq '.rect.width')
+inner_gap=$(echo "$ws" | jq '.gaps.inner // 0')
+gap=$(( (ws_width - WIDTH) / 2 - inner_gap ))
+[ "$gap" -lt 0 ] && gap=0
+
+on="layout tabbed; gaps horizontal current set $gap; bar mode hide"
+off="layout splith; gaps horizontal current set 0; bar mode dock"
+
+count=$(echo "$ws" | jq '.nodes | length')
+inner=$(echo "$ws" | jq '.nodes[0].nodes | length')
+
+if [ "$count" -eq 1 ] && [ "$inner" -gt 0 ]; then
+ layout=$(echo "$ws" | jq -r '.nodes[0].layout')
+ child=$(echo "$ws" | jq '.nodes[0].nodes[0].id')
+ if [ "$layout" = "tabbed" ]; then
+ i3-msg "[con_id=$child] $off"
+ else
+ i3-msg "[con_id=$child] $on"
+ fi
+else
+ child=$(echo "$ws" | jq '.nodes[0].id')
+ i3-msg "[con_id=$child] $on"
+fi
diff --git a/misc/.config/i3/rofi-pass.sh b/misc/.config/i3/rofi-pass.sh
new file mode 100755
index 0000000..d8aea04
--- /dev/null
+++ b/misc/.config/i3/rofi-pass.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+rofi-pass "$@"
+xdotool keyup ctrl
diff --git a/misc/.config/mpv/input.conf b/misc/.config/mpv/input.conf
index 0238138..8d0f7a3 100644
--- a/misc/.config/mpv/input.conf
+++ b/misc/.config/mpv/input.conf
@@ -1,3 +1,4 @@
PREV seek -15
NEXT stop
a vf toggle hflip
+j script-message-to console type "seek absolute" 6
diff --git a/misc/.config/mpv/mpv.conf b/misc/.config/mpv/mpv.conf
index b6b1beb..a2677e7 100644
--- a/misc/.config/mpv/mpv.conf
+++ b/misc/.config/mpv/mpv.conf
@@ -5,10 +5,7 @@ save-position-on-quit
script-opts=ytdl_hook-ytdl_path=/usr/bin/yt-dlp
ytdl-format="bestvideo[height<=?720]+bestaudio/best"
-osc=no
stop-screensaver = "yes"
-# play audio with ui
-# profile=pseudo-gui
[emacsconf-talks]
# Positioning
diff --git a/misc/.gdbinit b/misc/.gdbinit
index 00be34f..433973a 100644
--- a/misc/.gdbinit
+++ b/misc/.gdbinit
@@ -25,6 +25,14 @@ define bc
b $arg0
c
end
+define enc
+ en $arg0
+ c
+end
+define disc
+ dis $arg0
+ c
+end
# Print backtrace of all threads
alias abt = thread apply all bt
set history save on
@@ -44,5 +52,23 @@ define wlrc
watch -l $arg0
rc
end
+define brc
+ b $arg0
+ rc
+end
+
+# bison
+define pbs
+ print yyvsp[$arg0 - yylen]
+end
+
+define disw
+python
+for b in gdb.breakpoints():
+ if b.type in (gdb.BP_WATCHPOINT, gdb.BP_HARDWARE_WATCHPOINT,
+ gdb.BP_READ_WATCHPOINT, gdb.BP_ACCESS_WATCHPOINT):
+ b.enabled = False
+end
+end
source ~/.gdbinit_local
diff --git a/misc/bin/emms-audio-focus.sh b/misc/bin/emms-audio-focus.sh
new file mode 100755
index 0000000..44a2080
--- /dev/null
+++ b/misc/bin/emms-audio-focus.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# Pause EMMS while any other app plays audio; resume when quiet again.
+RESUME_DELAY=2 # seconds of silence before resuming
+
+others_playing() {
+ pactl --format=json list sink-inputs 2>/dev/null | jq '
+ [ .[] | select(.corked == false)
+ | select(.properties."application.name" != "emms")
+ | select(.properties."media.role" != "event") ] | length'
+}
+
+emms_pause_if_playing() { # prints t only if *we* paused it
+ emacsclient -s emms --eval '(when (and emms-player-playing-p
+ (not emms-player-paused-p))
+ (emms-pause) t)' 2>/dev/null
+}
+
+emms_resume() {
+ emacsclient -s emms --eval '(when emms-player-paused-p (emms-pause))' >/dev/null 2>&1
+}
+
+exec 3< <(pactl subscribe)
+paused_by_us=0
+quiet_since=0
+
+while :; do
+ # Wake up on a sound-server event or once a second; drain event bursts.
+ read -r -t 1 -u 3 _
+ while read -r -t 0.05 -u 3 _; do :; done
+
+ n=$(others_playing)
+ if (( ${n:-0} > 0 )); then
+ quiet_since=0
+ if (( ! paused_by_us )) && [[ $(emms_pause_if_playing) == t ]]; then
+ paused_by_us=1
+ fi
+ elif (( paused_by_us )); then
+ (( quiet_since )) || quiet_since=$SECONDS
+ if (( SECONDS - quiet_since >= RESUME_DELAY )); then
+ emms_resume
+ paused_by_us=0
+ quiet_since=0
+ fi
+ fi
+done
diff --git a/misc/bin/emms.sh b/misc/bin/emms.sh
new file mode 100755
index 0000000..0367671
--- /dev/null
+++ b/misc/bin/emms.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+EMACS_PROFILE=emms emacs
diff --git a/misc/bin/org-a-sync.el b/misc/bin/org-a-sync.el
index 7123f04..4ed9052 100755
--- a/misc/bin/org-a-sync.el
+++ b/misc/bin/org-a-sync.el
@@ -7,6 +7,21 @@
(my-setq-from-local my-org-agenda-and-next-export-files)
(my-setq-from-local org-agenda-files)
+(defvar my-org-agenda-export-seen (make-hash-table :test #'equal)
+ "Hash table of headings already shown in the current agenda run.")
+
+(defun my-org-agenda-drop-seen (item)
+ "Return agenda ITEM, or nil if its heading was already shown.
+Meant for `org-agenda-before-sorting-filter-function'. Items without
+an `org-hd-marker' (diary entries and the like) are always kept."
+ (let ((m (get-text-property 0 'org-hd-marker item)))
+ (if (not (and my-org-agenda-export-seen (markerp m) (marker-buffer m)))
+ item
+ (let ((key (cons (marker-buffer m) (marker-position m))))
+ (unless (gethash key my-org-agenda-export-seen)
+ (puthash key t my-org-agenda-export-seen)
+ item)))))
+
(progn
(setq org-todo-keywords
'((sequence "TODO(t)" "DOIN(i)" "WAIT(w)" "|"
@@ -16,16 +31,18 @@
org-enforce-todo-checkbox-dependencies nil)
(setq org-use-fast-todo-selection 'expert)
(setq org-agenda-custom-commands
- `(("A" "Agenda and next"
- ((agenda ""
+ `(("E" "Agenda and next (export: each heading once)"
+ ((agenda ""
((org-agenda-span 32)
;; only works when `org-agenda-start-on-weekday'
;; is nil
(org-agenda-start-day "-2d")))
(tags-todo "PRIORITY=\"A\"" nil))
- nil
- ,my-org-agenda-and-next-export-files
- )))
+ ;; Command-level settings are evaluated once per run, so both
+ ;; blocks share one fresh table.
+ ((org-agenda-before-sorting-filter-function
+ #'my-org-agenda-drop-seen))
+ ,my-org-agenda-and-next-export-files)))
(setq large-file-warning-threshold nil)
(setq org-agenda-todo-ignore-time-comparison-use-seconds t)
(setq org-agenda-todo-ignore-deadlines 'all)