From 7454e8aca12b47ae36fdb46b869ebf1e2ea7afa4 Mon Sep 17 00:00:00 2001 From: Phil Sainty Date: Mon, 2 Jul 2018 23:58:34 +1200 Subject: [PATCH] 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'. --- lisp/progmodes/cc-cmds.el | 60 ++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 31cf0b1..131d7d1 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -258,31 +258,43 @@ c-syntactic-information-on-region (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. + +These flags are set by `c-update-modeline'. + +See Info node `(ccmode) Minor Modes'." + :type 'boolean + :group 'c) + +(defvar-local c-modeline-flags "" + "Minor mode indicators to be appended to `mode-name'. + +Hidden when `c-modeline-display-flags' is nil. + +See Info node `(ccmode) Minor Modes'.") + (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'." + (when (stringp mode-name) + (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. -- 2.8.3