From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Complex SPEC for variables/customization like font-lock-keywords/org-capture-templates/etc Date: Fri, 24 Nov 2023 23:03:14 -0500 Message-ID: References: <87fs169mjj.fsf@posteo.net> <877cmhlhjp.fsf@web.de> <878r6xef86.fsf@posteo.net> <877cmgdak8.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29198"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: monnier@iro.umontreal.ca To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Nov 25 05:04:23 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r6ju2-0007KI-RA for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Nov 2023 05:04:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6jt3-0004X2-SK; Fri, 24 Nov 2023 23:03:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6jt3-0004Wt-0e for emacs-devel@gnu.org; Fri, 24 Nov 2023 23:03:21 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6jt1-0001Ak-5g for emacs-devel@gnu.org; Fri, 24 Nov 2023 23:03:20 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 86068100068; Fri, 24 Nov 2023 23:03:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700884995; bh=FOp0FcxhY4u8Z9I4ZL0U/L/rTO54UFMjSnd18OXwoyE=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=FoFv3YB8jt04h3ZeTFUe+R1QfeqGFvqExj59aMmPIP3fzleEjGtg5Ofqc0oh+tg16 svHymeyI3te3i9U/LfEOtbuLM3sZF7ylWKbLBaDbo5VywGaqn1G/yQUVUHFXPWGrjh thDnVBecxMwwbcrfkHtHr/hXBDWlF5LxMXYx/XCwZCWSCN+nvz3bVenVm3NVElI3Dd Gi5qKN0bXRMKsOE1hheOWYQJBakqFHVK4jpA5z/0NOmd7upFxnFcLWmnJOSSd1Qx4x czUzkL6XczcXAcbynWnFGiYMpKcqDaifAFcgHd9yQInnIHn2ryKtME0D3pgN98gjPb zYNUMQRvAE0wA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id C5EEE100033; Fri, 24 Nov 2023 23:03:15 -0500 (EST) Original-Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A8873120249; Fri, 24 Nov 2023 23:03:15 -0500 (EST) In-Reply-To: <877cmgdak8.fsf@localhost> (Ihor Radchenko's message of "Fri, 17 Nov 2023 08:54:31 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:313191 Archived-At: > Or font-lock-keywords... Last time I were seriously developing new > keywords, I had to do it by trial-and-error and even examine > font-lock sources. [...] > I do not know a good solution to the above, and thus would like to > discuss this problem. > > Some possible ideas: > > 1. Provide some universal mechanism for type-validation of variables. > Something similar to :type spec in defcustom, but for Elisp > variables. This will at least catch invalid values. IME, the problem usually stems from a confusion between code and data: `font-lock-keywords` should hold code (i.e. something like a function) rather than nested-lists-with-special-structure. We could then provide some kind of macro to make it easier to define these functions. That's what I tried to do with `syntax-propertize-rules`, which is otherwise very similar to the previous `font-lock-syntactic-keywords`. That's also what I did with `bindat-type`. This has the advantage that the macro can make various sanity checks (and hence detect some of the possible errors), and that we can (to some extent) Edebug the result. I intended to try and provide a similar replacement facility for `font-lock-keywords`, but haven't gotten to it. > 3. Enhance eldoc to show a tip about variable value structure, similar > to what is done for function arguments. It doesn't really work for `bindat-type`, but the use of macros should make it easier because the code tells us reliably that this is a Bindat type whereas nothing in the declaration of (defvar my-font-lock-keywords-1 ) that the nested lists are meant to be font-lock keywords (unless we use heuristics based on var names, which quickly become ugly and brittle). Stefan