diff options
| author | Vineet Kumar <git@vineetk.net> | 2026-05-28 14:29:57 -0400 |
|---|---|---|
| committer | Vineet Kumar <git@vineetk.net> | 2026-05-28 14:29:57 -0400 |
| commit | 389f1a7e240eca36443649d6b283c21cfeb51c08 (patch) | |
| tree | 1cb0e0b52cf4626488d2ff9d30ab91f264d8d0e0 /llm-tools-hl.el | |
| parent | 9ff38dcde67b1c0d597eaa0bee00c395f2f272e6 (diff) | |
get ready for packagingv1.0
Diffstat (limited to 'llm-tools-hl.el')
| -rw-r--r-- | llm-tools-hl.el | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/llm-tools-hl.el b/llm-tools-hl.el index b095a6e..daf9edd 100644 --- a/llm-tools-hl.el +++ b/llm-tools-hl.el | |||
| @@ -1,4 +1,35 @@ | |||
| 1 | ;; -*- lexical-binding: t; -*- | 1 | ;; llm-tools-hl.el --- Hashline file operations for llm-tools -*- lexical-binding: t; -*- |
| 2 | |||
| 3 | ;; Copyright (C) 2026 Vineet K | ||
| 4 | |||
| 5 | ;; Author: Vineet K <git@vineetk.net> | ||
| 6 | ;; Version: 1.0 | ||
| 7 | ;; Keywords: llm, gptel | ||
| 8 | ;; Package-Requires: ((emacs "28.1")) | ||
| 9 | |||
| 10 | ;; This program is free software; you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; This program is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Hashline-based file operations for the llm-tools package. | ||
| 26 | ;; Provides functions for reading, editing, and verifying files using | ||
| 27 | ;; a content-addressed line format. | ||
| 28 | |||
| 29 | ;;; Code: | ||
| 30 | |||
| 31 | (require 'cl-lib) | ||
| 32 | |||
| 2 | (defvar llm-tools--hl-bigrams | 33 | (defvar llm-tools--hl-bigrams |
| 3 | (list "aa" "ab" "ac" "ad" "ae" "af" "ag" "ah" "ai" "aj" "ak" "al" "am" "an" | 34 | (list "aa" "ab" "ac" "ad" "ae" "af" "ag" "ah" "ai" "aj" "ak" "al" "am" "an" |
| 4 | "ao" "ap" "aq" "ar" "as" "at" "au" "av" "aw" "ax" "ay" "az" "ba" "bb" | 35 | "ao" "ap" "aq" "ar" "as" "at" "au" "av" "aw" "ax" "ay" "az" "ba" "bb" |
| @@ -119,7 +150,7 @@ single string." | |||
| 119 | (not (string-prefix-p "#" trimmed))))) | 150 | (not (string-prefix-p "#" trimmed))))) |
| 120 | 151 | ||
| 121 | (defun llm-tools--hl-parse-op-line-for-verify (line) | 152 | (defun llm-tools--hl-parse-op-line-for-verify (line) |
| 122 | "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op`." | 153 | "Parse a single operation LINE (e.g. \"+ 4ei\") into a `hl-verify-op'." |
| 123 | (let* ((trimmed (string-trim line)) | 154 | (let* ((trimmed (string-trim line)) |
| 124 | (ch (substring trimmed 0 1))) | 155 | (ch (substring trimmed 0 1))) |
| 125 | (make-hl-verify-op | 156 | (make-hl-verify-op |
| @@ -334,7 +365,7 @@ line in the on-disk file." | |||
| 334 | (string-to-number (substring anchor 0 (- (length anchor) 2)))) | 365 | (string-to-number (substring anchor 0 (- (length anchor) 2)))) |
| 335 | 366 | ||
| 336 | (defun llm-tools--hl-parse-op-line (line) | 367 | (defun llm-tools--hl-parse-op-line (line) |
| 337 | "Parse a single operation LINE into an `hl-op` struct. | 368 | "Parse a single operation LINE into an `hl-op' struct. |
| 338 | LINE must start with `+`, `<`, `-`, or `=`, followed by a space, | 369 | LINE must start with `+`, `<`, `-`, or `=`, followed by a space, |
| 339 | followed by an anchor (or range)." | 370 | followed by an anchor (or range)." |
| 340 | (string-match "^[+<=-] \\(.*\\)" line) ; returns index or nil | 371 | (string-match "^[+<=-] \\(.*\\)" line) ; returns index or nil |
| @@ -349,7 +380,7 @@ followed by an anchor (or range)." | |||
| 349 | ("=" (make-hl-op :type 'replace :range (split-string anchor "\\.\\.")))))) | 380 | ("=" (make-hl-op :type 'replace :range (split-string anchor "\\.\\.")))))) |
| 350 | 381 | ||
| 351 | (defun llm-tools--hl-parse-section (section) | 382 | (defun llm-tools--hl-parse-section (section) |
| 352 | "Parse SECTION (body after `@@ PATH`) into a list of `hl-op` structs. | 383 | "Parse SECTION (body after `@@ PATH`) into a list of `hl-op' structs. |
| 353 | Skips comment lines (starting with `#`) and blank lines." | 384 | Skips comment lines (starting with `#`) and blank lines." |
| 354 | (let (ops op) | 385 | (let (ops op) |
| 355 | (dolist (line (string-lines section)) | 386 | (dolist (line (string-lines section)) |
| @@ -414,7 +445,7 @@ FILENAME." | |||
| 414 | (- offset (- b a 1))))) | 445 | (- offset (- b a 1))))) |
| 415 | 446 | ||
| 416 | (defun llm-tools--hl-apply-replace (range payload content offset) | 447 | (defun llm-tools--hl-apply-replace (range payload content offset) |
| 417 | "Replace lines from (car RANGE) to (cadr RANGE) with PAYLOAD (nil → '(\"\"))" | 448 | "Replace lines from (car RANGE) to (cadr RANGE) with PAYLOAD (nil to '(\"\"))" |
| 418 | (let ((a (+ (llm-tools--hl-anchor-to-line-num (car range)) offset)) | 449 | (let ((a (+ (llm-tools--hl-anchor-to-line-num (car range)) offset)) |
| 419 | (b (+ (llm-tools--hl-anchor-to-line-num (cadr range)) offset)) | 450 | (b (+ (llm-tools--hl-anchor-to-line-num (cadr range)) offset)) |
| 420 | (payload (or payload '("")))) | 451 | (payload (or payload '("")))) |
