From 5c056e01838d81213447d3599137845470e9dfec Mon Sep 17 00:00:00 2001
From: Phil Bajsicki <phil@bajsicki.com>
Date: Sat, 24 May 2025 03:48:56 +0200
Subject: [PATCH] Fix open-file-inactive

---
 README.org         | 6 +++---
 gptel-org-tools.el | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/README.org b/README.org
index b54ca7b..09d23f1 100644
--- a/README.org
+++ b/README.org
@@ -296,9 +296,9 @@ Disabled for now, as it's causing some issues.
 Opens a file into an inactive (background) buffer for processing.
 #+begin_src elisp
 (defun gptel-org-tools--open-file-inactive (file)
-  "Open FILE in a buffer."
-  (with-current-buffer (get-buffer-create file)
-    (current-buffer)))
+  "Open FILE in a background buffer without modifying its contents."
+    (find-file-noselect file)
+  (set-buffer-modified-p nil))
 
 (add-to-list 'gptel-org-tools
 	     (gptel-make-tool
diff --git a/gptel-org-tools.el b/gptel-org-tools.el
index eb4bc01..7b69f4e 100644
--- a/gptel-org-tools.el
+++ b/gptel-org-tools.el
@@ -106,9 +106,9 @@
 	      :category "filesystem"))
 
 (defun gptel-org-tools--open-file-inactive (file)
-  "Open FILE in a buffer."
-  (with-current-buffer (get-buffer-create file)
-    (current-buffer)))
+  "Open FILE in a background buffer without modifying its contents."
+    (find-file-noselect file)
+  (set-buffer-modified-p nil))
 
 (add-to-list 'gptel-org-tools
 	     (gptel-make-tool