[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/bug-2034 d22274b: Support mode line constructs for 'mo
From: |
Phil |
Subject: |
[Emacs-diffs] fix/bug-2034 d22274b: Support mode line constructs for 'mode-name' in c-mode (bug#2034) |
Date: |
Tue, 3 Jul 2018 09:26:50 -0400 (EDT) |
branch: fix/bug-2034
commit d22274b5c67fc82611354dc8079fd43eca574e92
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.
* lisp/progmodes/cc-cmds.el (c-modeline-flags): New variable.
(c-modeline-flags-major-modes-processed): 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'.
* lisp/progmodes/cc-mode.el (c-submit-bug-report): Format 'mode-name'.
* lisp/progmodes/cc-styles.el (c-set-style): Format '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 | 13 +++++++++
lisp/progmodes/cc-cmds.el | 71 ++++++++++++++++++++++++++++++---------------
lisp/progmodes/cc-mode.el | 2 +-
lisp/progmodes/cc-styles.el | 2 +-
5 files changed, 66 insertions(+), 26 deletions(-)
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index 5a229c1..9b7ed69 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -1190,6 +1190,10 @@ 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.}.
address@hidden c-modeline-display-flags
+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..7c64925 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -525,6 +525,19 @@ 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 characters indicating the states of various minor modes,
+which by default are 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..4f21254 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -258,31 +258,54 @@ 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.")
+
+(defvar-local c-modeline-flags-major-modes-processed nil
+ "Major modes for which `c-update-modeline' has processed `mode-name'.
+
+Needed to ensure that derived modes are processed.")
+
(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'."
+ ;; Add additional mode line constructs to `mode-name'.
+ (unless (memq major-mode c-modeline-flags-major-modes-processed)
+ (setq mode-name (list mode-name (list 'c-modeline-display-flags
+ 'c-modeline-flags)))
+ (unless (stringp (car mode-name))
+ (push "" mode-name))
+ (push major-mode c-modeline-flags-major-modes-processed))
+ ;; Generate the minor mode 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.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index f09ca04..8a960f1 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2521,7 +2521,7 @@ Key bindings:
t (message "") nil)
(reporter-submit-bug-report
c-mode-help-address
- (concat "CC Mode " c-version " (" mode-name ")")
+ (concat "CC Mode " c-version " (" (format-mode-line mode-name) ")")
(let ((vars (append
c-style-variables
'(c-buffer-is-cc-mode
diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el
index a1f3261..1f5258b 100644
--- a/lisp/progmodes/cc-styles.el
+++ b/lisp/progmodes/cc-styles.el
@@ -365,7 +365,7 @@ a null operation."
(interactive
(list (let ((completion-ignore-case t)
(prompt (format "Which %s indentation style? "
- mode-name)))
+ (format-mode-line mode-name))))
(completing-read prompt c-style-alist nil t nil
'c-set-style-history
c-indentation-style))))