[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 382b409176 03/20: gptel-transient: Simplify context
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 382b409176 03/20: gptel-transient: Simplify context buffer |
Date: |
Sun, 23 Jun 2024 00:59:52 -0400 (EDT) |
branch: elpa/gptel
commit 382b40917696c963bb35d2ce27ed25185bc199a9
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: karthink <karthikchikmagalur@gmail.com>
gptel-transient: Simplify context buffer
* gptel-transient.el (gptel--suffix-context-buffer): Simplify
definition.
gptel-context.el (gptel-context-buffer-mode,
gptel--context-buffer-setup, gptel--context-buffer-reverse,
gptel--context-post-command, gptel-context-visit,
gptel-context-next, gptel-context-previous,
gptel-context-flag-deletion, gptel-context-quit,
gptel-context-confirm, gptel-context-buffer-mode-map): Add major mode for
context buffers, `gptel-context-buffer-mode`.
gptel-transient.el: Move context buffer setup to
gptel-contexter.el.
---
gptel-contexter.el | 295 ++++++++++++++++++++++++++++++++++++++---------------
gptel-transient.el | 245 ++------------------------------------------
2 files changed, 222 insertions(+), 318 deletions(-)
diff --git a/gptel-contexter.el b/gptel-contexter.el
index 95a6563805..ec2bd30b94 100644
--- a/gptel-contexter.el
+++ b/gptel-contexter.el
@@ -1,5 +1,4 @@
-
-;;; gptel-contexter.el --- Context aggregator for GPTel
+;;; gptel-contexter.el --- Context aggregator for GPTel -*- lexical-binding:
t; -*-
;; Copyright (C) 2023 Karthik Chikmagalur
@@ -64,7 +63,8 @@ If non-nil, then the model will use the context in the chat
buffer."
:group 'gptel
:type 'string)
-(defvar gptel--context-overlays '())
+(defvar gptel--context-overlay-alist nil
+ "Alist of buffers and their corresponding context chunks.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ------------------------------ FUNCTIONS -------------------------------
;;;
@@ -122,7 +122,8 @@ If there is a context under point, it is removed when
called without a prefix."
(overlay-put overlay 'evaporate t)
(overlay-put overlay 'face gptel-context-highlight-face)
(overlay-put overlay 'gptel-context t)
- (push overlay gptel--context-overlays)
+ (push overlay (alist-get (current-buffer)
+ gptel--context-overlay-alist))
overlay))
(defun gptel--wrap-in-context (message)
@@ -168,16 +169,14 @@ The message is usually either a system message or user
prompt."
"Return the list of context overlays in the given region, if any, in BUFFER.
START and END signify the region delimiters."
(with-current-buffer buffer
- (cl-remove-if-not #'(lambda (overlay)
- (overlay-get overlay 'gptel-context))
+ (cl-remove-if-not (lambda (ov) (overlay-get ov 'gptel-context))
(overlays-in start end))))
;;;###autoload
(defun gptel-context-at-point ()
"Return the context overlay at point, if any."
- (car (cl-remove-if-not #'(lambda (ov)
- (overlay-get ov 'gptel-context))
- (overlays-at (point)))))
+ (cl-find-if (lambda (ov) (overlay-get ov 'gptel-context))
+ (overlays-at (point))))
;;;###autoload
(defun gptel-remove-context (&optional context)
@@ -203,11 +202,15 @@ If selection is active, removes all contexts within
selection."
(defun gptel-contexts ()
"Get the list of all active context overlays."
;; Get only the non-degenerate overlays, collect them, and update the
overlays variable.
- (let ((overlays (cl-loop for ov in gptel--context-overlays
- when (overlay-start ov)
- collect ov)))
- (setq gptel--context-overlays overlays)
- overlays))
+ (let ((overlay-alist
+ (cl-loop for (buf . ovs) in gptel--context-overlay-alist
+ when (buffer-live-p buf)
+ for updated-ovs = (cl-loop for ov in ovs
+ when (overlay-start ov)
+ collect ov)
+ when updated-ovs
+ collect (cons buf updated-ovs))))
+ (setq gptel--context-overlay-alist overlay-alist)))
;;;###autoload
(defun gptel-contexts-in-buffer (buffer)
@@ -269,81 +272,213 @@ representthe regions' boundaries within BUFFER."
(curr-line-start (line-number-at-pos (car current-region))))
(= prev-line-end curr-line-start))))
-(defun gptel-buffer-context-string (buffer &optional depropertize)
- "Create a context string from all contexts in BUFFER.
-If DEPROPERTIZE is non-nil, remove the properties from the final substring."
+(defun gptel-buffer-insert-context-string (buffer)
+ "Insert at point a context string from all contexts in BUFFER."
(let ((is-top-snippet t)
- buffer-file
(previous-line 1)
prog-lang-tag
- (contexts (gptel-contexts-in-buffer buffer)))
- (with-current-buffer buffer
- (setq prog-lang-tag (gptel-major-mode-md-prog-lang
- major-mode)))
- (setq buffer-file
- ;; Use file path if buffer has one, otherwise use its regular name.
- (if (buffer-file-name buffer)
- (format "`%s`"
- (buffer-file-name buffer))
- (format "buffer `%s`"
- (buffer-name buffer))))
- (with-temp-buffer
- (insert (format "In %s:" buffer-file))
- (insert "\n\n```" prog-lang-tag "\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.
+ (contexts (alist-get buffer gptel--context-overlay-alist)))
+ (setq prog-lang-tag (gptel-major-mode-md-prog-lang
+ (buffer-local-value 'major-mode buffer)))
+ (insert (format "In buffer `%s`:" (buffer-name buffer)))
+ (insert "\n\n```" prog-lang-tag "\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)
- (unless (= lineno 1)
- (insert (format "\n... (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"))))
- (let (substring)
- (with-current-buffer buffer
- (setq substring (buffer-substring-no-properties
- start end)))
- ;; This text property will allow us to know what overlay
- ;; is associated to which context.
- (put-text-property 0 (length substring)
- 'gptel-context-overlay
- context substring)
- (insert substring)))))
- (unless (>= (overlay-end (car (last contexts))) (point-max))
- (insert "\n..."))
- (insert "\n```")
- (let ((context-snippet (buffer-substring (point-min) (point-max))))
- (when depropertize
- (set-text-properties 0 (length context-snippet) nil
context-snippet))
- context-snippet))))
+ (insert "\n"))))
+ (insert-buffer-substring-no-properties
+ buffer start end))))
+ (unless (>= (overlay-end (car (last contexts))) (point-max))
+ (insert "\n..."))
+ (insert "\n```")))
;;;###autoload
-(defun gptel-context-string (&optional propertize)
+(defun gptel-context-string ()
"Return the context string of all aggregated contexts.
If PROPERTIZE is non-nil, keep the text properties."
(without-restriction
- (let ((context (string-trim-right
- (cl-loop for buffer in
- (delete-dups (mapcar #'overlay-buffer
(gptel-contexts)))
- concat (concat (gptel-buffer-context-string
buffer) "\n\n")))))
- (if propertize
- context
- (set-text-properties 0 (length context) nil context)
- context))))
+ (with-temp-buffer
+ (cl-loop for (buf . ovs) in (gptel-contexts)
+ do (gptel-buffer-insert-context-string buf)
+ (insert "\n\n")
+ finally return (buffer-string)))))
+
+;;; Major mode for context inspection buffers
+(define-derived-mode gptel-context-buffer-mode special-mode "gptel-context"
+ "Major-mode for inspecting context used by gptel."
+ :group 'gptel
+ (add-hook 'post-command-hook #'gptel--context-post-command
+ nil t)
+ (setq-local revert-buffer-function #'gptel--context-buffer-setup))
+
+(defun gptel--context-buffer-setup (&optional _ignore-auto _noconfirm)
+ (with-current-buffer (get-buffer-create "*gptel-context*")
+ (gptel-context-buffer-mode)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (setq header-line-format
+ (concat
+ "Mark/unmark deletion with "
+ (propertize "d" 'face 'help-key-binding)
+ ", jump to next/previous with "
+ (propertize "n" 'face 'help-key-binding)
+ "/"
+ (propertize "p" 'face 'help-key-binding)
+ ", respectively. "
+ (propertize "C-c C-c" 'face 'help-key-binding)
+ " to apply, or "
+ (propertize "C-c C-k" 'face 'help-key-binding)
+ " to abort."))
+ (save-excursion
+ (let ((contexts gptel--context-overlay-alist))
+ (if (length> contexts 0)
+ (let (beg ov l1 l2)
+ (pcase-dolist (`(,buf . ,ovs) contexts)
+ (dolist (source-ov ovs)
+ (with-current-buffer buf
+ (setq l1 (line-number-at-pos (overlay-start source-ov))
+ l2 (line-number-at-pos (overlay-end source-ov))))
+ (insert (make-separator-line)
+ (propertize (format "In buffer %s (lines
%d-%d):\n\n"
+ (buffer-name buf) l1 l2)
+ 'face 'bold))
+ (setq beg (point))
+ (insert-buffer-substring
+ buf (overlay-start source-ov) (overlay-end source-ov))
+ (insert "\n")
+ (setq ov (make-overlay beg (point)))
+ (overlay-put ov 'gptel-context source-ov)
+ (overlay-put ov 'gptel-overlay t)))
+ (goto-char (point-min)))
+ (insert "There are no active contexts in any buffer.")))))
+ (display-buffer (current-buffer)
+ `((display-buffer-reuse-window
+ display-buffer-reuse-mode-window
+ display-buffer-below-selected)
+ (body-function . ,#'select-window)
+ (window-height . ,#'fit-window-to-buffer)))))
+
+(defvar gptel--context-buffer-reverse nil
+ "Last direction of cursor movement in gptel context buffer.
+
+If non-nil, indicates backward movement.")
+
+(defalias 'gptel--context-post-command
+ (let ((highlight-overlay))
+ (lambda ()
+ ;; Only update if point moved outside the current region.
+ (unless (memq highlight-overlay (overlays-at (point)))
+ (let ((context-overlay
+ (cl-loop for ov in (overlays-at (point))
+ thereis (and (overlay-get ov 'gptel-overlay) ov))))
+ (when highlight-overlay
+ (overlay-put highlight-overlay 'face nil))
+ (when context-overlay
+ (overlay-put context-overlay 'face 'highlight))
+ (setq highlight-overlay context-overlay))))))
+
+(defun gptel-context-visit ()
+ (interactive)
+ (let ((ov-here (car (overlays-at (point)))))
+ (if-let* ((orig-ov (overlay-get ov-here 'gptel-context))
+ (buf (overlay-buffer orig-ov))
+ (offset (- (point) (overlay-start ov-here))))
+ (with-selected-window (display-buffer buf)
+ (goto-char (overlay-start orig-ov))
+ (forward-char offset)
+ (recenter))
+ (message "No source location for this context chunk."))))
+
+(defun gptel-context-next ()
+ (interactive)
+ (let ((ov-here (car (overlays-at (point))))
+ (next-start (next-overlay-change (point))))
+ (when (and (/= (point-max) next-start) ov-here)
+ ;; We were inside the overlay, so we want the next overlay change, which
+ ;; would be the start of the next overlay.
+ (setq next-start (next-overlay-change next-start)))
+ (when (/= next-start (point-max))
+ (setq gptel--context-buffer-reverse nil)
+ (goto-char next-start))))
+
+(defun gptel-context-previous ()
+ (interactive)
+ (let ((ov-here (car (overlays-at (point))))
+ (previous-end (previous-overlay-change (point))))
+ (when ov-here (goto-char (overlay-start ov-here)))
+ (goto-char (previous-overlay-change
+ (previous-overlay-change (point))))
+ (setq gptel--context-buffer-reverse t)))
+
+(defun gptel-context-flag-deletion ()
+ (interactive)
+ (let* ((overlays (if (use-region-p)
+ (overlays-in (region-beginning) (region-end))
+ (overlays-at (point))))
+ (deletion-ov)
+ (marked-ovs (cl-remove-if-not (lambda (ov) (overlay-get ov
'gptel-context-deletion-mark))
+ overlays)))
+ (if marked-ovs
+ (mapc #'delete-overlay marked-ovs)
+ (save-excursion
+ (dolist (ov overlays)
+ (goto-char (overlay-start ov))
+ (setq deletion-ov (make-overlay (overlay-start ov) (overlay-end ov)))
+ (overlay-put deletion-ov 'gptel-context (overlay-get ov
'gptel-context))
+ (overlay-put deletion-ov 'priority -80)
+ (overlay-put deletion-ov 'face 'diff-indicator-removed)
+ (overlay-put deletion-ov 'gptel-context-deletion-mark t))))
+ (if (use-region-p)
+ (deactivate-mark)
+ (if gptel--context-buffer-reverse
+ (gptel-context-previous)
+ (gptel-context-next)))))
+
+(defun gptel-context-quit ()
+ (interactive)
+ (quit-window)
+ (call-interactively #'gptel-menu))
+
+(defun gptel-context-confirm ()
+ (interactive)
+ ;; Delete all the context overlays that have been marked for deletion.
+ (mapc #'delete-overlay
+ (delq nil (mapcar (lambda (ov)
+ (and
+ (overlay-get ov 'gptel-context-deletion-mark)
+ (overlay-get ov 'gptel-context)))
+ (overlays-in (point-min) (point-max)))))
+ (gptel-context-quit))
+
+(defvar-keymap gptel-context-buffer-mode-map
+ :parent special-mode-map
+ "C-c C-c" #'gptel-context-confirm
+ "C-c C-k" #'gptel-context-quit
+ "RET" #'gptel-context-visit
+ "n" #'gptel-context-next
+ "p" #'gptel-context-previous
+ "d" #'gptel-context-flag-deletion)
(provide 'gptel-contexter)
;;; gptel-contexter.el ends here.
diff --git a/gptel-transient.el b/gptel-transient.el
index d59f0a07c6..333631ecfe 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -944,254 +944,23 @@ When LOCAL is non-nil, set the system message only in
the current buffer."
:key "-xb"
:description (lambda ()
(let* ((contexts (gptel-contexts))
- (buffer-count (length (delete-dups (mapcar
#'overlay-buffer contexts)))))
+ (buffer-count (length contexts))
+ (ov-count (if (> buffer-count 0)
+ (cl-loop for (_ . ovs) in contexts
+ sum (length ovs))
+ 0)))
(concat "Display context buffer "
(format
(propertize "(%s)" 'face 'transient-delimiter)
(propertize (format "%d context%s in %d buffer%s"
- (length contexts)
- (if (/= (length contexts) 1)
"s" "")
+ ov-count (if (/= ov-count 1)
"s" "")
buffer-count
(if (/= buffer-count 1) "s"
""))
'face (if (zerop (length contexts))
'transient-inactive-value
'transient-value))))))
(interactive)
- (let ((orig-buf (current-buffer))
- (highlight-overlay nil)
- (moved-backwards nil)) ; This is used for some deletion navigation QoL.
- (with-current-buffer (get-buffer-create "*gptel-context*")
- (read-only-mode 1)
- (let ((inhibit-read-only t))
- (erase-buffer)
- (setq header-line-format
- (concat
- "Mark/unmark deletion with "
- (propertize "d" 'face 'help-key-binding)
- ", jump to next/previous with "
- (propertize "n" 'face 'help-key-binding)
- "/"
- (propertize "p" 'face 'help-key-binding)
- ", respectively. "
- (propertize "C-c C-c" 'face 'help-key-binding)
- " to apply, or "
- (propertize "C-c C-k" 'face 'help-key-binding)
- " to abort."))
- (save-excursion
- (let ((contexts (gptel-contexts)))
- (if (> (length contexts) 0)
- (progn
- (insert (gptel-context-string t))
- ;; Mark the inserted context chunks with an overlay to
simplify bookkeeping.
- (goto-char (point-min))
- (while (not (eobp))
- (let* ((beg (next-single-property-change (point)
'gptel-context-overlay))
- (end (when beg
- (next-single-property-change beg
'gptel-context-overlay))))
- (if end
- (progn
- (when (get-text-property beg
'gptel-context-overlay)
- (let ((ov (make-overlay beg end)))
- ;; We want to make the highlighting overlay a
higher priority than
- ;; the deletion overlay. We superimpose both
overlays to have an
- ;; effect that allows for both highlighting
and deletion overlays
- ;; to exist simutaniously for the same context
chunk.
- (overlay-put ov 'priority 1)
- (overlay-put ov 'gptel-context-highlight t)))
- (goto-char end))
- (goto-char (point-max))))))
- (insert "There are no active contexts in any buffer.")))))
- (display-buffer (current-buffer)
- `((display-buffer-below-selected)
- (body-function . ,#'select-window)
- (window-height . ,#'fit-window-to-buffer)))
- ;; Add hook to change the highlight whenever the point has moved beyond
- ;; that of the current highlight.
- (add-hook
- 'post-command-hook
- #'(lambda ()
- ;; Only update if point moved outside the current region.
- (unless (member highlight-overlay (overlays-at (point)))
- (let ((context-overlay (car (cl-loop
- for ov in (overlays-at (point))
- when (overlay-get ov
'gptel-context-highlight)
- collect ov))))
- (when highlight-overlay
- (overlay-put highlight-overlay 'face nil))
- (when context-overlay
- (overlay-put context-overlay 'face 'highlight))
- (setq highlight-overlay context-overlay))))
- nil t)
- (let* ((quit-to-menu
- (lambda ()
- (interactive)
- (local-unset-key (kbd "d"))
- (local-unset-key (kbd "n"))
- (local-unset-key (kbd "p"))
- (local-unset-key (kbd "C-c C-c"))
- (local-unset-key (kbd "C-c C-k"))
- (quit-window)
- (display-buffer
- orig-buf
- `((display-buffer-reuse-window
- display-buffer-use-some-window)
- (body-function . ,#'select-window)))
- (call-interactively #'gptel-menu)))
- ;; Function used to detect whether or not we are at the edges of
an overlay. This is
- ;; used to know how many overlay changes we should jump over in
order to reach the
- ;; start or end of overlays. Refers to inner edge.
- (at-overlay-edge-p #'(lambda (pos left-edge)
- ;; Obviously, if we have no overlay at the
point, we cannot be
- ;; at an edge.
- (when (overlays-at (point))
- (not (if left-edge
- (overlays-at (max (1- pos)
(point-min)))
- (not (overlays-at (min (1+ pos)
(point-max)))))))))
- (move-forward
- #'(lambda ()
- (interactive)
- (let ((point-is-inside-overlay (overlays-at (point)))
- (next-start (next-overlay-change (point))))
- (when (and (/= (point-max) next-start)
point-is-inside-overlay)
- ;; We were inside the overlay, so we want the next
overlay change, which
- ;; would be the start of the next overlay.
- (setq next-start (next-overlay-change next-start)))
- (when (/= next-start (point-max))
- (setq moved-backwards nil)
- (goto-char next-start)))))
- (move-backward
- #'(lambda ()
- (interactive)
- (let ((point-is-inside-overlay (overlays-at (point)))
- (previous-end (previous-overlay-change (point))))
- (when (and (/= (point-min) previous-end)
point-is-inside-overlay
- ;; Handele the edge case where the caret is
located right at the
- ;; beginning of an overlay.
- (overlays-at (max (1- (point)) (point-min))))
- ;; We were inside an overlay, so are currently at the
start of the current
- ;; overlay.
- (setq previous-end (previous-overlay-change
previous-end)))
- (when (/= (point-min) previous-end)
- (setq moved-backwards t)
- (goto-char (1- previous-end)))))))
- (local-set-key (kbd "n") move-forward)
- (local-set-key (kbd "p") move-backward)
- (local-set-key
- (kbd "d") ; Marking overlays for deletion
- #'(lambda ()
- (interactive)
- (if (not (region-active-p)) ; Separate functionality with just
points vs. regions.
- (progn
- (let ((overlays (overlays-at (point)))
- (deletion-overlay-found nil)
- (highlighting-overlay nil)
- (something-marked-or-unmarked nil))
- ;; Loop through all overlays at point to check for
deletion mark or
- ;; highlight.
- (dolist (overlay overlays)
- (cond
- ((overlay-get overlay 'gptel-context-deletion-mark)
- ;; If deletion mark is found, delete the overlay and
set flag to true.
- (delete-overlay overlay)
- (setq something-marked-or-unmarked t)
- (setq deletion-overlay-found t))
- ((overlay-get overlay 'gptel-context-highlight)
- (setq highlighting-overlay overlay))))
- (when (and highlighting-overlay
- (not deletion-overlay-found)
- (overlay-get highlighting-overlay
'gptel-context-highlight))
- (let* ((start (overlay-start highlighting-overlay))
- (end (overlay-end highlighting-overlay))
- (new-overlay (make-overlay start end)))
- ;; We want to have 0 priority so that the
highlighting overlay takes
- ;; precedence.
- (setq something-marked-or-unmarked t)
- (overlay-put new-overlay 'priority 0)
- (overlay-put new-overlay 'face
'diff-indicator-removed)
- (overlay-put new-overlay 'gptel-context-deletion-mark
t)))
- (when something-marked-or-unmarked
- (if moved-backwards
- (progn
- (let ((point (point)))
- (funcall move-backward)
- (when (eq point (point))
- ;; We haven't moved. Disregard previous
movement and just go
- ;; forwards.
- (setq moved-backwards nil)
- (funcall move-forward))))
- (funcall move-forward)))))
- ;; We have a region selected, so we must iterate all the
overlays in it to do the
- ;; same as we have done above.
- (let ((marking-action :mark-all) ; :mark-all, :unmark-all
- (context-region-and-mark '())
- (start (region-beginning))
- (end (region-end))
- (unmarked-context-found nil)
- (highlight-overlay-region-at-point
- #'(lambda ()
- ;; We can't get the overlay, because the hook isn't
triggered, so the
- ;; highlighting overlay won't work when we use
`goto-char'.
- (let ((ov (car (cl-loop for ov in (overlays-at
(point))
- when (overlay-get ov
'gptel-context-highlight)
- collect ov))))
- (cons (overlay-start ov) (overlay-end ov)))))
- (deletion-overlay-at-point
- #'(lambda ()
- (car (cl-loop
- for ov in (overlays-at (point))
- when (overlay-get ov
'gptel-context-deletion-mark)
- collect ov)))))
- (deactivate-mark)
- ;; We want to collect the context regions and see if they
have deletion marks to
- ;; determine what we want to do.
- (save-excursion
- (goto-char start)
- (cl-loop for previous-point = start then (point)
- do (progn
- (let ((hov-region (funcall
highlight-overlay-region-at-point))
- (deletion-ov nil))
- (when hov-region
- (setq deletion-ov (funcall
deletion-overlay-at-point))
- (push (cons hov-region
- deletion-ov)
- context-region-and-mark)
- (unless deletion-ov
- (setq unmarked-context-found t)))
- (funcall move-forward)))
- until (or (= previous-point (point))
- (> (point) end))))
- (unless unmarked-context-found
- (setq marking-action :unmark-all))
- (cl-loop for (hov-region . dov) in context-region-and-mark do
- (if (eq marking-action :mark-all)
- (unless dov ; Do not make a duplicate deletion
overlay.
- (let* ((start (car hov-region))
- (end (cdr hov-region))
- (new-overlay (make-overlay start end)))
- (overlay-put new-overlay 'priority 0)
- (overlay-put new-overlay 'face
'diff-indicator-removed)
- (overlay-put new-overlay
'gptel-context-deletion-mark t)))
- ;; marking-action is :unmark-all.
- (delete-overlay dov)))))))
- (local-set-key (kbd "C-c C-c")
- #'(lambda ()
- (interactive)
- ;; Delete all the context overlays that have been
marked for deletion.
- (cl-loop for dov in
- (cl-loop for ov in (overlays-in
(point-min) (point-max))
- when
- (and (overlay-get ov
'gptel-context-deletion-mark)
- ;; Ignore zero-length
overlays. Not sure why
- ;; these appear at the start
of the buffer.
- (/= (overlay-start ov)
(overlay-end ov)))
- collect ov)
- do (delete-overlay
- ;; The text property from the context
string points to the
- ;; actual context overlay located in
the buffers.
- (get-text-property (overlay-start dov)
-
'gptel-context-overlay)))
- (funcall quit-to-menu)))
- (local-set-key (kbd "C-c C-k") quit-to-menu)))))
+ (gptel--context-buffer-setup))
;; ** Suffixes for rewriting/refactoring
- [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 <=
- [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, 2024/06/23
- [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