1

我有一个创建空 html 文件的 lisp 脚本:

(let ((mode "html-mode"))

  (funcall (intern mode)))

(write-region "" nil "index.html")

然后我使用 yasnippet 生成基本的 html 文件:我有一个名为“base”的片段(我按 TAB 键将其展开)

有没有办法在我的 lisp 脚本中使用这个片段?

我尝试了,但没有成功使用(yas/expand-snippet base)

谢谢。

古尔文。

编辑

使用 abo-abo 的代码,我得到了一些效果很好的东西:

(defun create-web-site-test()
  (interactive)
  (setq msg (concatenate 'string "Create web site in : " default-directory))
  (if (y-or-n-p msg)
    (progn  
     (write-region "" nil "./index.html")
     (find-file "./index.html")
     (html-mode)    
     (insert "\nbase")
     (yas/expand)
     (save-buffer)
     (kill-buffer))
    (progn
      ;; Give up
      (message "Ok, nothing will be donne, bybye...")
      )))

我只需要使用 Mx cd 将当前目录设置到正确的位置。可能有一个更有效的解决方案,无需在缓冲区中打开文件。但是这个已经很酷了。谢谢 abo-abo

4

1 回答 1

0

这应该有效:

(progn
  (html-mode)
  (insert-file-contents "~/index.html")
  (insert "\nbase")
  (yas/expand))

请尝试阅读 elisp 手册。这很好。

UPD

I've updated the function. I see that you're new. To get a good answer you need to state clearly what you want to do. And if this answer is useful, don't forget to up-vote and accept.

Also, some comments on your code: concat should be used for strings, instead of concatenate. And it's best not to use y-or-n-p - just do what you want to do, and if you want to abort, use C-g.

(defun create-test (directory)
  (interactive "D")
  (with-current-buffer (find-file-noselect 
                        (concat directory "index.html"))
    (delete-region (point-min) (point-max))
    (html-mode)
    (insert "base")
    (yas/expand)
    (save-buffer)
    (kill-buffer)))
于 2013-08-09T15:09:41.330 回答