Subject: bug#39190: 28.0.50; two buffers with same buffer-file-name (diff-syntax-fontify-props)

From: Eli Zaretskii <[email-masked]>
Date: Wed, 29 Jan 2020 19:13:14 +0200

> From: Stefan Monnier <[email-masked]>
> Cc: [email-masked],  [email-masked],  [email-masked]
> Date: Tue, 28 Jan 2020 18:17:23 -0500
> 
> > Sorry, I don't understand.  I meant to ask why the code which sets
> > this new variable cannot call the major mode function instead?
> 
> The code does basically:
> 
>     (let ((buffer-file-name FOO))
>       (set-auto-mode))

Ah, okay.

But then did you consider alternatives to yet another magic
buffer-local variable?  Two possibilities come to mind:

 . change set-auto-mode to accept another optional argument, the file
   name to use to look up the mode

 . perform look up of auto-mode-alist, then invoke the mode directly

Also, setting the pseudo-filename is not guaranteed to turn on the
mode according to that file name.  Not sure if this matters in these
cases.

And finally, I cannot say that I like this part of the patch:

  @@ -3459,6 +3460,8 @@ hack-local-variables-confirm
       (let ((name (cond (dir-name)
			(buffer-file-name
			 (file-name-nondirectory buffer-file-name))
  +		      (buffer-file-name-for-mode
  +		       (file-name-nondirectory buffer-file-name-for-mode))
			((concat "buffer " (buffer-name)))))
	    (offer-save (and (eq enable-local-variables t)
			     unsafe-vars))

If buffer-file-name-for-mode is not really a file name, we shouldn't
call file-name-nondirectory on it.  If nothing else, it will signal an
error if buffer-file-name-for-mode is nil.