From b2ac82792c6f6a4404844c89d76bebf1e9947413 Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Sat, 23 May 2026 21:00:35 -0400 Subject: add some more hl-* reading functions it feels like there's a lot of duplication I need to get rid of --- gptel-tools-hl.el | 60 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/gptel-tools-hl.el b/gptel-tools-hl.el index d186dd3..45d44fe 100644 --- a/gptel-tools-hl.el +++ b/gptel-tools-hl.el @@ -59,24 +59,48 @@ Precisely: https://raw.githubusercontent.com/can1357/oh-my-pi/85003ca/packages/c (defun hl-file-read (file) "Return FILE contents in hashline format." - (let ((lines (with-temp-buffer - (insert-file-contents-literally file) - (string-lines (buffer-string))))) - (string-join - (cl-mapcar (lambda (line i) - (format "%d:%2s|%s" i (hl-hash line) line)) - lines - (number-sequence 1 (length lines))) - "\n"))) + (with-temp-buffer + (insert-file-contents-literally file) + (let ((lines (string-lines (buffer-string)))) + (string-join + (cl-mapcar (lambda (line i) + (format "%d%2s|%s" i (hl-hash line) line)) + lines + (number-sequence 1 (length lines))) + "\n")))) +(defun hl-file-read-range (file beg end) + "Return FILE contents in hashline format from lines BEG to END." + (with-temp-buffer + (insert-file-contents-literally file) + (let ((lines (cl-subseq (string-lines (buffer-string)) + (1- beg) end))) + (string-join + (cl-mapcar (lambda (line i) + (format "%d%2s|%s" i (hl-hash line) line)) + lines + (number-sequence beg (+ beg (1- (length lines))))) + "\n")))) + +;; FIXME might be redundant with =hl-file-line-hash= if I'm only +;; verifying the hash of the anchors and telling LLM to re-read the +;; file when they don't match (defun hl-file-read-hashes (file) "Return FILE contents in hashline format without content." - (let ((lines (with-temp-buffer - (insert-file-contents-literally file) - (string-lines (buffer-string))))) - (string-join - (cl-mapcar (lambda (line i) - (format "%d:%2s" i (hl-hash line))) - lines - (number-sequence 1 (length lines))) - "\n"))) + (with-temp-buffer + (insert-file-contents-literally file) + (let ((lines (string-lines (buffer-string)))) + (string-join + (cl-mapcar (lambda (line i) + (format "%d%2s" i (hl-hash line))) + lines + (number-sequence 1 (length lines))) + "\n")))) + +(defun hl-file-line-hash (file n) + "Return the hash of the Nth line in FILE." + (with-temp-buffer + (insert-file-contents-literally file) + (let ((lines (string-lines (buffer-string)))) + (hl-hash (elt lines (1- n)))))) + -- cgit v1.2.3