Function: gptel-mode

gptel-mode is an interactive and natively compiled function defined in gptel.el.

Signature

(gptel-mode &optional ARG)

Documentation

Minor mode for interacting with LLMs.

This is a minor mode. If called interactively, toggle the GPTel mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable gptel-mode(var)/gptel-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
;;;; Minor mode
;;;###autoload
(define-minor-mode gptel-mode
  "Minor mode for interacting with LLMs."
  :lighter " GPT"
  :keymap
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-c RET") #'gptel-send)
    map)
  (if gptel-mode
      (progn
        (unless (derived-mode-p 'org-mode 'markdown-mode 'text-mode)
          (gptel-mode -1)
          (user-error (format "`gptel-mode' is not supported in `%s'." major-mode)))
        (add-hook 'before-save-hook #'gptel--save-state nil t)
        (add-hook 'after-change-functions 'gptel--inherit-stickiness nil t)
        (gptel--prettify-preset)
        (cond
         ((derived-mode-p 'org-mode)
          (require 'gptel-org)
          (jit-lock-register 'gptel-org--annotate-links)
          ;; Work around bug in `org-fontify-extend-region'.
          (add-hook 'gptel-post-response-functions #'font-lock-flush nil t))
         ((derived-mode-p 'markdown-mode)
          (font-lock-add-keywords ;keymap is a font-lock-managed property in markdown-mode
           nil '(("^```[ \t]*\\([[:alpha:]][^\n]*\\)?$" ;match code fences
                  0 (list 'face nil 'keymap gptel--markdown-block-map))))
          (jit-lock-register 'gptel-markdown--annotate-links)))
        (gptel--restore-state)
        (if gptel-use-header-line
            (progn (setq gptel--old-header-line header-line-format)
                   (gptel-use-header-line))
          (gptel--update-status " Ready" 'success)))
    (remove-hook 'before-save-hook #'gptel--save-state t)
    (remove-hook 'after-change-functions 'gptel--inherit-stickiness t)
    (cond
     ((derived-mode-p 'org-mode)
      (jit-lock-unregister #'gptel-org--annotate-links)
      (without-restriction (gptel--annotate-link-clear)))
     ((derived-mode-p 'markdown-mode)
      (jit-lock-unregister #'gptel-markdown--annotate-links)
      (without-restriction (gptel--annotate-link-clear))))
    (gptel--prettify-preset)
    (if gptel-use-header-line
        (setq header-line-format gptel--old-header-line
              gptel--old-header-line nil)
      (setq mode-line-process nil))))