使用Emacs自动从.h插入原型函数

Mar*_*ark 9 c++ emacs

如何配置emacs以在打开相应的.cc文件时从.h自动插入原型函数?

Nat*_*ath 4

当我使用成员函数包进行更多 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)
Run Code Online (Sandbox Code Playgroud)

您可以在以下位置找到member-functions.el: http: //www.emacswiki.org/emacs/member-functions.el