haskell / haskell-snippets

Official collection of YASnippet Haskell snippets for Emacs.
12 stars 9 forks source link

haskell-snippets-dir set relative to arbitrary buffer file names #1

Closed eigengrau closed 9 years ago

eigengrau commented 9 years ago

haskell-snippets 20150502.1315 seems to install a hook, run after yasnippet is loaded, which is meant to append the snippets path below the haskell-snippet distribution directory to yas-load-directory. However, it appears that the path setting is run inside the context of the buffer from which yasnippet is loaded. This sets the snippet path relative to some arbitrary buffer file name, so that yasnippet will fail to load and complain about a non-existing snippet directory.

E.g., when invoking yas-global-mode within a buffer visiting a file in /home/user/Dev/bla, I get

yas--subdirs: Opening directory: no such file or directory, /home/user/Dev/bla/snippets
lukehoersten commented 9 years ago

It's interesting that this affects you and not other users (including myself). It's pretty standard for other snippets do do the same: https://github.com/mpenet/clojure-snippets/blob/master/clojure-snippets.el#L25

Do you have any idea why this may be affecting you? Does the Clojure snippet have the same problem for you?

eigengrau commented 9 years ago

I’m not really sure. FWIW I see this even when running emacs -q, package-initialize, visit buffer, yas-global-mode. I suspect this might not be triggered if you have (yas-global-mode) in your init, so that the buffer active during evaluation doesn’t visit any file, in which case only load-file-name is used. Can you reproduce it with the above, making sure to visit a file before activating yas-global-mode?

Thanks for making haskell-snippets!

lukehoersten commented 9 years ago

Ah yes that makes sense about yas-global-mode. Good tip.

I'm still unsure why all the other snippet loaders do this then. Either way I will accept your PR.

eigengrau commented 9 years ago

Thanks! I’m not an Elisp hacker, but my theory of how this comes about is that buffer-file-name is needed when you develop such loaders, because it helps you do eval-buffer. Without it, eval-buffer fails because load-file-name is nil then. No idea why this hasn’t been noticed much; maybe everyone just fires up yasnippets from their init. The problem seems to have been noted at least once, though.