From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Phil Sainty Newsgroups: gmane.emacs.bugs 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 Message-ID: <47fd3239-fe83-0f2f-b903-e18713cc60f6@orcon.net.nz> References: <87skn8xhia.fsf@transitory.lefae.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5C0DBF0F5F2B969FCB2683FC" X-Trace: blaine.gmane.org 1530535212 16347 195.159.176.226 (2 Jul 2018 12:40:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 2 Jul 2018 12:40:12 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 To: 2034@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jul 02 14:40:08 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZy7j-00048b-7z for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jul 2018 14:40:07 +0200 Original-Received: from localhost ([::1]:60839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZy9q-0002wO-HB for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jul 2018 08:42:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fZy8h-0002Gp-DL for bug-gnu-emacs@gnu.org; Mon, 02 Jul 2018 08:41:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fZy8d-0002ky-Eo for bug-gnu-emacs@gnu.org; Mon, 02 Jul 2018 08:41:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34779) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fZy8d-0002ku-6r for bug-gnu-emacs@gnu.org; Mon, 02 Jul 2018 08:41:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fZy8c-00027g-11 for bug-gnu-emacs@gnu.org; Mon, 02 Jul 2018 08:41:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87skn8xhia.fsf@transitory.lefae.org> Resent-From: Phil Sainty Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Jul 2018 12:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 2034 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: notabug wontfix Original-Received: via spool by 2034-submit@debbugs.gnu.org id=B2034.15305352588144 (code B ref 2034); Mon, 02 Jul 2018 12:41:01 +0000 Original-Received: (at 2034) by debbugs.gnu.org; 2 Jul 2018 12:40:58 +0000 Original-Received: from localhost ([127.0.0.1]:42676 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZy8Y-00027I-El for submit@debbugs.gnu.org; Mon, 02 Jul 2018 08:40:58 -0400 Original-Received: from smtp-3.orcon.net.nz ([60.234.4.44]:39856) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fZy8V-000279-K6 for 2034@debbugs.gnu.org; Mon, 02 Jul 2018 08:40:56 -0400 Original-Received: from [150.107.172.83] (port=21033 helo=[192.168.20.103]) by smtp-3.orcon.net.nz with esmtpa (Exim 4.86_2) (envelope-from ) id 1fZy8P-0007NH-MD for 2034@debbugs.gnu.org; Tue, 03 Jul 2018 00:40:53 +1200 Content-Language: en-GB X-GeoIP: NZ X-Spam_score: -2.9 X-Spam_score_int: -28 X-Spam_bar: -- X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:148080 Archived-At: This is a multi-part message in MIME format. --------------5C0DBF0F5F2B969FCB2683FC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit `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 --------------5C0DBF0F5F2B969FCB2683FC Content-Type: text/x-patch; name="0001-Support-mode-line-constructs-for-mode-name-in-c-mode.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Support-mode-line-constructs-for-mode-name-in-c-mode.pa"; filename*1="tch" >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 --------------5C0DBF0F5F2B969FCB2683FC--