by natrys · 3y ago · 0 comments
(defun my-sort-list ()
(interactive)
(when (not (looking-at (rx "[")))
(search-backward "[" nil t))
(when-let* ((line (thing-at-point 'sexp t))
(items (split-string (substring line 1 -1) (rx ",") t (rx blank)))
(sorted (string-join (sort items #'string-lessp) ", ")))
(kill-sexp)
(insert "[" sorted "]")))
I don't think I am using any non-builtin function here, though I think a few exceptions like s.el, f.el and dash.el can make things much easier. (let ((list (treesit-thing-at-point "list" 'nested))
(query "(list (string (string_content) @item))"))
(cl-loop for (_ . item) in (treesit-query-capture list query)
collect (treesit-node-text item t)))