Skip to content

Commit 22cc86d

Browse files
committed
feat(context): Feed the llm with abbreviated paths for buffers
1 parent ad7e281 commit 22cc86d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gptel-context.el

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,19 @@ START and END signify the region delimiters."
402402
else collect (list buf) into elements
403403
finally return elements)))
404404

405+
(defun gptel-context--format-buffer-name (buffer)
406+
"Format buffer name with file path if applicable."
407+
(let ((buffer-name (buffer-name buffer))
408+
(file-name (buffer-file-name buffer)))
409+
(if file-name
410+
(format "%s (%s)" buffer-name (abbreviate-file-name file-name))
411+
buffer-name)))
412+
405413
(defun gptel-context--insert-buffer-string (buffer contexts)
406414
"Insert at point a context string from all CONTEXTS in BUFFER."
407415
(let ((is-top-snippet t)
408416
(previous-line 1))
409-
(insert (format "In buffer `%s`:" (buffer-name buffer))
417+
(insert (format "In buffer `%s`:" (gptel-context--format-buffer-name buffer))
410418
"\n\n```" (gptel--strip-mode-suffix (buffer-local-value
411419
'major-mode buffer))
412420
"\n")
@@ -504,7 +512,7 @@ context overlays, see `gptel-context--alist'."
504512
(setq l1 (line-number-at-pos (overlay-start source-ov))
505513
l2 (line-number-at-pos (overlay-end source-ov))))
506514
(insert (propertize (format "In buffer %s (lines %d-%d):\n\n"
507-
(buffer-name buf) l1 l2)
515+
(gptel-context--format-buffer-name buf) l1 l2)
508516
'face 'bold))
509517
(setq beg (point))
510518
(insert-buffer-substring

0 commit comments

Comments
 (0)