如何配置emacs在打开相应的.cc文件时自动插入.h中的原型(prototype)函数?
最佳答案
当我使用成员函数包进行更多 C++ 编码时,我有类似的东西用于执行此操作:
(require 'member-function)
;;expand member functions automatically when entering a cpp file
(defun c-file-enter ()
"Expands all member functions in the corresponding .h file"
(let* ((c-file (buffer-file-name (current-buffer)))
(h-file-list (list (concat (substring c-file 0 -3 ) "h")
(concat (substring c-file 0 -3 ) "hpp")
(concat (substring c-file 0 -1 ) "h")
(concat (substring c-file 0 -1 ) "hpp"))))
(if (or (equal (substring c-file -2 ) ".c")
(equal (substring c-file -4 ) ".cpp"))
(mapcar (lambda (h-file)
(if (file-exists-p h-file)
(expand-member-functions h-file c-file)))
h-file-list))))
(add-hook 'c++-mode-hook c-file-enter)
您可以在以下位置找到 member-functions.el:http://www.emacswiki.org/emacs/member-functions.el
关于c++ - 使用 Emacs 从 .h 自动插入原型(prototype)函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6892627/