Skip to content

Commit

Permalink
improve navigation to mold when inspecting starting times
Browse files Browse the repository at this point in the history
now C-c C-o opens the mold source in the mold buffer
  • Loading branch information
ag91 committed Aug 11, 2024
1 parent 188f655 commit 7340095
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
62 changes: 32 additions & 30 deletions moldable-emacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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."
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions molds/core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7340095

Please sign in to comment.