From 25bdce904933ce4699acccf7181247d445d300ea Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 23 Nov 2026 18:20:29 +1100 Subject: [emacs][bashrc] various improvements --- emacs/.emacs.d/init/ycp-markup.el | 5 ++- emacs/.emacs.d/init/ycp-prog.el | 14 +++--- emacs/.emacs.d/lisp/my/chatbot-mode.el | 2 +- emacs/.emacs.d/lisp/my/my-markdown.el | 12 +++++ emacs/.emacs.d/lisp/my/my-prog.el | 80 +++++++++++++++++++++++++++++----- misc/.bashrc | 6 ++- 6 files changed, 97 insertions(+), 22 deletions(-) diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el index 4373386..1697949 100644 --- a/emacs/.emacs.d/init/ycp-markup.el +++ b/emacs/.emacs.d/init/ycp-markup.el @@ -72,10 +72,11 @@ (require 'my-markdown) (my-keybind markdown-mode-map "" 'my-markdown-maybe-follow-thing-at-point - "C-`" 'markdown-view-mode) + "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 - "" 'my-markdown-maybe-follow-thing-at-point "o" 'markdown-follow-thing-at-point)) (my-package chatbot-mode diff --git a/emacs/.emacs.d/init/ycp-prog.el b/emacs/.emacs.d/init/ycp-prog.el index a0cd70e..c601ada 100644 --- a/emacs/.emacs.d/init/ycp-prog.el +++ b/emacs/.emacs.d/init/ycp-prog.el @@ -39,8 +39,10 @@ (setq comint-prompt-read-only t) (setq comint-buffer-maximum-size 9999) (setq comint-completion-autolist t) - (define-key comint-mode-map (kbd "C-") 'windmove-up) - (define-key comint-mode-map (kbd "C-") 'windmove-down) + (my-keybind comint-mode-map + "C-" 'windmove-up + "C-" 'windmove-down + ) (setq comint-input-ring-size 5000) (setq comint-input-ignoredups t) (setq comint-terminfo-terminal "dumb") @@ -125,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-" - #'my-comint-send-input-and-return-prompt) + (my-keybind comint-mode-map + "C-" #'my-comint-send-input-and-return-prompt + "" #'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 "" #'my-comint-restart) (add-hook 'shell-mode-hook 'my-shell-disable-company-if-remote) (my-keybind global-map "" #'my-shell-open-or-cycle) ) diff --git a/emacs/.emacs.d/lisp/my/chatbot-mode.el b/emacs/.emacs.d/lisp/my/chatbot-mode.el index 0880da5..7d56c09 100644 --- a/emacs/.emacs.d/lisp/my/chatbot-mode.el +++ b/emacs/.emacs.d/lisp/my/chatbot-mode.el @@ -365,7 +365,7 @@ Start a new User message if this log has no compose buffer." "Keymap for `chatbot-mode'.") ;;;###autoload -(define-derived-mode chatbot-mode markdown-view-mode "Chatbot" +(define-derived-mode chatbot-mode gfm-view-mode "Chatbot" "Major mode for read-only chatbot logs. \\{chatbot-mode-map}") diff --git a/emacs/.emacs.d/lisp/my/my-markdown.el b/emacs/.emacs.d/lisp/my/my-markdown.el index 97b8488..d3835b8 100644 --- a/emacs/.emacs.d/lisp/my/my-markdown.el +++ b/emacs/.emacs.d/lisp/my/my-markdown.el @@ -49,5 +49,17 @@ (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-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el index 1945b6c..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))) diff --git a/misc/.bashrc b/misc/.bashrc index 2cab0f6..48bc504 100644 --- a/misc/.bashrc +++ b/misc/.bashrc @@ -287,9 +287,11 @@ _chime() { local rc=$? local d=/usr/share/sounds/freedesktop/stereo if [ $rc -eq 0 ]; then - paplay "/usr/share/filezilla/resources/finished.wav" + # 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 - paplay "/usr/share/sounds/Oxygen-Sys-App-Error-Serious-Very.ogg" + # 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 } -- cgit v1.2.3