c++ - 使用 Emacs 从 .h 自动插入原型(prototype)函数

标签 c++ emacs

如何配置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/

相关文章:

c++ - 删除 Raspberry Pi 3 上 QMessageBox 的最小化按钮

emacs - 在 Emacs 中用苹果酒评估的表达式获得 pretty-print 结果

emacs - eval-buffer 在设置 CLISP/SLIME 时不做任何事情

Emacs:不保存修改后的缓冲区时,请勿创建#these#文件

c++ - 使用Doxygen制作Visual Studio和Emacs的文档

c++ - POD 类型的填充字节是否被复制?

c++ - 单独的 QT 小部件实例

emacs - 连接 abbrev 文件中的字符串

c++ - const ref lvalue to non-const func return value 是否专门减少拷贝?

C++:修改 const 的数组值