From 5e5406f6b1b47b84591ee9dea4233164e9a55fb0 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Fri, 5 Apr 2024 09:08:12 +1100 Subject: [emacs] improve org backtrace region --- emacs/.emacs.d/lisp/my/my-mariadb.el | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) (limited to 'emacs/.emacs.d/lisp/my/my-mariadb.el') diff --git a/emacs/.emacs.d/lisp/my/my-mariadb.el b/emacs/.emacs.d/lisp/my/my-mariadb.el index 355b89e..984cc29 100644 --- a/emacs/.emacs.d/lisp/my/my-mariadb.el +++ b/emacs/.emacs.d/lisp/my/my-mariadb.el @@ -154,5 +154,98 @@ (kill-line 1) ))) +(defvar my-mdev-32524-ids nil "List of ids used.") + +(defun my-mdev-32524-make-id () + "Return an id on the current position." + (let* ((base + (replace-regexp-in-string + "::" "_" + (replace-regexp-in-string + "^\\(SPIDER_\\)?" "SPD_MID_" + (upcase (which-function))))) + (last-id (car my-mdev-32524-ids)) + (counter (cdr last-id)) + (result)) + (if (equal (car last-id) base) + (progn + (setq result (format "%s_%d" base (1+ counter))) + (push (cons base (1+ counter)) my-mdev-32524-ids)) + (setq result (format "%s_1" base)) + (push (cons base 1) my-mdev-32524-ids)) + result)) + +(defun my-mdev-32524-replace-ids () + "Replace magic id numbers with enum symbols." + (setq my-mdev-32524-ids nil) + (dolist (file (directory-files "./storage/spider" t ".\\(cc\\|h\\)$")) + ;; Don't do this with spd_malloc.{cc,h} + (unless (string-match "spd_malloc" file) + (with-current-buffer (find-file-noselect file) + (goto-char (point-min)) + (while (re-search-forward + (concat + "\\(spider_alloc_calc_mem_init\\|init_calc_mem\\|spider_malloc\\|" + "spider_bulk_alloc_mem\\|spider_bulk_malloc\\)" + "\\(([^0-9)_]*\\)\\([0-9]+\\)") + nil t) + (let ((beg (match-beginning 3)) + (end (match-end 3))) + (replace-region-contents beg end #'my-mdev-32524-make-id))) + (save-buffer))))) + +(defun my-mdev-32524-insert-enum-def () + "Insert enum def at point according to `my-mdev-32524-ids'." + (with-current-buffer (find-file-noselect "./storage/spider/spd_include.h") + (goto-char (point-min)) + (re-search-forward "#define.* SPIDER_CONN_META_BUF_LEN") + (beginning-of-line 2) + (let ((pre + " +/* + IDs for spider mem alloc functions, including + - spider_alloc_calc_mem_init() + - spider_string::init_calc_mem() + - spider_malloc() + - spider_bulk_alloc_mem() + - spider_bulk_malloc() + In the format of + SPD_MID__ +*/ +enum spider_malloc_id { + ") + (middle (string-join + (sort + (mapcar + (lambda (pair) + (format "%s_%d" (car pair) (cdr pair))) + my-mdev-32524-ids) + #'string<) + ", + ")) + (post " +}; +")) + (insert (concat pre middle post)) + (save-buffer)))) + +(defun my-mdev-32524 () + "Make changes for MDEV-32524. Assuming we are at the source root." + (interactive) + (my-mdev-32524-replace-ids) + (my-mdev-32524-insert-enum-def)) + +(defun my-mdev-28861-ps () + "Wrap the current line between --disable_ps_protocol and --enable_ps_protocol" + (interactive) + (save-excursion + (beginning-of-line) + (push-mark + (save-excursion + (beginning-of-line 2) + (point)) + nil t) + (tempel-insert 'ps))) + (provide 'my-mariadb) ;;; my-mariadb.el ends here -- cgit v1.2.3