Function: combobulate-cursor-edit-identical-nodes
combobulate-cursor-edit-identical-nodes is a natively compiled
function defined in combobulate-cursor.el.
Signature
(combobulate-cursor-edit-identical-nodes NODE ACTION &optional MATCH-FN)
Documentation
Edit nodes identical to NODE if they match MATCH-FN.
The locus of editable nodes is determined by NODE's parents and is selectable.
MATCH-FN takes one argument, a node, and should return non-nil if it is a match.
Source Code
;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-cursor.el
(defun combobulate-cursor-edit-identical-nodes (node action &optional match-fn)
"Edit nodes identical to NODE if they match MATCH-FN.
The locus of editable nodes is determined by NODE's parents and
is selectable.
MATCH-FN takes one argument, a node, and should return non-nil if it is
a match."
(let ((matches)
;; default to 1 "match" as there's no point in creating
;; multiple cursors when there's just one match
(ct 1)
(grouped-matches))
(dolist (start-node (combobulate-get-parents node))
(let ((known-ranges (make-hash-table :test #'equal :size 1024)))
(setq matches (flatten-tree (combobulate-induce-sparse-tree
start-node
(lambda (tree-node)
(prog1
(and (funcall match-fn tree-node)
(not (gethash (combobulate-node-range tree-node) known-ranges nil)))
(puthash (combobulate-node-range tree-node) t known-ranges)))))))
;; this catches parent nodes that do not add more, new, nodes to
;; the editing locus by filtering them out.
(when (> (length matches) ct)
(setq ct (length matches))
(push (cons start-node matches) grouped-matches)))
(combobulate-refactor ()
(cl-flet ((current-matches (n) (cdr (assoc (combobulate-proxy-node-to-real-node n) grouped-matches))))
(let* ((chosen-node (combobulate-proxy-node-to-real-node
(combobulate-proffer-choices
(reverse (mapcar 'car grouped-matches))
(lambda-slots (current-node proxy-nodes refactor-id)
(combobulate-refactor (:id refactor-id)
(rollback)
(mark-node-highlighted current-node)
(princ (format "Editing %s in %s%s\n"
(combobulate-pretty-print-node-type current-node)
(combobulate-proxy-node-to-real-node current-node)
(and (combobulate-node-field-name current-node)
(format " (%s)"
(combobulate-node-field-name current-node)))))
;; rollback the outer
;; `combobulate-refactor' call so
;; the node cursors we place below
;; are properly erased.
;; place a fake cursor at every
;; node to indicate where the
;; matching nodes are.
(mapc #'mark-node-cursor (current-matches current-node))
;; indicate the locus of editing
;; by highlighting the entire node
;; boundary.
(mark-node-highlighted current-node)))
:flash-node t
:unique-only nil
:prompt-description
(lambda-slots (current-node proxy-nodes)
(concat
(propertize
(format "[%d/%d]" (length (current-matches current-node)) ct)
'face 'shadow)
" "
(format "Edit `%s' in"
(propertize (combobulate-pretty-print-node-type node)
'face 'combobulate-tree-branch-face)))))))
(matches (cdr (assoc chosen-node grouped-matches))))
(rollback)
(combobulate-cursor-edit-nodes matches action chosen-node))))))