forked from Github/emacs
Compare commits
2 commits
master
...
fix/bug-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9823f299bd | ||
|
|
6a4477d057 |
8 changed files with 85 additions and 63 deletions
|
|
@ -1179,16 +1179,21 @@ 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.
|
||||
|
||||
@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:
|
||||
|
||||
|
|
|
|||
12
etc/NEWS
12
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
|
||||
|
||||
|
|
|
|||
|
|
@ -2553,11 +2553,7 @@ the default language."
|
|||
(car r)))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode antlr-mode prog-mode
|
||||
;; FIXME: Since it uses cc-mode, it bumps into c-update-modeline's
|
||||
;; limitation to mode-name being a string.
|
||||
;; '("Antlr." (:eval (cadr (assq antlr-language antlr-language-alist))))
|
||||
"Antlr"
|
||||
(define-derived-mode antlr-mode prog-mode "Antlr"
|
||||
"Major mode for editing ANTLR grammar files."
|
||||
:abbrev-table antlr-mode-abbrev-table
|
||||
(c-initialize-cc-mode) ; cc-mode is required
|
||||
|
|
@ -2567,10 +2563,9 @@ the default language."
|
|||
(unless antlr-language
|
||||
(set (make-local-variable 'antlr-language)
|
||||
(or (antlr-language-option t) (antlr-language-option nil))))
|
||||
(if (stringp (cadr (assq antlr-language antlr-language-alist)))
|
||||
(setq mode-name
|
||||
(concat "Antlr."
|
||||
(cadr (assq antlr-language antlr-language-alist)))))
|
||||
(setq mode-name
|
||||
'("Antlr." (:eval (cadr (assq antlr-language
|
||||
antlr-language-alist)))))
|
||||
;; indentation, for the C engine -------------------------------------------
|
||||
(setq c-buffer-is-cc-mode antlr-language)
|
||||
(cond ((fboundp 'c-init-language-vars-for) ; cc-mode 5.30.5+
|
||||
|
|
|
|||
|
|
@ -258,31 +258,46 @@ 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'.
|
||||
|
||||
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.
|
||||
|
|
@ -322,7 +337,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 +353,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 +365,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 +374,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 +401,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))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -185,10 +185,6 @@
|
|||
(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
|
||||
|
|
|
|||
|
|
@ -637,11 +637,7 @@ that requires a literal mode spec at compile time."
|
|||
(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
|
||||
|
|
@ -2029,16 +2025,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 +2515,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
|
||||
|
|
|
|||
|
|
@ -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))))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue