Skip to content

gptel: Silence byte-compilation warnings#657

Merged
karthink merged 1 commit intokarthink:masterfrom
pabl0:compile-warnings
May 24, 2025
Merged

gptel: Silence byte-compilation warnings#657
karthink merged 1 commit intokarthink:masterfrom
pabl0:compile-warnings

Conversation

@pabl0
Copy link
Copy Markdown
Contributor

@pabl0 pabl0 commented Feb 20, 2025

Silence most low-hanging-fruit byte compilation warnings.

https://gist.github.com/pabl0/b48d221ab50914dc1cbf1196efca82d6

I think these might be real issues needing fixing?

Emacs 29.4:

gptel-rewrite.el:522:10: Warning: ‘gptel--suffix-rewrite’ is for interactive
    use only.
gptel-rewrite.el:529:10: Warning: ‘gptel--suffix-rewrite’ is for interactive
    use only.

Emacs 28.2:

gptel-rewrite.el:365:55: Warning: the function ‘rmc--add-key-description’ is
    not known to be defined.

@karthink
Copy link
Copy Markdown
Owner

Thanks. I think I fixed the gptel-rewrite warnings.

For the rest I would like to figure out why the byte-compiler thinks the docstrings of the gptel-make-* functions are too wide instead of ignoring them. Any idea?

@pabl0
Copy link
Copy Markdown
Contributor Author

pabl0 commented Feb 22, 2025

For the rest I would like to figure out why the byte-compiler thinks the docstrings of the gptel-make-* functions are too wide instead of ignoring them. Any idea?

https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-09/msg00713.html

@pabl0
Copy link
Copy Markdown
Contributor Author

pabl0 commented Feb 22, 2025

Thanks. I think I fixed the gptel-rewrite warnings.

Emacs 28 is lacking the rmc--add-key-description function. Does gptel--rewrite-dispatch work correctly with it just declared but not actually implemented with older emacsen?

gptel/gptel-rewrite.el

Lines 363 to 369 in 5d5610d

(concat
(unless (eq (char-before (overlay-start ov)) ?\n) "\n")
(propertize "REWRITE READY: " 'face 'success)
(mapconcat (lambda (e) (cdr e)) (mapcar #'rmc--add-key-description choices) ", ")
(propertize
" " 'display `(space :align-to (- right ,(1+ (length hint-str)))))
(propertize hint-str 'face 'success)))

@pabl0
Copy link
Copy Markdown
Contributor Author

pabl0 commented Feb 22, 2025

For the rest I would like to figure out why the byte-compiler thinks the docstrings of the gptel-make-* functions are too wide instead of ignoring them. Any idea?

https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-09/msg00713.html

To clarify:

(car (last (split-string (documentation 'gptel-make-azure) "\n" t)))
==> "(fn NAME &key CURL-ARGS HOST (PROTOCOL \"https\") (HEADER (lambda nil `((\"api-key\" \\, (gptel--get-api-key))))) (KEY 'gptel-api-key) MODELS STREAM ENDPOINT REQUEST-PARAMS)"
(length (car (last (split-string (documentation 'gptel-make-azure) "\n" t))))
==> 168

describe-function wraps it nicely, but I don't think the cl-defun macro can wrap the actual docstring stored.

If I set byte-compile-docstring-max-column to 168, it compiles without warnings. Would that be a more suitable option? I don't think it makes much practical difference.

I believe this issue should go away in future versions of Emacs where the internal docstring presentation of macros will be wrapped, if I understand the emacs-devel thread correctly.

@karthink
Copy link
Copy Markdown
Owner

For the rest I would like to figure out why the byte-compiler thinks the docstrings of the gptel-make-* functions are too wide instead of ignoring them. Any idea?

https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-09/msg00713.html

Ah, thanks for the link. That explains it.

The reason I didn't merge it immediately is that I wasn't sure what (not docstrings) does:

  docstrings  docstrings that are too wide (longer than
              `byte-compile-docstring-max-column' or
              `fill-column' characters, whichever is bigger) or
              have other stylistic issues.

What does "other stylistic issues" mean? Is that something we should care about?

@pabl0
Copy link
Copy Markdown
Contributor Author

pabl0 commented Mar 25, 2025

What does "other stylistic issues" mean?  Is that something we should care about?

I'm not entirely sure; it seems that emacs-lisp/checkdoc.el performs a variety of checks, but I'm uncertain which ones are applicable in the context of byte compilation. Naturally, setting the byte-compile-docstring-max-column to a large value would be the safest approach. However, relying on specific numbers may necessitate frequent adjustments.

@karthink
Copy link
Copy Markdown
Owner

karthink commented Apr 19, 2025

I agree with setting byte-compile-docstring-max-column -- let's set it once in .dir-locals instead of in every elisp file, to a value just above that generated by the cl-defstruct macros.

@pabl0
Copy link
Copy Markdown
Contributor Author

pabl0 commented Apr 19, 2025

I don't think setting variables in .dir-locals.el works with byte-compilation.

@karthink
Copy link
Copy Markdown
Owner

I don't think setting variables in .dir-locals.el works with byte-compilation.

I tested it out. Whether it works depends on how byte-compilation is invoked. elisp-byte-compile-buffer copies the buffer to a temporary file (different directory) so it doesn't work. elisp-byte-compile-file respects the value of byte-compile-docstring-max-column in .dir-locals.

So it depends on how each package manager handles it.

@karthink
Copy link
Copy Markdown
Owner

Let's just add it to all the files defining cl-structures, i.e. to all the backend libraries.

@pabl0
Copy link
Copy Markdown
Contributor Author

pabl0 commented Apr 20, 2025

Also, MELPA does not ship the .git-ignore.el file at all (unlike NonGNU-ELPA).

@karthink karthink force-pushed the compile-warnings branch from 3d822ee to 2dfdf96 Compare May 24, 2025 07:12
* gptel-antropic (gptel--anthropic-models): Use URL format recognized
by `describe-variable` in docstring.

* gptel-anthropic.el (gptel-make-anthropic): Silence warnings about
docstring (created by a macro) wider than 80 characters with local
variable.  (See Emacs bug#65790.)

* gptel-kaqi.el (gptel--wrap-user-prompt): Ditto.

* gptel-openai.el: (gptel-make-azure): Ditto.

* gptel-openai-extras.el (gptel-make-perplexity): Ditto.

* gptel-ollama.el (gptel--wrap-user-prompt): Wrap a docstring line to
less than 80 characters.

* gptel-org.el (gptel-org--element-lineage-map): Silence warnings
about `org-element-type-p' and `org-element-parent', see karthink#294.
@karthink karthink force-pushed the compile-warnings branch from 2dfdf96 to 289a5cc Compare May 24, 2025 07:15
@karthink karthink merged commit 289a5cc into karthink:master May 24, 2025
@karthink
Copy link
Copy Markdown
Owner

Thanks for the PR @pabl0!

@pabl0 pabl0 deleted the compile-warnings branch March 24, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants