added custom template expand function (M-j)