Function: cider-ns-edit--delete-elements

cider-ns-edit--delete-elements is a byte-compiled function defined in cider-ns.el.

Signature

(cider-ns-edit--delete-elements POS INDICES)

Documentation

Delete the elements at INDICES of the list or vector at POS.

INDICES count from 0. What stays keeps its layout, comments included. Each run of consecutive elements goes with

- the lines it's on, when it has them to itself;
- the blanks up to what follows it on its line, if anything does;
- the blanks up to the next element, when it comes right after the
  opening delimiter or the first element;
- the blanks back to the element before it, otherwise.

A comment that follows a run on its line goes with it.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20261106.1225/cider-ns.el
;;; Cleaning the ns form

(defun cider-ns-edit--delete-elements (pos indices)
  "Delete the elements at INDICES of the list or vector at POS.
INDICES count from 0.  What stays keeps its layout, comments included.
Each run of consecutive elements goes with

- the lines it's on, when it has them to itself;
- the blanks up to what follows it on its line, if anything does;
- the blanks up to the next element, when it comes right after the
  opening delimiter or the first element;
- the blanks back to the element before it, otherwise.

A comment that follows a run on its line goes with it."
  (let* ((elements (vconcat (cider-ns-edit--elements pos)))
         (count (length elements))
         runs)
    ;; Runs of consecutive indices, the last first.
    (dolist (index (sort (seq-uniq indices) #'<))
      (if (and runs (= index (1+ (cdar runs))))
          (setcdr (car runs) index)
        (push (cons index index) runs)))
    (pcase-dolist (`(,first . ,last) runs)
      (let ((beg (aref elements first))
            (end (scan-sexps (aref elements last) 1))
            (next (and (< (1+ last) count) (aref elements (1+ last)))))
        (goto-char end)
        (skip-chars-forward " \t,")
        (when (eq (char-after) ?\;)
          (end-of-line)
          (setq end (point)))
        (cond
         ((and next
               (eolp)
               (save-excursion (goto-char beg) (skip-chars-backward " \t,") (bolp)))
          (setq beg (save-excursion (goto-char beg) (line-beginning-position))
                end (line-beginning-position 2)))
         ((and next (not (eolp)))
          (setq end (point)))
         ((and next
               (<= first 1)
               (progn (skip-chars-forward " \t\n,") (= (point) next)))
          (setq end next))
         ((> first 0)
          (goto-char beg)
          (skip-chars-backward " \t\n," (scan-sexps (aref elements (1- first)) 1))
          ;; Never join up with a comment, which would swallow what follows.
          (unless (nth 4 (syntax-ppss))
            (setq beg (point)))))
        (delete-region beg end)))))