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

From: Juri Linkov <[email-masked]>
Date: Fri, 31 Jan 2020 00:50:37 +0200

> And now that I think about it, maybe
>
>     (or buffer-file-name-for-mode buffer-file-name)

I encountered more problems with buffer-file-name-for-mode
because there are more unexpected places that expect buffer-file-name:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  find-file-name-handler(nil file-name-sans-versions)
  file-name-sans-versions(nil)
  generic-mode-find-file-hook()
  diff-syntax-fontify-props(#("/dev/null" 0 9 (face (diff-file-header diff-header) fontified t)) "" (0 0) t)
  diff-syntax-fontify-hunk(1686 3081 t)
  diff-syntax-fontify(1686 3081)

because it relies on non-nil buffer-file-name:

(defun generic-mode-find-file-hook ()
  ...
  (when (and (eq major-mode 'fundamental-mode)
             (or (null generic-ignore-files-regexp)
                 (not (string-match-p
                       generic-ignore-files-regexp
                       (file-name-sans-versions buffer-file-name)))))
                                                ================

It would be hard to find all occurrences of buffer-file-name
where to add buffer-file-name-for-mode.

Maybe safer would be to use just (delay-mode-hooks (set-auto-mode))