I am doing some Drupal programming and have created yasnippets for common functions: db_select, db_delete etc.
I want to load them only when I am working on a Drupal file and not for a common php file. The task is this:
given a list of yasnippet files and the path of the currently opening file
if(path contains '/sites/all/modules')
{
load all the snippets from the list
}
How to do it?
You have two options:
Either way you'll be doing things based on the current directory or filename.
find-file-hook
exampleI haven't tested this code but the concept is there. You'll probably have to check the yas/load-directory-1
function to something else or mess around with parameters.
(defun load-drupal-snippets ()
(when (string-match-p "/sites/all/modules" (file-name-directory (buffer-file-name)))
(yas--load-directory-1 "/path/to/drupal/snippets/" 'php-mode 'text-mode)))
(add-hook 'find-file-hook 'load-drupal-snippets)