From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#39190: 28.0.50; two buffers with same buffer-file-name (diff-syntax-fontify-props) Date: Fri, 24 Jan 2020 02:13:18 +0200 Organization: LINKOV.NET Message-ID: <875zh13e5d.fsf@mail.linkov.net> References: <875zh73dg8.fsf@betli.tmit.bme.hu> <8736c921s6.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="80731"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.60 (x86_64-pc-linux-gnu) Cc: 39190@debbugs.gnu.org, Felician Nemeth To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 24 01:16:14 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1iumdx-000KwH-N4 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Jan 2020 01:16:13 +0100 Original-Received: from localhost ([::1]:35700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iumdw-0000Xy-Bz for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Jan 2020 19:16:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36134) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iumdo-0000Xe-0S for bug-gnu-emacs@gnu.org; Thu, 23 Jan 2020 19:16:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iumdm-00060Y-Me for bug-gnu-emacs@gnu.org; Thu, 23 Jan 2020 19:16:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47353) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iumdm-00060P-DO for bug-gnu-emacs@gnu.org; Thu, 23 Jan 2020 19:16:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iumdm-0003B6-7s for bug-gnu-emacs@gnu.org; Thu, 23 Jan 2020 19:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Jan 2020 00:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39190 X-GNU-PR-Package: emacs Original-Received: via spool by 39190-submit@debbugs.gnu.org id=B39190.157982495012190 (code B ref 39190); Fri, 24 Jan 2020 00:16:02 +0000 Original-Received: (at 39190) by debbugs.gnu.org; 24 Jan 2020 00:15:50 +0000 Original-Received: from localhost ([127.0.0.1]:53326 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iumda-0003AY-Cn for submit@debbugs.gnu.org; Thu, 23 Jan 2020 19:15:50 -0500 Original-Received: from egyptian.birch.relay.mailchannels.net ([23.83.209.56]:51173) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iumdY-0003AP-4D for 39190@debbugs.gnu.org; Thu, 23 Jan 2020 19:15:49 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id BB8056A1E59; Fri, 24 Jan 2020 00:15:46 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a9.g.dreamhost.com (100-96-89-22.trex.outbound.svc.cluster.local [100.96.89.22]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 0A5A16A0C10; Fri, 24 Jan 2020 00:15:46 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a9.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.18.5); Fri, 24 Jan 2020 00:15:46 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Arch-Relation: 7455ad1e4dcc18c1_1579824946280_1926449678 X-MC-Loop-Signature: 1579824946280:3302374372 X-MC-Ingress-Time: 1579824946278 Original-Received: from pdx1-sub0-mail-a9.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a9.g.dreamhost.com (Postfix) with ESMTP id 1D09D7EFAA; Thu, 23 Jan 2020 16:15:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=sjqaAKGObz+zqoysSD8V+uIJDRk=; b= yFmES99Qatd53R5TkoAewc3GYJklhmSELJq9MLYVwJekhEhd/68/dW3yYK4iLscf WtqGlUFJjdwdm+SaQbfSdsHhAl549RoT1T8h4zkCDJfVYTAIcWcIfNnoymGzEnKh yigiiCNL1Mob0iflOwcvLOERIJBqCciPEmmUDPUte/o= Original-Received: from mail.jurta.org (m91-129-105-126.cust.tele2.ee [91.129.105.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a9.g.dreamhost.com (Postfix) with ESMTPSA id 51EC47ED5E; Thu, 23 Jan 2020 16:15:39 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a9 In-Reply-To: (Stefan Monnier's message of "Mon, 20 Jan 2020 18:34:34 -0500") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrvdefgddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffuohhfffgjkfgfgggtsehttdertddtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecukfhppeeluddruddvledruddthedruddvieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddthedruddviedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehmohhnnhhivghrsehirhhordhumhhonhhtrhgvrghlrdgtrg 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: 209.51.188.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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:175199 Archived-At: Now I tried to repeat this problem with eglot and got such backtrace: Debugger entered--Lisp error: (wrong-type-argument arrayp nil) substring(nil 0 1) file-truename(nil) eglot--path-to-uri(nil) eglot--TextDocumentIdentifier() eglot--signal-textDocument/didClose() kill-buffer(#) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)) (unwind-protect (progn (insert text) (diff-syntax-fontify-props ... (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert text) (diff-syntax-fontify-props ... (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert text) ... (cond ((and file diff-default-directory ...) ...) ...) (let ((file (car (diff-hunk-file-names old)))) ...) (or (if (and diff-vc-backend (not (eq diff-font-lock-syntax 'hunk-only))) ...) ...) (let* ((hunk (buffer-substring-no-properties beg end)) ...) ... diff-syntax-fontify-hunk(10530 14909 t) diff-syntax-fontify(10530 14909) #f(compiled-function (beg end) #)(10530 14909) diff--iterate-hunks(12505 #f(compiled-function (beg end) #)) diff--font-lock-syntax(12505) font-lock-fontify-keywords-region(11965 12505 nil) font-lock-default-fontify-region(11980 12480 nil) font-lock-fontify-region(11980 12480) #f(compiled-function (fun) #)(font-lock-fontify-region) run-hook-wrapped(#f(compiled-function (fun) #) font-lock-fontify-region) jit-lock--run-functions(11980 12480) jit-lock-fontify-now(11980 12480) jit-lock-function(11980) redisplay_internal\ \(C\ function\)() >> Stefan, do you think diff-syntax-fontify-props should let-bind >> after-change-major-mode-hook to nil to not allow running this hook >> on an internal buffer. > > No, that's definitely not the right fix. It's at best a weak > workaround, but it won't handle the case where the code that depends on > `buffer-file-name` is placed on `foo-mode-hook` rather than on > `after-change-major-mode-hook`. In fact, eglot recommends adding such hooks: (add-hook 'foo-mode-hook 'eglot-ensure) where eglot-ensure relies on buffer-file-name, so such fix is not possible indeed. >>> If I read correctly, diff-syntax-fontify-props sets buffer-file-name of >>> a temporary buffer to an existing one. This is not necessarily a bug, >>> but it definitely looks strange that we have two buffers with different >>> contents and the same buffer-file-name. > > Yes, it's definitely borderline. I remember feeling a bit uneasy about > it at the time. Maybe a better fix would be to be able to pass the > file-name to `set-auto-mode` (or some new function created for that > purpose) as an argument (instead of passing it via dynamic scoping in > `buffer-file-name`). The problem is that the right value of buffer-file-name is required also by other more deep functions that set local variables like dir-locals-collect-variables. > BTW, I see somewhat similar code in `xref--collect-matches`, so maybe > there's a need for a more general solution (haven't looked any further, > but I'd be surprised if there aren't other cases). Another example is mm-display-inline-fontify in gnus/mm-view.el, so the problem is more widespread, and perhaps not much could be done more than already using temporary buffers as an indication for external packages that these buffers are for internal use only. >> Or it's the responsibility of the eglot package to check for the >> leading space in the buffer name when its after-change-major-mode-hook >> is called? > > The eglot package could protect itself from such things by making its > `after-change-major-mode-hook` just add the buffer to a global var, and > then process this global var in `post-command-hook` or in a timer. Felician, do you think that the eglot package should take more care to protect itself, so this report could be closed?