From 734009505c3a993c8b947cf68796b252dd435d6e Mon Sep 17 00:00:00 2001 From: ag91 Date: Sun, 11 Aug 2024 18:16:41 +0100 Subject: [PATCH] improve navigation to mold when inspecting starting times now C-c C-o opens the mold source in the mold buffer --- moldable-emacs.el | 62 ++++++++++++++++++++++++----------------------- molds/core.el | 8 ++++++ 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/moldable-emacs.el b/moldable-emacs.el index 4cbea64..5708485 100644 --- a/moldable-emacs.el +++ b/moldable-emacs.el @@ -99,7 +99,7 @@ all-keys))) (defun me-get-in (plist keys) -"Navigate PLIST's KEYS in sequence. + "Navigate PLIST's KEYS in sequence. For example, (me-get-in '(:a (:b (:c 1))) '(:a :b :c)) yields 1. >> (me-get-in '(:a (:b 1)) '(:a :b)) @@ -109,17 +109,22 @@ For example, (me-get-in '(:a (:b (:c 1))) '(:a :b :c)) yields 1. => 1 >> (me-get-in '((a . ((b . 1)))) '(a b)) -=> 1" -(let ((access - (lambda (key list) (if (me-plistp plist) - (plist-get list key) - (alist-get key list))))) - (--reduce-from - (if (numberp it) - (nth it acc) - (funcall access it acc)) - plist - keys))) +=> 1 + +>> (me-get-in '(:a (1 2 3)) '(:a)) +=> (1 2 3) +" + (let ((access + (lambda (key list) + (if (me-plistp plist) + (plist-get list key) + (alist-get key list))))) + (--reduce-from + (if (numberp it) + (nth it acc) + (funcall access it acc)) + plist + keys))) (defmacro me-with-file (file &rest body) "Open FILE, execute BODY close FILE if it was not already open." @@ -2019,24 +2024,21 @@ This stores the original screen configuration in the `m' register." (defun me-goto-mold-source (mold) "Go to source code of MOLD." (interactive - (list nil)) - (let* ((molds me-available-molds) - (keys (--map (plist-get it :key) molds)) - (picked-mold (or mold - (completing-read - "Pick the mold you need:" - keys)))) - (--> picked-mold - (-find - (lambda (x) - (string= - (plist-get x :key) - it)) - molds) - (plist-get it :origin) - (find-file it)) - (goto-char (point-min)) - (search-forward picked-mold))) + (list + (completing-read + "Pick the mold you need:" + (--map (plist-get it :key) me-available-molds)))) + (--> mold + (-find + (lambda (x) + (string= + (plist-get x :key) + it)) + me-available-molds) + (plist-get it :origin) + (find-file it)) + (goto-char (point-min)) + (search-forward mold)) (defun me-org-roam-backlinks-contents (node &optional depth) "Collect NODE backlink contents. diff --git a/molds/core.el b/molds/core.el index b7e8fea..ee6da93 100644 --- a/molds/core.el +++ b/molds/core.el @@ -1025,6 +1025,13 @@ It specializes for source code." (emacs-lisp-mode) (erase-buffer) (me-print-to-buffer stats) + (me-override-keybiding-in-buffer + (kbd "C-c C-o") + '(lambda () + (interactive) + (let ((entry (read (when-let ((line (thing-at-point 'line))) (and (s-starts-with-p "(:mold" (s-trim line)) line))))) + (message "xxxx %s" (list entry (plist-get entry :mold))) + (me-goto-mold-source (plist-get entry :mold))))) (setq-local self stats)))) :docs "You can see how long did the mold take to evaluate the given clause." :examples nil) @@ -1102,6 +1109,7 @@ It specializes for source code." (me-register-mold :key "ShowElispAPI" :given (:fn (ignore-errors (and + nil ;; didn't find this useful, I will delete it later (equal major-mode 'emacs-lisp-mode) (me-mold-treesitter-to-parse-tree)))) :then (:fn