Skip to content

Commit

Permalink
add RegionToCodeTree
Browse files Browse the repository at this point in the history
to make it easy to transform bits of code in code tree to query.
For instance I had a python code snippet that I wanted to query with a
bit of elisp.
  • Loading branch information
ag91 committed Sep 3, 2024
1 parent 46b5fd0 commit cd16313
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions moldable-emacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -1891,8 +1891,8 @@ Optionally filter for files with FILE-EXTENSION."
(let ((filename (let ((default-directory dir)) (expand-file-name it))))
(or
(ignore-errors (me-filepath-to-flattened-tree filename)) ; sometimes there is an encoding issue with this that I can fix me-mold-treesitter-to-parse-tree
(ignore-errors (with-file filename
(me-mold-treesitter-to-parse-tree)))))
(ignore-errors (me-with-file filename
(me-mold-treesitter-to-parse-tree)))))
it)))

(defun me-project-to-flattened-nodes (dir &optional file-extension)
Expand Down
27 changes: 27 additions & 0 deletions molds/core.el
Original file line number Diff line number Diff line change
Expand Up @@ -1157,3 +1157,30 @@ It specializes for source code."
(setq-local self tree))))
:docs "You can produce an org table with headings from one obtained from a list of plists."
:examples nil)

(me-register-mold
:key "RegionToCodeTree"
:given (:fn (region-active-p))
:then (:fn
(let* ((filename (read-file-name
"Store in" "/tmp/"
nil
nil
(concat "/tmp/moldable-emacs-"
(with-temp-buffer
(uuidgen t)
(s-trim (buffer-string)))
".")))
(selection (me-get-region))
(_ (with-temp-file filename
(insert selection)))
(tree (me-with-file filename
(me-mold-treesitter-to-parse-tree))))
(with-current-buffer buffername
(emacs-lisp-mode)
(erase-buffer)
(me-print-to-buffer tree)
(setq-local self tree))
))
:docs "You can turn a region to a code tree."
:examples nil)

0 comments on commit cd16313

Please sign in to comment.