Only in /var/lib/copr-rpmbuild/results/ripgrep-edit/upstream-unpacked/Source0/ripgrep-edit-0.3.16: .distro diff -U2 -r /var/lib/copr-rpmbuild/results/ripgrep-edit/upstream-unpacked/Source0/ripgrep-edit-0.3.16/emacs/rg-edit.el /var/lib/copr-rpmbuild/results/ripgrep-edit/srpm-unpacked/ripgrep-edit-0.3.16.tar.gz-extract/ripgrep-edit-0.3.16/emacs/rg-edit.el --- /var/lib/copr-rpmbuild/results/ripgrep-edit/upstream-unpacked/Source0/ripgrep-edit-0.3.16/emacs/rg-edit.el 2026-05-28 15:42:35.000000000 +0000 +++ /var/lib/copr-rpmbuild/results/ripgrep-edit/srpm-unpacked/ripgrep-edit-0.3.16.tar.gz-extract/ripgrep-edit-0.3.16/emacs/rg-edit.el 2026-06-14 21:07:19.000000000 +0000 @@ -86,10 +86,18 @@ (use-local-map map))) (insert "C-c C-k on this buffer will close it and terminate any outstanding rg-edit session\n\n") - (when (and (fboundp 'gptel--model-capable-p) - (gptel--model-capable-p 'gbnf)) + (when (rg-edit--gptel-gbnf-enabled-p) (insert "GBNF Grammar Enabled\n\n")) (with-current-buffer rg-buffer (visual-line-mode))) +(defun rg-edit--gptel-gbnf-enabled-p () + "Return non-nil if at least one configured gptel backend supports GBNF." + (when (fboundp 'gptel--model-capable-p) + (cl-loop for backend-entry in gptel--known-backends + for backend-value = (cdr backend-entry) + if (gptel-backend-p backend-value) + if (gptel--model-capable-p 'gbnf (intern (car backend-entry))) + return t))) + (defun rg-edit--run-command (regexp path extra-args) "Run rg-edit with REGEXP, PATH, and EXTRA-ARGS." @@ -97,6 +105,5 @@ (dir-name (file-name-nondirectory path-dir)) (rg-buffer (get-buffer-create "*rg-edit*" t)) - (gbnf (when (and (fboundp 'gptel--model-capable-p) - (gptel--model-capable-p 'gbnf)) + (gbnf (when (rg-edit--gptel-gbnf-enabled-p) "--gbnf")) (extra-args (concat gbnf @@ -221,7 +228,6 @@ (defun rg-edit--gbnf () - "Read the .gbnf file and inject its contents into the JSON as the 'gbnf' field." - (when (and (fboundp 'gptel--model-capable-p) - (gptel--model-capable-p 'gbnf)) + "Read the .gbnf file and inject its contents into the JSON as the 'grammar' field." + (when (rg-edit--gptel-gbnf-enabled-p) (when-let* ((buffer-file (buffer-file-name)) (gbnf-path (concat buffer-file ".gbnf")) @@ -231,7 +237,14 @@ (buffer-string))))) (when gbnf-content + (add-hook 'gptel-prompt-transform-functions #'rg-edit--gptel-clear-gbnf) (setq-local gptel--request-params (plist-put gptel--request-params :grammar gbnf-content)))))) +(defun rg-edit--gptel-clear-gbnf () + "If the model doesn't support GBNF, clear the grammar from the request." + (unless (and (fboundp 'gptel--model-capable-p) + (gptel--model-capable-p 'gbnf)) + (cl-remf gptel--request-params :grammar))) + (defun rg-edit--commit () "Commit changes made in the rg-edit buffer."