I'm test-driving Emacs 25.1 and have noticed that a simple concat command, which used to work in v.24 (and v.23), doesn't work in v.25.1:

(setq yas-snippet-dirs (concat user-emacs-directory "snippets"))

In v.25.1 I get the following error message:

byte-code: Wrong type argument: listp, "~/Dropbox/emacs/snippets"

To make it work in v.25.1, I need to do call the function thus:

(setq yas-snippet-dirs (concat user-emacs-directory '("snippets")))

So my question is, why doesn't the latter work in Emacs 25.1 anymore? (Or alternatively, is the former the correct way actually?)

  • It should be a list, instead of a string: (setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets")) – lawlist Feb 14 '16 at 18:09
  • Yep. But notice I'm concatenating my emacs dir (in the variable user-emacs-directory) with the string "snippets". (I use the same config in different machines with different OSs, so I need to have different dirs in that variable.) – NVaughan Feb 14 '16 at 18:13
  • 1
    Can you toggle-debug-on-error and post the backtrace? I think the error is not triggered by the concatenation at all (and the difference is more likey due to change in yasnippet version than Emacs). By the way, the correct way should be (setq yas-snippet-dirs (list (concat user-emacs-directory "snippets")) – npostavs Feb 14 '16 at 19:30
  • 1
    Re. building paths: consider using expand-file-name instead of concat. – Constantine Feb 14 '16 at 19:32
  • 1
    Well, that backtrace confirms that it's not concat itself throwing the error, but it's hard to make sense of it due to byte-compilation. Can you load yasnippet.el without the elc and redo it? – npostavs Feb 14 '16 at 21:43

The change is not in concat, but in yas-snippet-dirs. In earlier versions, yas-snippet-dirs could be either a single directory (a string) or a list of directories. The line

(setq yas-snippet-dirs (concat user-emacs-directory "snippets"))

is working, it's setting yas-snippet-dirs to the string "~/Dropbox/emacs/snippets". The error message

byte-code: Wrong type argument: listp, "~/Dropbox/emacs/snippets"

lists that string, and is telling you that this string was used in a context that requires a list.

I'm actually surprised that your second attempt got anywhere, as Emacs from git, just like previous released versions, do not accept a list of strings as the argument of concat.

In any case, unless you need to keep supporting older versions of yasnippet, make yas-snippet-dirs a list.

(setq yas-snippet-dirs (list (concat user-emacs-directory "snippets")))

or the more explicit (and theoretically more portable, and more robust as it doesn't require that user-emacs-directory have a trailing slash)

(setq yas-snippet-dirs (list (expand-file-name "snippets" user-emacs-directory)))
  • FWIW, that doesn't sound like a great library change. I wonder if the incompatibility was really necessary. Seems like the author of ya-snippet might have respected backward compatibility a bit better. (Typically code just creates a singleton list if the thing in question is a non-nil atom.) – Drew Feb 14 '16 at 23:34
  • @Drew I only skimmed the code in git. The documentation no longer says that strings are accepted, but some of the code still accepts strings. The lack of support for strings may be unintended and may only arise in specific use cases. – Gilles Feb 14 '16 at 23:36
  • 1
    "Emacs [...] do[es] not accept a list of strings as the argument of concat." - the arguments to concat are user-emacs-directory and "snippets", both of which are strings, not lists. – npostavs Feb 15 '16 at 0:16
  • @npostavs I was refering to the “I need to do call the function thus” bit. I've clarified my answer. – Gilles Feb 15 '16 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.