From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: POC: customizable cc-mode keywords Date: Mon, 08 Sep 2014 13:28:32 -0400 Message-ID: References: <53632C6F.5070903@dancol.org> <20140511211351.GC2759@acm.acm> <536FEA43.5090402@dancol.org> <20140516175226.GB3267@acm.acm> <537653A0.2070109@dancol.org> <20140518213331.GB2577@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1410197351 17457 80.91.229.3 (8 Sep 2014 17:29:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Sep 2014 17:29:11 +0000 (UTC) Cc: Daniel Colascione , Emacs developers To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 08 19:29:03 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XR2kR-0007LD-DS for ged-emacs-devel@m.gmane.org; Mon, 08 Sep 2014 19:29:03 +0200 Original-Received: from localhost ([::1]:44910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR2kQ-0006Bl-Q0 for ged-emacs-devel@m.gmane.org; Mon, 08 Sep 2014 13:29:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR2kA-0006Aa-Fd for emacs-devel@gnu.org; Mon, 08 Sep 2014 13:28:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XR2k1-0004Yw-VO for emacs-devel@gnu.org; Mon, 08 Sep 2014 13:28:46 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:59902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR2k1-0004YS-Rj for emacs-devel@gnu.org; Mon, 08 Sep 2014 13:28:37 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id s88HSWuF028710; Mon, 8 Sep 2014 13:28:33 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 6B0F660BF3; Mon, 8 Sep 2014 13:28:32 -0400 (EDT) In-Reply-To: <20140518213331.GB2577@acm.acm> (Alan Mackenzie's message of "Sun, 18 May 2014 21:33:31 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV5058=0 X-NAI-Spam-Version: 2.3.0.9378 : core <5058> : inlines <1264> : streams <1284662> : uri <1811740> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:174093 Archived-At: > :-) This problem was first highlighted as such, by you, this month, not > several years ago. Your patch is complicated, it's disruptive, yet you > seem put out that I want to discuss it and understand it, rather than > just blindly applying it as it is. FWIW, his patch is not that complicated. It has 2 parts: - get rid of some of the compile-time precomputation of settings. - add a new (set of) custom vars and use them where appropriate. The second part is very straightforward (quoted below, for reference). The first part mostly removes code, and more specifically removes complex code, so it actually makes the code simpler. I think the performance impact is higher than what Daniel claims (his machine is clearly faster than mine), but I suspect that this can be fixed. >> It's not a massive change in architecture. > As I said, I don't fully understand the change, yet. Take another look at it, below. > But moving calculations from compile time to run time _is_ a change of > architecture, and it seems to me not to be small. Right, this one is larger, but if it can be made without significant performance degradation, then it's a good change. > It seems to me that the rigid separation between language (e.g. C) and > user configuration is being broken down. How much easier will it be > for a user mistakenly to attempt to configure her CC Mode by messing > around with the c-lang-consts? I'm not too worried ;-) Stefan === modified file 'lisp/progmodes/cc-langs.el' --- lisp/progmodes/cc-langs.el 2014-01-01 07:43:34 +0000 +++ lisp/progmodes/cc-langs.el 2014-05-02 05:19:24 +0000 @@ -1921,15 +1921,13 @@ ;; declaration. Specifically, they aren't recognized in the middle ;; of multi-token types, inside declarators, and between the ;; identifier and the arglist paren of a function declaration. - ;; - ;; FIXME: This ought to be user customizable since compiler stuff - ;; like this usually is wrapped in project specific macros. (It'd - ;; of course be even better if we could cope without knowing this.) - t nil - (c c++) '(;; GCC extension. - "__attribute__" - ;; MSVC extension. - "__declspec")) + t (when (boundp (c-mode-symbol "extra-keywords")) + (mapcar #'car (c-mode-var "extra-keywords"))) + (c c++) (append (c-lang-const c-decl-hangon-kwds) + '( ;; GCC extension. + "__attribute__" + ;; MSVC extension. + "__declspec"))) (c-lang-defconst c-decl-hangon-key ;; Adorned regexp matching `c-decl-hangon-kwds'. @@ -2120,11 +2118,18 @@ (c-lang-defconst c-paren-nontype-kwds "Keywords that may be followed by a parenthesis expression that doesn't contain type identifiers." - t nil - (c c++) '(;; GCC extension. - "__attribute__" - ;; MSVC extension. - "__declspec")) + t (when (boundp (c-mode-symbol "extra-keywords")) + (apply 'nconc + (mapcar (lambda (kw) + (when (cdr kw) + (list (car kw)))) + (c-mode-var "extra-keywords")))) + (c c++) (append + (c-lang-const c-paren-nontype-kwds) + '( ;; GCC extension. + "__attribute__" + ;; MSVC extension. + "__declspec"))) (c-lang-defconst c-paren-type-kwds "Keywords that may be followed by a parenthesis expression containing === modified file 'lisp/progmodes/cc-vars.el' --- lisp/progmodes/cc-vars.el 2014-01-01 07:43:34 +0000 +++ lisp/progmodes/cc-vars.el 2014-05-02 05:24:28 +0000 @@ -1614,6 +1614,75 @@ :group 'c) + +(define-widget 'c-extra-keywords-widget 'lazy + "Internal CC Mode widget for the `*-extra-keywords' variables." + :type '(repeat + (cons + (string :tag "Keyword") + (boolean :tag "Parenthesized expression follows")))) + +(defun c-make-extra-keywords-blurb (mode1 mode2) + (concat "\ +*List of extra keywords to recognize in " + mode1 " mode. +Each list item should be a cons (KW . PAREN). +KW should be a string naming a single identifier. +PAREN should be nil or t. If t, expect the a parenthesized expression +after KW and skip over it. + +Note that this variable is only consulted when the major mode is +initialized. If you change it later you have to reinitialize CC +Mode by doing \\[" mode2 "]. Additionally, if you change this +variable outside of customize, you need to call +`c-clear-value-cache' to make your changes take effect.")) + +(defun c-extra-keywords-setter (sym val) + (set-default sym val) + (c-clear-value-cache)) + +(defcustom c-extra-keywords + nil + (c-make-extra-keywords-blurb "C" "c-mode") + :type 'c-extra-keywords-widget + :set 'c-extra-keywords-setter + :group 'c) + +(defcustom c++-extra-keywords + nil + (c-make-extra-keywords-blurb "C++" "c++-mode") + :type 'c-extra-keywords-widget + :set 'c-extra-keywords-setter + :group 'c) + +(defcustom objc-extra-keywords + nil + (c-make-extra-keywords-blurb "ObjC" "objc-mode") + :type 'c-extra-keywords-widget + :set 'c-extra-keywords-setter + :group 'c) + +(defcustom java-extra-keywords + nil + (c-make-extra-keywords-blurb "Java" "java-mode") + :type 'c-extra-keywords-widget + :set 'c-extra-keywords-setter + :group 'c) + +(defcustom idl-extra-keywords nil + nil + :type 'c-extra-keywords-widget + :set 'c-extra-keywords-setter + :group 'c) + +(defcustom pike-extra-keywords + nil + (c-make-extra-keywords-blurb "Pike" "pike-mode") + :type 'c-extra-keywords-widget + :set 'c-extra-keywords-setter + :group 'c) + + ;; Non-customizable variables, still part of the interface to CC Mode (defvar c-macro-with-semi-re nil ;; Regular expression which matches a (#define'd) symbol whose expansion [[End of PGP Signed Part]]