对于从遗留项目到当前项目的多个项目使用emacs,我必须使用多个约定,例如用于注释或文件头。例如,我使用此函数为C++文件插入文件头:
(defun mg-c-file-header()
"Inserts a c/c++ file header"
(if (boundp 'mg-auto-insert-style)
(case mg-auto-insert-style
(project-a
(insert
" * @file "(file-name-nondirectory buffer-file-name)"\n"
" * \n"
" * (c) 2000 - "( format-time-string "%Y" )" by someone\n"))
(project-b
(insert "/** another header*/\n"))
(otherwise (message "Meh.")))))我在下面的上下文中调用此函数:
(setq auto-insert-alist
'(
(("\\.\\([C]\\|cc\\|cpp\\)\\'" . "C++ Program")
nil
( mg-c-file-header )
"// --- includes --- \n"
;; and do on....我可以用M-x的set-variable来设置mg-auto-insert-style,这没问题。但我希望根据当前缓冲区的文件路径自动设置该变量。因此,如果我在~/projects/project-a中打开一个缓冲区或访问一个新文件,mg-auto-insert-style应该是project-a。
这是可行的,但并不完美:
(ede-cpp-root-project "project-a"
:file "~/projects/project-a/trunk/src/Makefile"
:local-variables (list
(cons 'mg-auto-insert-style 'project-a )))如果我创建了一个新文件,当自动插入完成时,mg-auto-insert-style不会被绑定。后来,就没问题了.
你有什么想法吗?
马库斯
https://stackoverflow.com/questions/6532634
复制相似问题