[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 0abaefed38 13/20: gptel-context: Fix narrowing bug w
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 0abaefed38 13/20: gptel-context: Fix narrowing bug when inserting context |
Date: |
Sun, 23 Jun 2024 00:59:53 -0400 (EDT) |
branch: elpa/gptel
commit 0abaefed3882a2b46b291646fcc8f469fbf7e059
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: karthink <karthikchikmagalur@gmail.com>
gptel-context: Fix narrowing bug when inserting context
* gptel-context.el (gptel-context--insert-buffer-string,
gptel-context--collect): When adding the context to the user
prompt, handle narrowed buffers correctly. When collecting the
context, handle killed buffers correctly.
---
gptel-context.el | 54 ++++++++++++++++++++++++++----------------------------
1 file changed, 26 insertions(+), 28 deletions(-)
diff --git a/gptel-context.el b/gptel-context.el
index 54f6c2edd4..5d46cef122 100644
--- a/gptel-context.el
+++ b/gptel-context.el
@@ -233,7 +233,7 @@ START and END signify the region delimiters."
if (cl-loop for ov in ovs when (overlay-start ov) collect
ov)
collect (cons buf it) into elements
end
- else if (file-exists-p buf)
+ else if (and (stringp buf) (file-exists-p buf))
collect (list buf) into elements
finally return elements)))
@@ -245,33 +245,31 @@ START and END signify the region delimiters."
"\n\n```" (gptel--strip-mode-suffix (buffer-local-value
'major-mode buffer))
"\n")
- (cl-loop for context in contexts do
- (progn
- (let* ((start (overlay-start context))
- (end (overlay-end context)))
- (let (lineno column)
- (with-current-buffer buffer
- (setq lineno (line-number-at-pos start t))
- (setq column (save-excursion
- (goto-char start)
- (current-column))))
- ;; We do not need to insert a line number indicator if we
have two regions
- ;; on the same line, because the previous region should
have already put the
- ;; indicator.
- (unless (= previous-line lineno)
- (unless (= lineno 1)
- (unless is-top-snippet
- (insert "\n"))
- (insert (format "... (Line %d)\n" lineno))))
- (setq previous-line lineno)
- (unless (zerop column)
- (insert " ..."))
- (if is-top-snippet
- (setq is-top-snippet nil)
- (unless (= previous-line lineno)
- (insert "\n"))))
- (insert-buffer-substring-no-properties
- buffer start end))))
+ (dolist (context contexts)
+ (let* ((start (overlay-start context))
+ (end (overlay-end context))
+ content)
+ (let (lineno column)
+ (with-current-buffer buffer
+ (without-restriction
+ (setq lineno (line-number-at-pos start t)
+ column (save-excursion (goto-char start)
+ (current-column))
+ content (buffer-substring-no-properties start end))))
+ ;; We do not need to insert a line number indicator if we have two
regions
+ ;; on the same line, because the previous region should have
already put the
+ ;; indicator.
+ (unless (= previous-line lineno)
+ (unless (= lineno 1)
+ (unless is-top-snippet
+ (insert "\n"))
+ (insert (format "... (Line %d)\n" lineno))))
+ (setq previous-line lineno)
+ (unless (zerop column) (insert " ..."))
+ (if is-top-snippet
+ (setq is-top-snippet nil)
+ (unless (= previous-line lineno) (insert "\n"))))
+ (insert content)))
(unless (>= (overlay-end (car (last contexts))) (point-max))
(insert "\n..."))
(insert "\n```")))
- [nongnu] elpa/gptel updated (44780a408a -> df0b424ea1), ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel ef9684206a 01/20: gptel-context: Add contexter, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel b10cd98e07 02/20: gptel-context: Implement DWIM features, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 382b409176 03/20: gptel-transient: Simplify context buffer, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel f6306b5b15 08/20: gptel-transient: Update menu for context actions, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 5d093f2135 10/20: gptel-context: Support for files as context, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 0787592609 12/20: gptel-context: Fix context deletion overlay bug, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 0abaefed38 13/20: gptel-context: Fix narrowing bug when inserting context,
ELPA Syncer <=
- [nongnu] elpa/gptel c81284479f 18/20: gptel-transient: Move context items around, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 883b5e608a 17/20: gptel-context: Extra newlines before separator-line, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel df0b424ea1 20/20: gptel-ollama: Add num_ctx option, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel ef44164614 19/20: README: Update for context features, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 56f9fc5e72 04/20: gptel-transient: Make gptel-lisp-variable more flexible, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel cbb49f92d3 05/20: gptel-context: Add gptel-context--wrap, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 2b1dbf77b1 09/20: gptel-context: Make overlays front/rear-advance, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 70e3053c42 14/20: gptel-context: Clean up context buffer setup, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 8838f88950 06/20: gptel: Add gptel--strip-mode-suffix, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 31aa385a9d 07/20: gptel-context: Invert dependency, rename contexter and lint, ELPA Syncer, 2024/06/23