[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/bug-2034 1520990: Support mode line constructs for 'mo
From: |
Phil |
Subject: |
[Emacs-diffs] fix/bug-2034 1520990: Support mode line constructs for 'mode-name' in c-mode (bug#2034) |
Date: |
Tue, 3 Jul 2018 07:41:28 -0400 (EDT) |
branch: fix/bug-2034
commit 1520990fbb0347ae981d0032cc20d721d851fb25
Author: Phil Sainty <address@hidden>
Commit: Phil Sainty <address@hidden>
Support mode line constructs for 'mode-name' in c-mode (bug#2034)
Also make the inclusion of minor mode flags in 'mode-name' optional.
* cc-cmds.el (c-modeline-flags): New variable.
(c-modeline-display-flags): New user option.
(c-update-modeline): Use them. Use mode line constructs, rather than
string concatenation, to optionally include minor mode flags in
'mode-name'.
* etc/NEWS: Mention new user option and behaviors.
* doc/misc/cc-mode.texi: Document 'c-modeline-display-flags'.
---
doc/misc/cc-mode.texi | 4 +++
etc/NEWS | 12 +++++++++
lisp/progmodes/cc-cmds.el | 65 ++++++++++++++++++++++++++++++-----------------
3 files changed, 57 insertions(+), 24 deletions(-)
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index 5a229c1..4dc33cb 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -1179,6 +1179,7 @@ you initialize a buffer, the comment style is set to the
default for
the major mode, electric mode and syntactic-indentation mode are
enabled, but the other three modes are disabled.
address@hidden c-modeline-display-flags
@ccmode{} displays the current state of the first five of these minor
modes on the mode line by appending characters to the major mode's
name: @samp{/} or @samp{*} to indicate the comment style (respectively
@@ -1190,6 +1191,9 @@ you'd see @samp{C/address@hidden @samp{C} would be
replaced with
the name of the language in question for the other languages @ccmode{}
supports.}.
+If you do not wish these minor mode states to be displayed, set the
+user option @code{c-modeline-display-flags} to @code{nil}.
+
Here are the commands to toggle these modes:
@table @asis
diff --git a/etc/NEWS b/etc/NEWS
index c92ee6e..e2ae500 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -525,6 +525,18 @@ It was obsolete since Emacs 22.1, replaced by customize.
Use of built-in libgnutls based functionality (described in the Emacs
GnuTLS manual) is recommended instead.
+** CC mode
+
++++
+*** The user option 'c-modeline-display-flags' allows hiding the
+sequence of minor mode indicator characters which are otherwise
+appended to 'mode-name' in the mode line (and elsewhere).
+
+---
+*** 'mode-name' is no longer required to be a string. The function
+'c-update-modeline' now uses mode line constructs to append the minor
+mode flags to 'mode-name'.
+
** Message
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 31cf0b1..10e7440 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -258,31 +258,48 @@ With universal argument, inserts the analysis as a
comment on that line."
(defvar c-block-comment-flag nil)
(make-variable-buffer-local 'c-block-comment-flag)
+(defcustom c-modeline-display-flags t
+ "If non-nil, `mode-name' includes indicators for certain minor modes.
+
+See Info node `(ccmode) Minor Modes'.
+
+These flags are set by `c-update-modeline'."
+ :type 'boolean
+ :version "27.1"
+ :group 'c)
+
+(defvar-local c-modeline-flags nil
+ "Minor mode indicators to be appended to `mode-name'.
+
+See Info node `(ccmode) Minor Modes'.
+
+The flags are hidden when `c-modeline-display-flags' is nil.
+
+If the default value of `c-modeline-flags' is made non-nil,
+`c-update-modeline' will not add the constructs to `mode-name'
+necessary for displaying the flags.")
+
(defun c-update-modeline ()
- (let ((fmt (format "/%s%s%s%s%s"
- (if c-block-comment-flag "*" "/")
- (if c-electric-flag "l" "")
- (if (and c-electric-flag c-auto-newline)
- "a" "")
- (if c-hungry-delete-key "h" "")
- (if (and
- ;; (cc-)subword might not be loaded.
- (boundp 'c-subword-mode)
- (symbol-value 'c-subword-mode))
- ;; FIXME: subword-mode already comes with its
- ;; own lighter!
- "w"
- "")))
- ;; FIXME: Derived modes might want to use something else
- ;; than a string for `mode-name'.
- (bare-mode-name (if (string-match "\\(^[^/]*\\)/" mode-name)
- (match-string 1 mode-name)
- mode-name)))
- (setq mode-name
- (if (> (length fmt) 1)
- (concat bare-mode-name fmt)
- bare-mode-name))
- (force-mode-line-update)))
+ "Update `c-modeline-flags' and append to `mode-name'."
+ (unless c-modeline-flags
+ (setq mode-name (list "" mode-name (list 'c-modeline-display-flags
+ 'c-modeline-flags))))
+ (setq c-modeline-flags
+ (format "/%s%s%s%s%s"
+ (if c-block-comment-flag "*" "/")
+ (if c-electric-flag "l" "")
+ (if (and c-electric-flag c-auto-newline)
+ "a" "")
+ (if c-hungry-delete-key "h" "")
+ (if (and
+ ;; (cc-)subword might not be loaded.
+ (boundp 'c-subword-mode)
+ (symbol-value 'c-subword-mode))
+ ;; FIXME: subword-mode already comes with its
+ ;; own lighter!
+ "w"
+ "")))
+ (force-mode-line-update))
(defun c-toggle-syntactic-indentation (&optional arg)
"Toggle syntactic indentation.