commit 56c14ff82a18748603b3a49cd66e04fe059c3b0a
parent 31372203feb19e452730b722c6202f11dd9039d2
Author: Vineet Kumar <git@vineetk.net>
Date: Mon, 25 May 2026 20:43:41 -0400
replace most of the dolists with maps
Diffstat:
| M | llm-tools-hl.el | | | 69 | +++++++++++++++++++++++++++++++++------------------------------------ |
1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/llm-tools-hl.el b/llm-tools-hl.el
@@ -159,23 +159,20 @@ Each element is a line number and two-character hash, like `1vx'."
(defun llm-tools--hl-validate-insert-has-payload (ops)
"Check that all insert ops have at least one payload line."
- (let (errors)
- (dolist (op ops)
- (when (and (memq (hl-verify-op-type op) '(insert-after insert-before))
- (null (hl-verify-op-payload op)))
- (push (format "Insert operation (%s) has no payload lines following it"
- (hl-verify-op-type op))
- errors)))
- (nreverse errors)))
+ (mapcan (lambda (op)
+ (when (and (memq (hl-verify-op-type op) '(insert-after insert-before))
+ (null (hl-verify-op-payload op)))
+ (list (format "Insert operation (%s) has no payload lines following it"
+ (hl-verify-op-type op)))))
+ ops))
(defun llm-tools--hl-validate-delete-no-payload (ops)
"Check that delete ops have no payload lines."
- (let (errors)
- (dolist (op ops)
- (when (and (eq (hl-verify-op-type op) 'delete)
- (hl-verify-op-payload op))
- (push "Delete operation (-) must not have payload lines" errors)))
- errors))
+ (mapcan (lambda (op)
+ (when (and (eq (hl-verify-op-type op) 'delete)
+ (hl-verify-op-payload op))
+ (list "Delete operation (-) must not have payload lines")))
+ ops))
(defun llm-tools--hl-validate-insert-anchor (anchor)
"Return error string if ANCHOR is malformed for insert, else nil."
@@ -201,16 +198,15 @@ Each element is a line number and two-character hash, like `1vx'."
(defun llm-tools--hl-validate-anchors (ops)
"Check that all anchors are well-formed."
- (let (errors)
- (dolist (op ops)
- (pcase (hl-verify-op-type op)
- ((or 'insert-after 'insert-before)
- (let ((err (llm-tools--hl-validate-insert-anchor (hl-verify-op-anchor op))))
- (when err (push err errors))))
- ((or 'delete 'replace)
- (let ((err (llm-tools--hl-validate-range-anchor (hl-verify-op-anchor op))))
- (when err (push err errors))))))
- (nreverse errors)))
+ (mapcan (lambda (op)
+ (pcase (hl-verify-op-type op)
+ ((or 'insert-after 'insert-before)
+ (when-let ((err (llm-tools--hl-validate-insert-anchor (hl-verify-op-anchor op))))
+ (list err)))
+ ((or 'delete 'replace)
+ (when-let ((err (llm-tools--hl-validate-range-anchor (hl-verify-op-anchor op))))
+ (list err)))))
+ ops))
(defun llm-tools--hl-verify-section (section)
"Validate a single SECTION. Returns a list of error strings."
@@ -454,18 +450,19 @@ Returns the modified list of strings."
"Apply all operations in PATCH to their respective files.
Operations within a file are applied sequentially, with line numbers
adjusted for prior insertions/deletions via a running offset."
- (dolist (file-group (llm-tools--hl-group-by-file
- (llm-tools--split-patch-sections patch)))
- (let* ((file (car file-group))
- (ops (mapcan (lambda (sec)
- (llm-tools--hl-parse-section (cdr sec)))
- (cdr file-group)))
- (content (llm-tools--hl-apply-ops
- ops
- (llm-tools--hl-file-lines file))))
- (with-temp-buffer
- (insert (string-join content "\n"))
- (write-region (point-min) (point-max) file)))))
+ (mapc (lambda (file-group)
+ (let* ((file (car file-group))
+ (ops (mapcan (lambda (sec)
+ (llm-tools--hl-parse-section (cdr sec)))
+ (cdr file-group)))
+ (content (llm-tools--hl-apply-ops
+ ops
+ (llm-tools--hl-file-lines file))))
+ (with-temp-buffer
+ (insert (string-join content "\n"))
+ (write-region (point-min) (point-max) file))))
+ (llm-tools--hl-group-by-file
+ (llm-tools--split-patch-sections patch))))
(defun llm-tools--hl-edit (patch)
"Apply a hashline PATCH to the files it references.