From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Spiers Newsgroups: gmane.emacs.devel Subject: Re: Patch upstream Git for Elisp diff hunk headings Date: Thu, 11 Feb 2021 18:27:38 +0000 Message-ID: References: <87czx68y4i.fsf@protesilaos.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10137"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Protesilaos Stavrou Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Feb 11 19:30:18 2021 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 1lAGjI-0002LB-9Z for ged-emacs-devel@m.gmane-mx.org; Thu, 11 Feb 2021 19:30:16 +0100 Original-Received: from localhost ([::1]:43914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAGjH-0001HO-Bd for ged-emacs-devel@m.gmane-mx.org; Thu, 11 Feb 2021 13:30:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAGgr-0007iv-ET for emacs-devel@gnu.org; Thu, 11 Feb 2021 13:27:45 -0500 Original-Received: from coral.adamspiers.org ([2001:ba8:1f1:f27f::2]:46272) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAGgo-0000Vc-Ot for emacs-devel@gnu.org; Thu, 11 Feb 2021 13:27:45 -0500 Original-Received: from localhost (243.103.2.81.in-addr.arpa [81.2.103.243]) by coral.adamspiers.org (Postfix) with ESMTPSA id C85D82E749; Thu, 11 Feb 2021 18:27:39 +0000 (GMT) Content-Disposition: inline In-Reply-To: <87czx68y4i.fsf@protesilaos.com> Received-SPF: pass client-ip=2001:ba8:1f1:f27f::2; envelope-from=emacs-devel@adamspiers.org; helo=coral.adamspiers.org X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:264420 Archived-At: On Thu, 11 Feb 2021 at 14:42, Protesilaos Stavrou wrote: >Dear members, > >Myself and Adam Spiers (in cc) have been discussing the possibility of >patching Git so that it can handle Emacs Lisp diff hunk headings >natively. Those headings consist of the text that follows the line >ranges that diff outputs. So this: > > @@ -389,7 +390,7 @@ HEADING HERE > >Git produces those headings using language-specific regular expressions. >Elisp is not covered. Users must thus define their own Git attributes. >Not doing so results in practically useless text for the heading; text >that does not provide an accurate sense of context. > >I have noticed that Emacs' git repo includes the file ".gitattributes" >which instructs diffs inside of that repo to use an Elisp-aware regexp >present in "autogen.sh": > > git_config diff.elisp.xfuncname \ > '^\([^[:space:]]*def[^[:space:]]+[[:space:]]+([^()[:space:]]+)' > >This is an improvement over the out-of-the-box Git experience. > >Now the questions to this list: > >1. What do you think about only targeting top-level forms? Thanks Prot. To add a little bit of colour to this particular question, I'm thinking of cases like (use-package some-package :config [... many lines of config code ...]) or many other top-level forms commonly found in users' emacs init files. These would not match the regexp above, and since clearly it is possible to define any function or macro, the only way I can think of to teach git a line-based regexp for recognising the start of top-level forms is to make the assumption that they are not indented, e.g. git_config diff.elisp.xfuncname "^(\\(.*)$" Indeed this is what Prot initially suggested in his original blog post which sparked this discussion: https://protesilaos.com/codelog/2021-01-26-git-diff-hunk-elisp-org/ While of course no one is claiming that this is technically correct in all cases, I don't think I can actually recall ever seeing a single instance of a top-level form which *was* indented. So presumably it's a good enough heuristic to be helpful in the vast majority of cases. Or at least it's more likely to be right than a heuristic which assumes that all top-level forms include "def" in the first symbol in the form, since the latter obviously fails in many common scenarios including the init files one mentioned above. Would be grateful to hear other views on this. Thanks, Adam