mineo / yatemplate

File templates for Emacs with YASnippet
https://github.com/mineo/yatemplate
GNU General Public License v3.0
70 stars 11 forks source link

Brakes in cases where `buffer-file-name' is nil #14

Closed terlar closed 6 years ago

terlar commented 6 years ago

I am not entirely sure why buffer-file-name would be nil, but I have found it consistently breaking the find-file-hook for files using nov-mode. There might be other cases where this happen.

Here is a minimal reproducible setup:

(require 'package)
(setq package-archives
      '(("melpa"    . "https://melpa.org/packages/")
    ("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)
(package-refresh-contents)

(package-install 'use-package)
(setq use-package-always-ensure t)

(require 'autoinsert)
(auto-insert-mode 1)

(use-package nov :mode ("\\.epub$" . nov-mode))
(use-package yasnippet :hook (after-init . yas-global-mode))
(use-package yatemplate :hook (yas-global-mode . yatemplate-fill-alist))

After that open an epub-file and the following error will be yielded:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  find-file-name-handler(nil file-in-directory-p)
  file-in-directory-p(nil "~/.emacs.d/templates")
  yatemplate--find-file-hook()
  run-hooks(find-file-hook)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer to.epub<devops>> "/path/to.epub" nil nil "/path/to.epub" (15755148 65026))
  find-file-noselect("/path/to.epub" nil nil t)
  find-file("/path/to.epub" t)
  funcall-interactively(find-file "/path/to.epub" t)
  call-interactively(find-file nil nil)
  command-execute(find-file)

This is due to the buffer-file-name being nil and find-file-name-handler not supporting nil as an argument. I am not sure why it would be nil since there is a file, but it must somehow run the hook before the buffer-file-name is set up?