[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/bug-2034 ce79708 1/3: Support mode line constructs for
From: |
Phil |
Subject: |
[Emacs-diffs] fix/bug-2034 ce79708 1/3: Support mode line constructs for 'mode-name' in c-mode (bug#2034) |
Date: |
Sat, 7 Jul 2018 08:27:31 -0400 (EDT) |
branch: fix/bug-2034
commit ce797083c1b2ba0edffddc43fdcbc71b49f2f109
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-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.
---
doc/misc/cc-mode.texi | 4 +++
etc/NEWS | 12 +++++++++
lisp/progmodes/cc-cmds.el | 66 +++++++++++++++++++++++++--------------------
lisp/progmodes/cc-mode.el | 10 +++----
lisp/progmodes/cc-styles.el | 2 +-
lisp/progmodes/cc-vars.el | 10 +++++++
6 files changed, 69 insertions(+), 35 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..76f776d 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 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..d6f3503 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -258,31 +258,44 @@ 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)
+(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'.
+
+When the value of `major-mode' is not a match for this buffer-
+local value, we know that 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, and needs
+to be updated.")
+
(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.
@@ -322,7 +335,6 @@ after special characters such as brace, comma, semi-colon,
and colon."
(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)
@@ -339,7 +351,6 @@ the mode line after the mode name) the delete key gobbles
all preceding
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)
@@ -352,7 +363,6 @@ See `c-toggle-auto-newline' and `c-toggle-hungry-state' for
details."
(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)
@@ -362,7 +372,6 @@ positive, turns it off when negative, and just toggles it
when zero or
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))
@@ -390,7 +399,6 @@ This action does nothing when the mode only has one comment
style."
(if c-block-comment-flag
(concat " " c-block-comment-ender)
""))
- (c-update-modeline)
(c-keep-region-active))
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index f09ca04..456b826 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -642,6 +642,8 @@ that requires a literal mode spec at compile time."
;; (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
@@ -2029,16 +2031,14 @@ This function is called from `c-common-init', once per
mode initialization."
(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)))
;; Support for C
@@ -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))))
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index 0475114..8dee5e2 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -1695,6 +1695,16 @@ c-noise-macro-with-parens-names is invalid: %s"
c-noise-macro-with-parens-names)
(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)
;; Non-customizable variables, still part of the interface to CC Mode
(defvar c-macro-with-semi-re nil