emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 760910f: Add a new buffer-local variable `minor-modes'


From: Lars Ingebrigtsen
Subject: master 760910f: Add a new buffer-local variable `minor-modes'
Date: Sun, 14 Feb 2021 06:37:56 -0500 (EST)

branch: master
commit 760910f4917ad8ff5e1cd1bf0bfec443b02f0e44
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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_.
---
 doc/lispref/modes.texi        |  5 +++++
 etc/NEWS                      |  5 +++++
 lisp/emacs-lisp/easy-mmode.el |  4 ++++
 src/buffer.c                  | 13 +++++++++++++
 src/buffer.h                  |  3 +++
 5 files changed, 30 insertions(+)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 3c64e97..3a4828c 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index d865aa7..7e224b4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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.
 
 ---
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 2916ae4..bfffbe4 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -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))
diff --git a/src/buffer.c b/src/buffer.c
index 80c799e..487599d 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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.
diff --git a/src/buffer.h b/src/buffer.h
index 790291f..0668d16 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -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_;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]