aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2026-11-22 14:49:22 +1100
committerYuchen Pei <id@ypei.org>2026-11-22 14:49:22 +1100
commit6c8085f37da600b1ed33be7f6fcc41bdbe6e105a (patch)
treedbcad2990ce809cc78070f953e4474fb6ffeae90
parent2e74307a7225e96fbf2d743ffcd69adec780c8ac (diff)
[emacs][i3][bash][gdbinit] Updates
-rw-r--r--emacs/.emacs.d/init/ycp-markup.el13
-rw-r--r--emacs/.emacs.d/init/ycp-org.el8
-rw-r--r--emacs/.emacs.d/init/ycp-prog.el10
-rw-r--r--emacs/.emacs.d/init/ycp-system.el27
-rw-r--r--emacs/.emacs.d/init/ycp-vc.el5
-rw-r--r--emacs/.emacs.d/lisp/my/my-dired.el12
-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.el16
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el19
-rw-r--r--mariadb-server/.dir-locals.el8
-rw-r--r--misc/.bashrc14
-rw-r--r--misc/.config/i3/config1
-rw-r--r--misc/.gdbinit26
14 files changed, 267 insertions, 20 deletions
diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el
index b46acda..4373386 100644
--- a/emacs/.emacs.d/init/ycp-markup.el
+++ b/emacs/.emacs.d/init/ycp-markup.el
@@ -62,16 +62,21 @@
;;; 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
+ "<RET>" 'my-markdown-maybe-follow-thing-at-point
"C-`" 'markdown-view-mode)
(my-keybind markdown-view-mode-map
- "C-`" 'markdown-mode))
+ "C-`" 'markdown-mode
+ "<RET>" 'my-markdown-maybe-follow-thing-at-point
+ "o" 'markdown-follow-thing-at-point))
(my-package chatbot-mode
(:delay 60))
diff --git a/emacs/.emacs.d/init/ycp-org.el b/emacs/.emacs.d/init/ycp-org.el
index f6b9c59..69abc47 100644
--- a/emacs/.emacs.d/init/ycp-org.el
+++ b/emacs/.emacs.d/init/ycp-org.el
@@ -541,7 +541,13 @@
"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)
diff --git a/emacs/.emacs.d/init/ycp-prog.el b/emacs/.emacs.d/init/ycp-prog.el
index e50c5dd..a0cd70e 100644
--- a/emacs/.emacs.d/init/ycp-prog.el
+++ b/emacs/.emacs.d/init/ycp-prog.el
@@ -32,6 +32,7 @@
;;; 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)
@@ -92,6 +93,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 +114,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)
@@ -201,10 +204,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 +537,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)
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..b5440c3 100644
--- a/emacs/.emacs.d/init/ycp-vc.el
+++ b/emacs/.emacs.d/init/ycp-vc.el
@@ -134,6 +134,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/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-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..97b8488 100644
--- a/emacs/.emacs.d/lisp/my/my-markdown.el
+++ b/emacs/.emacs.d/lisp/my/my-markdown.el
@@ -33,5 +33,21 @@
(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!")))
+
(provide 'my-markdown)
;;; my-markdown.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index eead408..1945b6c 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -340,6 +340,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 +606,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/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 f64de44..2cab0f6 100644
--- a/misc/.bashrc
+++ b/misc/.bashrc
@@ -282,5 +282,19 @@ gs-merge() {
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$@"
}
+_chime() {
+ "$@"
+ local rc=$?
+ local d=/usr/share/sounds/freedesktop/stereo
+ if [ $rc -eq 0 ]; then
+ paplay "/usr/share/filezilla/resources/finished.wav"
+ else
+ paplay "/usr/share/sounds/Oxygen-Sys-App-Error-Serious-Very.ogg"
+ 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 84b1247..4928269 100644
--- a/misc/.config/i3/config
+++ b/misc/.config/i3/config
@@ -215,3 +215,4 @@ 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/.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