Also make the inclusion of minor mode flags in 'mode-name' optional.
* lisp/progmodes/cc-vars.el (c-modeline-display-flags): New user
option.
* lisp/progmodes/cc-cmds.el (c-modeline-flags): New variable.
(c--modeline-major-mode): New internal buffer-local variable.
(c-update-modeline): Use mode line constructs, rather than string
concatenation, to optionally include minor mode flags in 'mode-name'.
* lisp/progmodes/cc-cmds.el (c-toggle-auto-newline)
(c-toggle-hungry-state, c-toggle-auto-hungry-state)
(c-toggle-electric-state, c-toggle-comment-style):
* lisp/progmodes/cc-mode.el (c-electric-indent-mode-hook)
(c-electric-indent-local-mode-hook): Remove redundant calls to
'c-update-modeline'. It is no longer necessary to call this function
every time one of the minor mode states changes. The remaining calls
are in 'c-basic-common-init' (which is called via 'c-common-init' by
all the major modes defined in cc-mode.el), and in the :after-hook of
those modes (which ensures that 'mode-name' is still processed for a
derived mode that doesn't call 'c-common-init' itself).
* lisp/progmodes/cc-mode.el (c-submit-bug-report):
* lisp/progmodes/cc-styles.el (c-set-style): Format 'mode-name'.
* doc/misc/cc-mode.texi: Document 'c-modeline-display-flags'.
* etc/NEWS: Mention new user option and behaviors.
* lisp/progmodes/cc-engine.el:
* lisp/progmodes/cc-mode.el: Remove commented remnants of
'c-submode-indicators'. This code was commented out in commit
cb694ab73063cc92342daf96d009cdc6d086bc0b in which the indicators were
moved directly into 'mode-name' (to prevent lighter text for other
minor modes from appearing inbetween). These indicators are now
replaced by 'c-modeline-flags'.
the major mode, electric mode and syntactic-indentation mode are
enabled, but the other three modes are disabled.
-@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
-line or block), and one letter for each of the other minor modes which
-is enabled - @samp{l} for electric mode, @samp{a} for auto-newline
-mode, @samp{h} for hungry delete mode, and @samp{w} for subword mode.
-If the comment style was block and all the other modes were enabled,
-you'd see @samp{C/*lahw}@footnote{The @samp{C} would be replaced with
-the name of the language in question for the other languages @ccmode{}
-supports.}.
+@ccmode{}, by default, 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 line or block), and one letter for each of the other
+minor modes which is enabled - @samp{l} for electric mode, @samp{a}
+for auto-newline mode, @samp{h} for hungry delete mode, and @samp{w}
+for subword mode. If the comment style was block and all the other
+modes were enabled, you'd see @samp{C/*lahw}@footnote{The @samp{C}
+would be replaced with the name of the language in question for the
+other languages @ccmode{} supports.}.
+
+@vindex c-modeline-display-flags
+@vindex modeline-display-flags @r{(c-)}
+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:
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'.
\f
** Message
(defvar c-block-comment-flag nil)
(make-variable-buffer-local 'c-block-comment-flag)
+(defvar c-modeline-flags
+ '(c-modeline-display-flags
+ ("/"
+ (c-block-comment-flag "*" "/")
+ (c-electric-flag ("l" (c-auto-newline "a")))
+ (c-hungry-delete-key "h")
+ ;; FIXME: subword-mode already comes with its own lighter!
+ (c-subword-mode "w")))
+ "A mode line construct to indicate the enabled minor modes.
+
+See Info node `(ccmode) Minor Modes'.
+
+The flags are hidden when `c-modeline-display-flags' is nil.
+
+This construct is added to `mode-name' by `c-update-modeline'.")
+
+(defvar-local c--modeline-major-mode nil
+ "The last major mode processed by `c-update-modeline'.
+
+Internal use only.
+
+If the value of `major-mode' is not a match for this buffer-
+local value, then a new mode has been invoked (e.g. a derived
+mode of the previous value seen). That in turn means that
+`mode-name' has been reset by the new major mode body, and it
+needs to be 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)))
+ "Add `c-modeline-flags' to `mode-name', if not already done.
+
+This is called from `c-basic-common-init' and should also be
+invoked via the :after-hook of the major mode. The hook ensures
+that this function is still called for derived modes which don't
+call `c-basic-common-init'."
+ (unless (eq major-mode c--modeline-major-mode)
+ (setq mode-name (list mode-name 'c-modeline-flags))
+ (unless (stringp (car mode-name))
+ (push "" mode-name))
+ (setq c--modeline-major-mode major-mode))
+ (force-mode-line-update))
(defun c-toggle-syntactic-indentation (&optional arg)
"Toggle syntactic indentation.
(setq c-auto-newline
(c-calculate-state arg (and c-auto-newline c-electric-flag)))
(if c-auto-newline (setq c-electric-flag t))
- (c-update-modeline)
(c-keep-region-active))
(defalias 'c-toggle-auto-state 'c-toggle-auto-newline)
whitespace in one fell swoop."
(interactive "P")
(setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
- (c-update-modeline)
(c-keep-region-active))
(defun c-toggle-auto-hungry-state (&optional arg)
(interactive "P")
(setq c-auto-newline (c-calculate-state arg c-auto-newline))
(setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
- (c-update-modeline)
(c-keep-region-active))
(defun c-toggle-electric-state (&optional arg)
left out."
(interactive "P")
(setq c-electric-flag (c-calculate-state arg c-electric-flag))
- (c-update-modeline)
(when (fboundp 'electric-indent-local-mode) ; Emacs 24.4 or later.
(electric-indent-local-mode (if c-electric-flag 1 0)))
(c-keep-region-active))
(if c-block-comment-flag
(concat " " c-block-comment-ender)
""))
- (c-update-modeline)
(c-keep-region-active))
\f
(defvar c-auto-newline nil)
(make-variable-buffer-local 'c-auto-newline)
-;; Included in the mode line to indicate the active submodes.
-;; (defvar c-submode-indicators nil)
-;; (make-variable-buffer-local 'c-submode-indicators)
-
(defun c-calculate-state (arg prevstate)
;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
;; arg is nil or zero, toggle the state. If arg is negative, turn
(when (fboundp 'electric-indent-local-mode)
(setq c-electric-flag electric-indent-mode))
-;; ;; Put submode indicators onto minor-mode-alist, but only once.
-;; (or (assq 'c-submode-indicators minor-mode-alist)
-;; (setq minor-mode-alist
-;; (cons '(c-submode-indicators c-submode-indicators)
-;; minor-mode-alist)))
+ ;; Add minor mode flags to `mode-name'.
(c-update-modeline)
;; Install the functions that ensure that various internal caches
(with-current-buffer buf
(when c-buffer-is-cc-mode
;; Don't use `c-toggle-electric-state' here due to recursion.
- (setq c-electric-flag electric-indent-mode)
- (c-update-modeline))))
+ (setq c-electric-flag electric-indent-mode))))
(buffer-list)))
(defun c-electric-indent-local-mode-hook ()
;; Emacs has en/disabled `electric-indent-local-mode' for this buffer.
;; Propagate this through to this buffer's value of `c-electric-flag'
(when c-buffer-is-cc-mode
- (setq c-electric-flag electric-indent-mode)
- (c-update-modeline)))
+ (setq c-electric-flag electric-indent-mode)))
\f
;; Support for C
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
(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))))
(copy-sequence c-noise-macro-names))
(t (error "c-make-noise-macro-regexps: \
c-noise-macro-names is invalid: %s" c-noise-macro-names)))))
+
+(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 defined by `c-modeline-flags'."
+ :version "27.1"
+ :type 'boolean
+ :group 'c)
\f
;; Non-customizable variables, still part of the interface to CC Mode
(defvar c-macro-with-semi-re nil