unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 39190@debbugs.gnu.org, Felician Nemeth <felician.nemeth@gmail.com>
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	[thread overview]
Message-ID: <875zh13e5d.fsf@mail.linkov.net> (raw)
In-Reply-To: <jwvy2u17lwo.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 20 Jan 2020 18:34:34 -0500")

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(#<buffer  *temp*-492063>)
  (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) #<bytecode 0x1cb64d70b7d4e0e5>)(10530 14909)
  diff--iterate-hunks(12505 #f(compiled-function (beg end) #<bytecode 0x1cb64d70b7d4e0e5>))
  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) #<bytecode 0x303b13b2afd8864>)(font-lock-fontify-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x303b13b2afd8864>) 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?





  reply	other threads:[~2020-01-24  0:13 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-19 11:14 bug#39190: 28.0.50; two buffers with same buffer-file-name (diff-syntax-fontify-props) Felician Nemeth
2020-01-20 22:56 ` Juri Linkov
2020-01-20 23:34   ` Stefan Monnier
2020-01-24  0:13     ` Juri Linkov [this message]
2020-01-24 14:18       ` Stefan Monnier
2020-01-28  0:01         ` Juri Linkov
2020-01-28  1:30           ` Stefan Monnier
2020-01-28  3:32             ` Eli Zaretskii
2020-01-28 13:58               ` Stefan Monnier
2020-01-28 14:54                 ` Dmitry Gutov
2020-01-28 22:53                   ` Juri Linkov
2020-01-28 17:54                 ` Eli Zaretskii
2020-01-28 20:12                   ` Stefan Monnier
2020-01-28 20:23                     ` Eli Zaretskii
2020-01-28 23:17                       ` Stefan Monnier
2020-01-29 17:13                         ` Eli Zaretskii
2020-01-29 21:33                           ` Stefan Monnier
2020-01-30 14:17                             ` Eli Zaretskii
2020-01-30 14:34                               ` Stefan Monnier
2020-01-30 22:50             ` Juri Linkov
2020-01-30 23:09               ` Stefan Monnier
2020-01-30 23:31               ` Dmitry Gutov
2020-01-26 19:34       ` Felician Nemeth
2020-01-28  0:05         ` Juri Linkov
2020-01-28 17:18           ` Felician Nemeth
2020-01-29 23:07             ` Juri Linkov
2020-01-30 19:48               ` Felician Nemeth
2020-01-30 22:45                 ` Juri Linkov
2020-02-02  9:42                   ` Felician Nemeth
2020-02-02 13:50                     ` Stefan Monnier
2020-02-02 23:41                       ` Juri Linkov
2020-02-03 13:14                         ` Dmitry Gutov
2020-02-03 22:44                           ` Juri Linkov
2020-02-04 13:08                             ` Dmitry Gutov
2020-02-03 22:45                     ` Juri Linkov
2020-02-04 13:36                       ` Stefan Monnier
2020-02-04 23:20                         ` Juri Linkov
2020-02-05 22:39                           ` Juri Linkov
2020-02-09 16:06                             ` Felician Nemeth
2020-02-18  0:06                               ` Juri Linkov
2020-02-18 13:33                                 ` Stefan Monnier
2020-02-18 22:53                                   ` Juri Linkov
2020-02-18 23:07                                     ` Stefan Monnier
2020-02-18 23:31                                       ` Stefan Monnier
2020-02-19  0:49                                         ` Juri Linkov
2020-02-19 13:20                                           ` Stefan Monnier
2020-02-20  0:58                                             ` Juri Linkov
2020-03-24 21:37                                         ` Juri Linkov
2020-03-24 22:29                                           ` Stefan Monnier
2020-03-25 20:39                                             ` Juri Linkov
2020-03-25 21:13                                               ` Stefan Monnier
2020-03-25 21:48                                                 ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zh13e5d.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=39190@debbugs.gnu.org \
    --cc=felician.nemeth@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).