all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Phil Sainty <psainty@orcon.net.nz>
To: 2034@debbugs.gnu.org
Subject: bug#2034: [PATCH] 27.0.50; Support mode line constructs for `mode-name' in c-mode
Date: Tue, 3 Jul 2018 00:40:49 +1200	[thread overview]
Message-ID: <47fd3239-fe83-0f2f-b903-e18713cc60f6@orcon.net.nz> (raw)
In-Reply-To: <87skn8xhia.fsf@transitory.lefae.org>

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

`c-update-modeline' in cc-cmds.el has a long-standing bug (and FIXME
comment) whereby a `mode-name' which is not a string will trigger
errors, on account of the function using string manipulations to add
the minor mode flags to the original `mode-name'.

This is what bug #2034 was originally about. i.e.:

> c-update-modeline: Wrong type argument: stringp,
> (sgml-xml-mode "XML" "SGML")

This new patch instead uses mode-line constructs to concatenate the
flags, thus eliminating the string manipulation code and this bug.

In the process I've added a user option to allow the user to choose
whether or not these flags should be displayed at all, as this was not
previously configurable.

e.g.: `c-update-modeline' will now convert the mode-name "C++" into
'("C++" (c-modeline-display-flags c-modeline-flags)); and it only
updates the buffer-local value of `c-modeline-flags' which is then
conditionally displayed based on option `c-modeline-display-flags'.

This bug fix also resolves an incompatibility with the `delight'
package in GNU ELPA, which wraps any targeted `mode-name' values
in additional mode line constructs, and consequently triggered the
`c-update-modeline' bug with its assumption of a string, when used
with any of the major modes in question.

In my testing thus far this new approach seems to work nicely.


-Phil

[-- Attachment #2: 0001-Support-mode-line-constructs-for-mode-name-in-c-mode.patch --]
[-- Type: text/x-patch, Size: 3262 bytes --]

From 7454e8aca12b47ae36fdb46b869ebf1e2ea7afa4 Mon Sep 17 00:00:00 2001
From: Phil Sainty <psainty@orcon.net.nz>
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


  parent reply	other threads:[~2018-07-02 12:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8cbpgkqwkt.fsf@fencepost.gnu.org>
2009-01-25  2:10 ` bug#2034: 23.0.60; c-subword-mode incompatible with xml-mode me
2009-01-25 15:44   ` Stefan Monnier
2009-01-25 18:48     ` Ross Patterson
2010-01-23 22:36   ` bug#2034: marked as done (23.0.60; c-subword-mode incompatible with xml-mode) Emacs bug Tracking System
2018-07-02 12:40   ` Phil Sainty [this message]
2018-07-02 15:29     ` bug#2034: [PATCH] 27.0.50; Support mode line constructs for `mode-name' in c-mode Eli Zaretskii
2018-07-02 22:53       ` Phil Sainty
2018-07-03 13:37         ` Phil Sainty
2018-07-04  2:41         ` Eli Zaretskii
     [not found]   ` <mailman.3006.1530625089.1292.bug-gnu-emacs@gnu.org>
2018-07-04 20:11     ` Alan Mackenzie
2018-07-04 21:13       ` Phil Sainty
2018-07-08  2:46         ` Phil Sainty
2018-07-08 20:08         ` Alan Mackenzie
2018-07-09 14:47           ` Phil Sainty

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47fd3239-fe83-0f2f-b903-e18713cc60f6@orcon.net.nz \
    --to=psainty@orcon.net.nz \
    --cc=2034@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.