aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-01-18 08:56:21 +1100
committerYuchen Pei <id@ypei.org>2025-01-18 08:56:21 +1100
commitdef1c859b40d09e44c2b0e2bc95d0cf450ff60b4 (patch)
tree07f0de26ababee151112d64833d47ab776553403
parentddb5b07e1e43c7b44877bae9d786dbb80ca95311 (diff)
[emacs] eval expr in gud source and infobox value transform
-rw-r--r--emacs/.emacs.d/init/ycp-prog.el4
-rw-r--r--emacs/.emacs.d/init/ycp-web.el20
-rw-r--r--emacs/.emacs.d/lisp/my/infobox.el9
-rw-r--r--emacs/.emacs.d/lisp/my/my-github.el4
-rw-r--r--emacs/.emacs.d/lisp/my/my-prog.el11
5 files changed, 39 insertions, 9 deletions
diff --git a/emacs/.emacs.d/init/ycp-prog.el b/emacs/.emacs.d/init/ycp-prog.el
index 39427e8..3209e81 100644
--- a/emacs/.emacs.d/init/ycp-prog.el
+++ b/emacs/.emacs.d/init/ycp-prog.el
@@ -191,6 +191,8 @@
(:delay 5)
(define-key c-mode-map (kbd "C-c C-c") 'compile)
(define-key c++-mode-map (kbd "C-c C-c") 'project-compile)
+ (define-key c-mode-map (kbd "C-x C-e") 'my-gud-print-expr-region)
+ (define-key c++-mode-map (kbd "C-x C-e") 'my-gud-print-expr-region)
(add-to-list 'auto-mode-alist '("\\.inl\\'" . c++-mode))
(setq c-default-style
'((java-mode . "java")
@@ -211,7 +213,7 @@
(add-hook 'c-mode-hook 'my-c-set-compile-command)
(define-key c-mode-map (kbd "C-c s") 'my-c-switch-between-header-and-source)
(define-key c++-mode-map (kbd "C-c s")
- 'my-c-switch-between-header-and-source)
+ 'my-c-switch-between-header-and-source)
(my-override bookmark-make-record)
)
diff --git a/emacs/.emacs.d/init/ycp-web.el b/emacs/.emacs.d/init/ycp-web.el
index f72c609..6083b35 100644
--- a/emacs/.emacs.d/init/ycp-web.el
+++ b/emacs/.emacs.d/init/ycp-web.el
@@ -260,7 +260,12 @@
"b" #'my-eww-switch-by-title)
(my-keybind global-map "\C-c\C-o" #'my-browse-url-at-point)
(my-setq-from-local my-newscorp-au-amp-nk)
- )
+ (add-to-list 'browse-url-handlers
+ `(my-newscorp-au-url-p
+ . ,(lambda (url &rest _) (my-open-newscorp-au url))))
+ (add-to-list 'browse-url-handlers
+ `("^https?://www.spectator.com.au\\>" .
+ ,(lambda (url &rest _) (my-fetch-browse-as-googlebot url)))) )
(my-package my-gitlab
(:delay 60)
@@ -269,6 +274,13 @@
. ,(lambda (url &rest _) (my-gitlab-project-infobox url))))
)
+(my-package my-github
+ (:delay 60)
+ (add-to-list 'browse-url-handlers
+ `(my-github-project-url-p
+ . ,(lambda (url &rest _) (my-github-project-infobox url))))
+ )
+
(my-package my-ytdl
(:delay 60)
(add-to-list 'browse-url-handlers
@@ -329,12 +341,6 @@
(add-to-list 'browse-url-handlers
`(my-mastodon-url-p
. ,(lambda (url &rest _) (mastorg-open url))))
- (add-to-list 'browse-url-handlers
- `(my-newscorp-au-url-p
- . ,(lambda (url &rest _) (my-open-newscorp-au url))))
- (add-to-list 'browse-url-handlers
- `("^https?://www.spectator.com.au\\>" .
- ,(lambda (url &rest _) (my-fetch-browse-as-googlebot url))))
)
(add-to-list 'load-path (locate-user-emacs-file "lisp/servall/lisp"))
diff --git a/emacs/.emacs.d/lisp/my/infobox.el b/emacs/.emacs.d/lisp/my/infobox.el
index 518c7db..2c33ae9 100644
--- a/emacs/.emacs.d/lisp/my/infobox.el
+++ b/emacs/.emacs.d/lisp/my/infobox.el
@@ -27,6 +27,13 @@
;;; Code:
+(defun infobox-transform-field-value (v)
+ (cond ((stringp v) v)
+ ((eq v t) "YES")
+ ((eq v :json-false) "NO")
+ ((seqp v) (mapconcat #'identity v ", "))
+ (t (format "%s" v))))
+
(defun infobox-default-specs (info)
(seq-map
(lambda (pair)
@@ -47,7 +54,7 @@ something like
(lambda (pair)
(when-let ((val (alist-get (car pair) info)))
(if (or (stringp (cdr pair)) (symbolp (cdr pair)))
- (cons (cdr pair) val)
+ (cons (cdr pair) (infobox-transform-field-value val))
(cons (cadr pair) (funcall (cddr pair) val)))))
specs))
diff --git a/emacs/.emacs.d/lisp/my/my-github.el b/emacs/.emacs.d/lisp/my/my-github.el
index 1643612..7caff57 100644
--- a/emacs/.emacs.d/lisp/my/my-github.el
+++ b/emacs/.emacs.d/lisp/my/my-github.el
@@ -75,6 +75,10 @@ License; name; description; homepage; created at"
(my-url-fetch-raw
(format "https://api.github.com/repos%s/readme" project-id))))
+(defun my-github-project-url-p (url)
+ (let ((urlobj (url-generic-parse-url url)))
+ (string-match-p "\\(www\\.\\)?github.com" (url-host urlobj))))
+
(defun my-github-project-infobox (url)
(interactive "sGithub repo url: ")
(let ((info
diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el
index d93c745..faf20b6 100644
--- a/emacs/.emacs.d/lisp/my/my-prog.el
+++ b/emacs/.emacs.d/lisp/my/my-prog.el
@@ -442,6 +442,17 @@ overlay arrow in source buffer."
;; (accept-process-output (get-buffer-process gud-comint-buffer) .1)))
;; (gud-gdb-completions-1 gud-gdb-fetched-lines)))
+(defun my-gud-print-expr (expr)
+ (with-current-buffer gud-comint-buffer
+ (insert "p " expr)
+ (comint-send-input)))
+
+(defun my-gud-print-expr-region (b e)
+ (interactive "r")
+ (if (eq (gdb-get-source-buffer) (current-buffer))
+ (my-gud-print-expr (buffer-substring b e))
+ (error "Not in the source buffer")))
+
;;; which-func
(defun my-copy-which-func ()
(interactive)