Add a new buffer-local variable `minor-modes'

* lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Keep
`minor-modes' updated.
* src/buffer.c (bset_minor_modes, Fmake_indirect_buffer)
(reset_buffer, init_buffer_once): Initialise `minor-modes'.
(syms_of_buffer): Add `minor-modes' as a new permanently-local
variable.

* src/buffer.h (struct buffer): Add minor_modes_.
This commit is contained in:
Lars Ingebrigtsen 2021-02-14 12:37:44 +01:00
parent 103039b06c
commit 760910f491
5 changed files with 30 additions and 0 deletions

View file

@ -1454,6 +1454,11 @@ used only with Diff mode.
other minor modes in effect. It should be possible to activate and
deactivate minor modes in any order.
@defvar minor-modes
This buffer-local variable lists the currently enabled minor modes in
the current buffer, and is a list if symbols.
@end defvar
@defvar minor-mode-list
The value of this variable is a list of all minor mode commands.
@end defvar

View file

@ -2266,6 +2266,11 @@ back in Emacs 23.1. The affected functions are: 'make-obsolete',
* Lisp Changes in Emacs 28.1
+++
** New buffer-local variable 'minor-modes'.
This permanently buffer-local variable holds a list of currently
enabled minor modes in the current buffer (as a list of symbols).
** The 'values' variable is now obsolete.
---

View file

@ -317,6 +317,10 @@ or call the function `%s'."))))
nil)
(t
t)))
;; Keep `minor-modes' up to date.
(setq minor-modes (delq ',modefun minor-modes))
(when ,getter
(push ',modefun minor-modes))
,@body
;; The on/off hooks are here for backward compatibility only.
(run-hooks ',hook (if ,getter ',hook-on ',hook-off))

View file

@ -292,6 +292,11 @@ bset_major_mode (struct buffer *b, Lisp_Object val)
b->major_mode_ = val;
}
static void
bset_minor_modes (struct buffer *b, Lisp_Object val)
{
b->minor_modes_ = val;
}
static void
bset_mark (struct buffer *b, Lisp_Object val)
{
b->mark_ = val;
@ -893,6 +898,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
bset_file_truename (b, Qnil);
bset_display_count (b, make_fixnum (0));
bset_backed_up (b, Qnil);
bset_minor_modes (b, Qnil);
bset_auto_save_file_name (b, Qnil);
set_buffer_internal_1 (b);
Fset (intern ("buffer-save-without-query"), Qnil);
@ -967,6 +973,7 @@ reset_buffer (register struct buffer *b)
b->clip_changed = 0;
b->prevent_redisplay_optimizations_p = 1;
bset_backed_up (b, Qnil);
bset_minor_modes (b, Qnil);
BUF_AUTOSAVE_MODIFF (b) = 0;
b->auto_save_failure_time = 0;
bset_auto_save_file_name (b, Qnil);
@ -5151,6 +5158,7 @@ init_buffer_once (void)
bset_auto_save_file_name (&buffer_local_flags, make_fixnum (-1));
bset_read_only (&buffer_local_flags, make_fixnum (-1));
bset_major_mode (&buffer_local_flags, make_fixnum (-1));
bset_minor_modes (&buffer_local_flags, make_fixnum (-1));
bset_mode_name (&buffer_local_flags, make_fixnum (-1));
bset_undo_list (&buffer_local_flags, make_fixnum (-1));
bset_mark_active (&buffer_local_flags, make_fixnum (-1));
@ -5617,6 +5625,11 @@ The default value (normally `fundamental-mode') affects new buffers.
A value of nil means to use the current buffer's major mode, provided
it is not marked as "special". */);
DEFVAR_PER_BUFFER ("minor-modes", &BVAR (current_buffer, minor_modes),
Qnil,
doc: /* Minor modes currently active in the current buffer.
This is a list of symbols, or nil if there are no minor modes active. */);
DEFVAR_PER_BUFFER ("mode-name", &BVAR (current_buffer, mode_name),
Qnil,
doc: /* Pretty name of current buffer's major mode.

View file

@ -338,6 +338,9 @@ struct buffer
/* Symbol naming major mode (e.g., lisp-mode). */
Lisp_Object major_mode_;
/* Symbol listing all currently enabled minor modes. */
Lisp_Object minor_modes_;
/* Pretty name of major mode (e.g., "Lisp"). */
Lisp_Object mode_name_;