Skip to content

fix: resolve byte-compile warnings - #571

Open
dannywillems wants to merge 8 commits into
noctuid:masterfrom
dannywillems-fork:fix/byte-compile-warnings
Open

fix: resolve byte-compile warnings#571
dannywillems wants to merge 8 commits into
noctuid:masterfrom
dannywillems-fork:fix/byte-compile-warnings

Conversation

@dannywillems

Copy link
Copy Markdown

This pull request resolves the behaviour-preserving byte-compile
warnings emitted by general.el on recent Emacs versions. Each warning
type is addressed in its own commit, and a CI workflow is added.

Fixes

  • Unescaped single quotes in docstrings: escape leading single
    quotes with \=' so they render as intended and no longer trigger
    warnings. This also covers the docstrings generated by the
    general-create-definer macro, whose interpolated quoted defaults
    (for example :states 'insert) were flagged. The generated text
    renders identically in help buffers.
  • Docstring line wider than 80 characters: reflow the docstring of
    general--parse-def without changing wording.
  • More than one doc string: in general-predicate-dispatch, the
    (declare (indent 1)) form preceded the docstring, so the compiler
    treated the docstring as a second one. Move declare after the
    docstring; the indent declaration is still applied.
  • Function not known to be defined: add declare-function
    declarations for functions defined inside the
    general-with-eval-after-load use-package block and for the state
    definers created at runtime by general-evil-setup. These are
    compiler hints only and do not change runtime behaviour.

CI

Add a byte-compile workflow that byte-compiles and loads general.el
on Emacs 28.2, 29.4, 30.1, and snapshot (installing the optional evil
and use-package dependencies). It does not use warnings-as-errors
because some warnings remain that cannot be fixed without changing
behaviour or raising the minimum supported Emacs version. A dependabot
configuration is added for the GitHub Actions.

Residual warnings (intentionally left out of scope)

  • in define-widget for general-alist: 'or' is not a valid type
    (line 162): changing the :type widget from or to choice would
    alter the custom widget, which is a behaviour change.
  • cl-gensym is an obsolete function ... use gensym instead (two
    occurrences): plain gensym was only added to core in Emacs 26.1,
    but the declared minimum is Emacs 24.4. Replacing cl-gensym would
    raise the minimum supported version, so it is left unchanged.

The byte-compiler in recent Emacs versions warns when a docstring
contains a leading single quote that it cannot interpret as part of a
`...' quoting pair. Escape these quotes with \=' so they render as
intended in help buffers and no longer trigger warnings.

For the docstrings generated by the `general-create-definer' macro, the
quoted defaults (for example, :states 'insert) were interpolated
verbatim. Escape leading single quotes in the formatted defaults string
so the generated docstrings are also warning-free. This does not change
how the text renders in the help buffer.
The docstring of `general--parse-def' had a line wider than the 80
character limit enforced by the byte-compiler. Rewrap it without
changing the wording.
The `(declare (indent 1))' form preceded the docstring in
`general-predicate-dispatch', so the byte-compiler treated the following
string as a second doc string and warned. Move the declare form after
the docstring, which is the expected position. The indent declaration is
still applied.
Several functions are defined either inside a `general-with-eval-after-load'
block (the use-package integration handlers) or at runtime by
`general-evil-setup' via `general-create-definer' (general-imap and the
other state definers). Because the byte-compiler does not see these
definitions as top-level forms, it warned that the functions were not
known to be defined where they are referenced.

Add `declare-function' declarations for these functions. The
declarations only inform the byte-compiler and do not change runtime
behaviour; the functions are still defined exactly as before.
Add a dedicated workflow that byte-compiles and loads general.el on
Emacs 28.2, 29.4, 30.1, and the snapshot build, installing the optional
evil and use-package dependencies first. The build does not treat
warnings as errors because general.el still emits a small number of
warnings that cannot be fixed without changing behaviour or raising the
minimum supported Emacs version.

Also add a dependabot configuration to keep the GitHub Actions used by
the workflows up to date.
@dannywillems

Copy link
Copy Markdown
Author

This is an automated effort to help maintaining packages in the Emacs community. See https://x.com/dwillems42/status/2060720730338185699 and https://dannywillems.github.io/emacs-package-maintenance/

The :key-type of the general-alist widget used (or symbol (repeat
symbol)), but or is not a valid widget type. The byte-compiler reported
"in define-widget for general-alist: or is not a valid type", and the
widget would error if ever instantiated. The widget type that expresses
"a symbol or a list of symbols" is choice, so replace or with choice.
This is behaviour-preserving: the previous form was never a usable
widget type.
cl-gensym is obsolete as of Emacs 31.1 (use gensym instead), which the
byte-compiler reports for the two call sites in general-define-key and
general-key-dispatch. The built-in gensym has existed since Emacs 26.1,
but the package declares a 24.4 minimum, so a blind replacement would
break on 24.4 and 25.x.

Add a general--gensym defalias that resolves to gensym when available
and falls back to cl-gensym only on Emacs older than 26.1. The fallback
reference is wrapped in with-suppressed-warnings so the obsolete warning
does not fire on Emacs 31.1+ (which always provide gensym and never take
that branch). Behaviour is unchanged: both produce a fresh uninterned
symbol from the same prefix.
Now that the residual byte-compile warnings are resolved, enable
byte-compile-error-on-warn so the byte-compile workflow fails on any new
warning across the matrix (Emacs 28.2, 29.4, 30.1, snapshot). The
optional integration dependencies (evil, use-package) are already
installed before compilation so their symbols are known to the
byte-compiler.
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.

1 participant