Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for remapped and aliased modes #9

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

dankessler
Copy link
Contributor

This patch tries to make bind-map aware of two ways in which major modes can be remapped: via aliasing or via major-mode-remap-alist.

The motivating scenario is AUCTeX, which as of version 14.0.1 has renamed several major modes, e.g., latex-mode has been renamed as LaTeX-mode. AUCTeX attempts to offer backwards compatibility using a mix of remapping and aliasing. For users of emacs < 29, latex-mode is redefined as an alias for LaTeX-mode, whereas for users of emacs 29+, latex-mode is remapped to LaTeX-mode using major-mode-remap-alist.

However, if a user had configured keymaps for latex-mode using bind-map, they will not be available in LaTeX-mode. This is especially problematic for distributions like spacemacs which need to support users of both old and new AUCTeX (see syl20bnr/spacemacs#16282 for more discussion).

This patch introduces two new customizable options, bind-map-use-remapped-modes and bind-map-use-aliased-modes. Both options default to t, in which case when bind-map is deciding whether to activate a given keymap, it will compare the value of major-mode to not only the symbol for which the keymap was configured configured (e.g., latex-mode), but any remapped or aliased modes (e.g., '(latex-mode LaTeX-mode). This logic is implemented in the new (private) function bind-map--lookup-major-modes to facilitate lookup of applicable major-modes on the fly. As a result, if a user adjusts major-mode-remap-alist or adjusts aliased, bind-map's behavior will change accordingly.

This patch tries to make `bind-map` aware of two ways in which major modes can
be remapped: via aliasing or via `major-mode-remap-alist`.

The motivating scenario is AUCTeX, which as of version 14.0.1 has renamed
several major modes, e.g., latex-mode has been renamed as LaTeX-mode. AUCTeX
attempts to offer backwards compatibility using a mix of remapping and aliasing.
For users of emacs < 29, `latex-mode` is redefined as an alias for `LaTeX-mode`,
whereas for users of emacs 29+, `latex-mode` is remapped to `LaTeX-mode` using
`major-mode-remap-alist`.

However, if a user had configured keymaps for `latex-mode` using `bind-map`,
they will not be available in `LaTeX-mode`. This is especially problematic for
distributions like `spacemacs` which need to support users of both old and new
AUCTeX (see syl20bnr/spacemacs#16282 for more discussion).

This patch introduces two new customizable options,
`bind-map-use-remapped-modes` and `bind-map-use-aliased-modes`. Both options
default to `t`, in which case when `bind-map` is deciding whether to activate a
given keymap, it will compare the value of `major-mode` to not only the symbol
for which the keymap was configured configured (e.g., `latex-mode`), but any
remapped or aliased modes (e.g., `'(latex-mode LaTeX-mode)`. This logic is
implemented in the new (private) function `bind-map--lookup-major-modes` to
facilitate lookup of applicable major-modes on the fly. As a result, if a user
adjusts `major-mode-remap-alist` or adjusts aliased, `bind-map`'s behavior will
change accordingly.
@justbur
Copy link
Owner

justbur commented Mar 7, 2024

Thanks. It looks ok to me.

@justbur justbur merged commit d0e33d0 into justbur:master Mar 7, 2024
@dankessler
Copy link
Contributor Author

Oh shoot, I used function-alias-p in my PR and it turns out that's only available in emacs 29.1+. This is causing big problems for people using bind-map in earlier versions of emacs. I'll submit a new PR shortly to try to only enable this logic if emacs > 29.1

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.

None yet

2 participants