aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emacs/.emacs.d/init/ycp-prog.el1
-rw-r--r--emacs/.emacs.d/init/ycp-vc.el2
-rw-r--r--emacs/.emacs.d/lisp/my/my-magit.el40
-rw-r--r--emacs/.emacs.d/lisp/my/my-mariadb.el45
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el7
-rw-r--r--misc/.bashrc10
6 files changed, 98 insertions, 7 deletions
diff --git a/emacs/.emacs.d/init/ycp-prog.el b/emacs/.emacs.d/init/ycp-prog.el
index c601ada..9317a65 100644
--- a/emacs/.emacs.d/init/ycp-prog.el
+++ b/emacs/.emacs.d/init/ycp-prog.el
@@ -315,6 +315,7 @@
(require 'ansi-color)
;; ansi color in compilation buffer
(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter)
+ (add-hook 'compilation-finish-functions #'my-compilation-bell-on-failure)
)
;;; flymake
diff --git a/emacs/.emacs.d/init/ycp-vc.el b/emacs/.emacs.d/init/ycp-vc.el
index 61989e0..989141a 100644
--- a/emacs/.emacs.d/init/ycp-vc.el
+++ b/emacs/.emacs.d/init/ycp-vc.el
@@ -79,6 +79,8 @@
B ">>>>>>> B: Incoming"))
(setq ediff-diff-options "-w")
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
+ (require 'my-vc)
+ (add-hook 'ediff-after-setup-windows-hook #'my-ediff-swap-upper-and-merged)
)
(my-package vc-git
diff --git a/emacs/.emacs.d/lisp/my/my-magit.el b/emacs/.emacs.d/lisp/my/my-magit.el
index d4c28bb..dc8d965 100644
--- a/emacs/.emacs.d/lisp/my/my-magit.el
+++ b/emacs/.emacs.d/lisp/my/my-magit.el
@@ -82,5 +82,45 @@ For use as a :filter-args advice"
(interactive)
(magit-show-commit "HEAD" '("--stat" "--no-ext-diff")))
+(defun my--smerge-side-rev (side label)
+ "Revision for an smerge-ediff SIDE buffer whose marker LABEL is given."
+ (let ((pick (seq-find #'magit-rev-verify
+ '("CHERRY_PICK_HEAD" "REBASE_HEAD"
+ "MERGE_HEAD" "REVERT_HEAD"))))
+ (cond ((and label (magit-rev-verify label)) label)
+ ((equal side "UPPER") "HEAD")
+ ((equal side "LOWER") pick)
+ ((equal side "BASE") (and pick (concat pick "^"))))))
+
+(defun my-ediff-side-blame ()
+ "Blame the current line of an smerge-ediff side buffer in its revision."
+ (interactive)
+ (unless (string-match "\\`\\*\\(.+?\\) \\(UPPER\\|LOWER\\|BASE\\)=\\([^ *]*\\)"
+ (buffer-name))
+ (user-error "Not an smerge-ediff UPPER/LOWER/BASE buffer"))
+ (let* ((name (match-string 1 (buffer-name)))
+ (side (match-string 2 (buffer-name)))
+ (rev (or (my--smerge-side-rev side (match-string 3 (buffer-name)))
+ (user-error "Cannot determine revision for %s" side)))
+ (files (seq-filter (lambda (f) (equal (file-name-nondirectory f) name))
+ (magit-unmerged-files)))
+ (file (if (cdr files) (completing-read "File: " files nil t)
+ (or (car files) (user-error "No unmerged file named %s" name))))
+ (line (line-number-at-pos))
+ (text (string-trim (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position))))
+ best)
+ (magit-find-file rev file)
+ (goto-char (point-min))
+ (while (search-forward text nil t)
+ (let ((l (line-number-at-pos)))
+ (when (or (null best) (< (abs (- l line)) (abs (- best line))))
+ (setq best l))))
+ (if (not best)
+ (message "Line not found in %s:%s" rev file)
+ (goto-char (point-min))
+ (forward-line (1- best))
+ (magit-blame-addition nil))))
+
(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 dec505e..da9445a 100644
--- a/emacs/.emacs.d/lisp/my/my-mariadb.el
+++ b/emacs/.emacs.d/lisp/my/my-mariadb.el
@@ -487,5 +487,50 @@ https://mariadb.com/docs/server/ha-and-performance/optimization-and-tuning/query
(buffer-substring-no-properties (point) (point-max)))))
(find-file file)))
+(defun my--sql-comment-start (s)
+ "Index in S where a trailing # or -- comment starts, or nil.
+Ignores comment characters inside '...', \"...\" and `...`."
+ (let ((i 0) (n (length s)) quote res)
+ (while (and (< i n) (not res))
+ (let ((c (aref s i)))
+ (cond
+ (quote (cond ((and (eq c ?\\) (not (eq quote ?`))) (setq i (1+ i)))
+ ((eq c quote) (setq quote nil))))
+ ((memq c '(?' ?\" ?`)) (setq quote c))
+ ((eq c ?#) (setq res i))
+ ((and (eq c ?-)
+ (< (1+ i) n) (eq (aref s (1+ i)) ?-)
+ (or (= (+ i 2) n) (memq (aref s (+ i 2)) '(?\s ?\t)))
+ (or (= i 0) (memq (aref s (1- i)) '(?\s ?\t))))
+ (setq res i))))
+ (setq i (1+ i)))
+ res))
+
+(defun my-mtr-trailing-comments-to-echo (beg end)
+ "Turn trailing SQL comments in region into --echo lines above them."
+ (interactive "r")
+ (let ((end (copy-marker end)))
+ (save-excursion
+ (goto-char beg)
+ (beginning-of-line)
+ (while (< (point) end)
+ (let* ((bol (point))
+ (eol (line-end-position))
+ (line (buffer-substring-no-properties bol eol))
+ (pos (and (not (string-match-p "\\`[ \t]*\\(#\\|--\\|$\\)" line))
+ (my--sql-comment-start line)))
+ (code (and pos (string-trim-right (substring line 0 pos)))))
+ (when (and code (string-suffix-p ";" code))
+ (let ((indent (progn (string-match "\\`[ \t]*" line)
+ (match-string 0 line)))
+ (text (string-trim
+ (replace-regexp-in-string
+ "\\`\\(#\\|--\\)" "" (substring line pos)))))
+ (delete-region bol eol)
+ (insert indent "--echo #" (if (string-empty-p text) "" " ") text
+ "\n" code))))
+ (forward-line 1)))
+ (set-marker end nil)))
+
(provide 'my-mariadb)
;;; my-mariadb.el ends here
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index 85fd876..9e16498 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -675,5 +675,12 @@ is indented by +; otherwise it lines up with /*."
'+
0))))
+(defun my-compilation-bell-on-failure (buf status)
+ (unless (string-prefix-p "finished" status)
+ (with-current-buffer buf
+ (unless (derived-mode-p 'grep-mode) ; grep exits 1 when nothing matches
+ (ding)
+ (message "Compilation failed: %s" (string-trim status))))))
+
(provide 'my-prog)
;;; my-prog.el ends here
diff --git a/misc/.bashrc b/misc/.bashrc
index 8677bb6..e000c79 100644
--- a/misc/.bashrc
+++ b/misc/.bashrc
@@ -284,21 +284,17 @@ gs-merge() {
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="$@"
}
-_chime() {
- "$@"
+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
+ play -V1 -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
+ play -V1 -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"