2

如何在 obj-c (c++) 模式下(即在 foo.[mM]{1,2} 和 foo.[hH]{1,2} 之间)使用头文件/实现文件在缓冲区之间切换 emacs?是否可以分配标准 Xcode 键盘快捷键 (ctrl+cmd) 来运行这样的宏?

4

3 回答 3

4

Emacs 内置支持使用 ff-find-other-file 从头文件跳转到实现文件:

(add-hook 'c-mode-common-hook
  (lambda() 
  (local-set-key  (kbd "C-c m d") 'ff-find-other-file)))

CC模式包括C、C++、Java、Objective C等。

于 2013-06-07T08:53:36.160 回答
2

看看这个链接。他描述了这个功能:

(defun objc-in-header-file ()
  (let* ((filename (buffer-file-name))
         (extension (car (last (split-string filename "\\.")))))
    (string= "h" extension)))

(defun objc-jump-to-extension (extension)
  (let* ((filename (buffer-file-name))
         (file-components (append (butlast (split-string filename
                                                         "\\."))
                                  (list extension))))
    (find-file (mapconcat 'identity file-components "."))))

;;; Assumes that Header and Source file are in same directory
(defun objc-jump-between-header-source ()
  (interactive)
  (if (objc-in-header-file)
      (objc-jump-to-extension "m")
    (objc-jump-to-extension "h")))

(defun objc-mode-customizations ()
  (define-key objc-mode-map (kbd "C-c t") 'objc-jump-between-header-source))

(add-hook 'objc-mode-hook 'objc-mode-customizations)
于 2013-06-07T08:07:01.117 回答
0

eassist-switch-h-cpp除了 C/C++ 代码之外,还可以从 CEDET 的 contrib扩展函数以使用 ObjC 文件。更改很简单,将以下代码添加到您的 init 文件中:

(eval-after-load "eassist"
 '(progn
   (setq eassist-header-switches '(("h" . ("cpp" "cc" "c" "m"))
                ("hpp" . ("cpp" "cc"))
                ("cpp" . ("h" "hpp"))
                ("c" . ("h"))
                ("m" . ("h"))
                ("C" . ("H"))
                ("H" . ("C" "CPP" "CC"))
                ("cc" . ("h" "hpp"))))))

您可以调用该eassist-swith-h-cpp函数-它将处理头文件和实现文件之间的切换。您可以将此功能绑定到选定的键(C-c t在给定的挂钩中):

(defun my/c-mode-cedet-hook ()
  (local-set-key "\C-ct" 'eassist-switch-h-cpp))
(add-hook 'c-mode-common-hook 'my/c-mode-cedet-hook)
于 2013-06-07T08:29:34.393 回答