I have a yasnippet for cperl-mode:
# -*- mode: snippet -*- # name: print Dumper # key: vd # -- print Dumper($0);
I need to expand this snippet to different strings depending upon the directory of the file I'm editing:
- if dir contains
/mnt/beta/- output "die Dumper($0);"
- otherwise - output "print Dumper($0);"
I created the following function:
(defun print-dumper () "Print certain snippet depending upon file directory" (interactive) (let ((file-name (buffer-file-name))) (if (string-match "/mnt/beta/" file-name) (insert "die Dumper();") (insert "print Dumper();"))) (backward-char 2))
It works. But how to call it in cperl mode instead of expanding yasnippet? Is there a better way to do this?