From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Sam Halliday Newsgroups: gmane.emacs.devel Subject: Re: possible bug in anchored font-lock functions Date: Sun, 11 Nov 2018 15:43:02 +0000 Message-ID: References: <87r2frg078.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1541950919 14527 195.159.176.226 (11 Nov 2018 15:41:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 11 Nov 2018 15:41:59 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 11 16:41:55 2018 Return-path: Envelope-to: ged-emacs-devel@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 1gLrs3-0003fE-CG for ged-emacs-devel@m.gmane.org; Sun, 11 Nov 2018 16:41:55 +0100 Original-Received: from localhost ([::1]:42673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLru9-00054d-Mt for ged-emacs-devel@m.gmane.org; Sun, 11 Nov 2018 10:44:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLrtP-0004il-Fh for emacs-devel@gnu.org; Sun, 11 Nov 2018 10:43:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLrtN-00078F-L7 for emacs-devel@gnu.org; Sun, 11 Nov 2018 10:43:19 -0500 Original-Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]:33795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gLrtL-00077E-FX for emacs-devel@gnu.org; Sun, 11 Nov 2018 10:43:16 -0500 Original-Received: by mail-io1-xd36.google.com with SMTP id f6so1541402iob.1 for ; Sun, 11 Nov 2018 07:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=5oc8GNOyK12EBDuYwIKVUPcYiJhueDT7AucWJ/Xa4UY=; b=NGWX8PjwW97rs90RLs0EfkvpYo4TDLk6TXQjN/E96RsnmzIRIO8IGnKTvEhMs6JjLy RTzvkIPt1azriALsuP+UkeH//r15TibBjj8c7FzecfxwH5GgqURK1fFP5q8mslq8bQpz 5uWzlyvf7GTJeFi9JHTWrrBYwSbs0rtAzorMrZ7kqB3v4FbGaOi/s3IT/x/iTbu3IUuk nv0nR+93MWyNj/NRed+VahSMlcMtX5jpKajJheYfHVfhmkw4kTyWu+nalCi5uvD4vrvO 1yfHh78IR5A88uQOL48Fp4zEqVTbB+b5L/nhOQ+WIpabuKIYIl2uNCPbN4ikMGd2SJDb hsrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=5oc8GNOyK12EBDuYwIKVUPcYiJhueDT7AucWJ/Xa4UY=; b=VRbQhYcPl+RGslKbbubgct9BZ0QPUITHkTdasYZkvGcMTnDgOVydIg4Z5swhJ2obaX GA+kMBR+lr1WG+vE3m2v+Oram2S8b13L7WIHK2q6IFyKO96mE0GOhaygYiC/5E/FCOR4 lfcwzX2pK+B+uclUpCMCmg9DjGpshqmUFxSKe2FL+UBp/OV1R5tLqwHHvce4DCHE+gkb gYPW8o30eJ8EAGGAi0qUu1L0YcSLZEfGUK3fX8mjPEqibnGTK52GfhddS47A70AzrBWi OTI6nEHof/i8BcTRmHf2uVdRDom+NNfAwFEItL7iyVgNdInitUH6QeyAUUjJp+l07btw IQjw== X-Gm-Message-State: AGRZ1gKPeUXJ6he4dpwtCx2c7ER5jIDNCU9ShFnJeuzYsjRQOOhGp4+2 awJ7T2Rmn/kkNLhBpcAxmZmBsuu90CtHUuScU6NxYpkJ X-Google-Smtp-Source: AJdET5dIHXLHpf8oF2Ua3+//5x4tsXjqij4aUKFl8ueVOHvvWAAGiy8PY3qN1ttkU3v5lQGohl9s+SmiXtdNEjA5118= X-Received: by 2002:a5e:d510:: with SMTP id e16-v6mr2225507iom.291.1541950993636; Sun, 11 Nov 2018 07:43:13 -0800 (PST) In-Reply-To: <87r2frg078.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::d36 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:231073 Archived-At: Further to this, I think I've tracked the issue to `font-lock-fontify-anchored-keywords` which is called with a `limit` parameter, but then `limit` is mutated very intentionally to the limit generated by the outer matcher... so I think this is NOT a bug, but just different behaviour to what I expected. i.e. the first pattern resets the limit for the anchored highlighters. On Sun, 11 Nov 2018 at 14:26, Sam Halliday wrote: > > Dear all, > > I think I might have found a bug in GNU Emacs but I would like to check > my understanding first, before filing a report or (ideally) fixing it. > > In Search Based Fontification[1] it is possible to specify a function as a > matcher. It must obey the following contract: > > > it receives one argument, the limit of the search; it should begin > > searching at point, and not search beyond the limit. It should return > > non-nil if it succeeds, and set the match data to describe the match > > that was found. Returning nil indicates failure of the search. > > In addition, it is possible to extend the region to be fontified by > adding a routine to `font-lock-extend-region-functions` that in-place > updates the `font-lock-beg` or `font-lock-end` variables (these > variables are not visible in a function matcher). Let's ignore > `font-lock-multiline` property approaches, I'm not using them. > > Indeed, I have confirmed that if I extend the region in a > `font-lock-extend-region-functions` then the `limit` does increase for > my function matcher! > > However, if I use an an `anchored` matcher, having the form `(matcher . > anchored-highlighter)`, where the `anchored-highlighter` is a > `function`, my custom `font-lock-{beg,end}` regions are ignored and > `limit` is much reduced! > > Is there something I need to do so that anchored matchers receive the > calculated regions or are they only designed to extend to the end of the > current line by default? > > If I had to guess I'd say the anchored matcher is forgetting to use > `font-lock-{beg,end}` and is instead calculating a new limit or using a > cached version of the limit from before > `font-lock-extend-region-functions` ran. > > I would greatly appreciate it if somebody could please point me to the > source code in GNU Emacs where the `font-lock-keywords` are called for > anchored matchers. I suspect the limit is also broken for `regexp` > matchers, not just `function`, but I have no way of printing out `limit` > in that case. > > A final note, this is the first time I've written a syntax-table and > font-lock for a programming language, and I have found the experience to > be much more pleasant than I expected! The font-lock-keyword API is > lovely to work with and I've been using the rx macro to avoid writing > regexps by hand... my code reads like a simplified BNF description! > > > [1] https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Search_002dbased-Fontification > > -- > Best regards, > Sam