@@ -371,11 +371,19 @@ START and END signify the region delimiters."
371371 else collect (list buf) into elements
372372 finally return elements)))
373373
374+ (defun gptel-context--format-buffer-name (buffer )
375+ " Format buffer name with file path if applicable."
376+ (let ((buffer-name (buffer-name buffer))
377+ (file-name (buffer-file-name buffer)))
378+ (if file-name
379+ (format " %s (%s )" buffer-name (abbreviate-file-name file-name))
380+ buffer-name)))
381+
374382(defun gptel-context--insert-buffer-string (buffer contexts )
375383 " Insert at point a context string from all CONTEXTS in BUFFER."
376384 (let ((is-top-snippet t )
377385 (previous-line 1 ))
378- (insert (format " In buffer `%s `: " (buffer-name buffer))
386+ (insert (format " In buffer `%s `: " (gptel-context--format- buffer-name buffer))
379387 " \n\n ```" (gptel--strip-mode-suffix (buffer-local-value
380388 'major-mode buffer))
381389 " \n " )
@@ -410,7 +418,7 @@ START and END signify the region delimiters."
410418
411419(defun gptel-context--insert-file-string (path )
412420 " Insert at point the contents of the file at PATH as context."
413- (insert (format " In file `%s `: " path)
421+ (insert (format " In file `%s `: " ( abbreviate-file-name path) )
414422 " \n\n ```\n " )
415423 (insert-file-contents path)
416424 (goto-char (point-max ))
@@ -481,7 +489,7 @@ context overlays, see `gptel-context--alist'."
481489 (setq l1 (line-number-at-pos (overlay-start source-ov))
482490 l2 (line-number-at-pos (overlay-end source-ov))))
483491 (insert (propertize (format " In buffer %s (lines %d -%d ):\n\n "
484- (buffer-name buf) l1 l2)
492+ (gptel-context--format- buffer-name buf) l1 l2)
485493 'face 'bold ))
486494 (setq beg (point ))
487495 (insert-buffer-substring
@@ -493,7 +501,7 @@ context overlays, see `gptel-context--alist'."
493501 (overlay-put ov 'evaporate t )
494502 (insert " \n " (make-separator-line) " \n " ))
495503 ; ; BUF is a file path, not a buffer
496- (insert (propertize (format " In file %s :\n\n " buf)
504+ (insert (propertize (format " In file %s :\n\n " ( file-name-nondirectory buf) )
497505 'face 'bold ))
498506 (setq beg (point ))
499507 (if-let* ((mime (plist-get ovs :mime )))
0 commit comments