yaotti's diary

Software is Eating the World

EmacsでObjective-Cを書く最低限の設定

最近iPhod touchを買ったついでにObjective-Cの勉強中.
そこでEmacsでの環境構築メモを残しとく.

以下を追加.

;; mode config
(setq auto-mode-alist
      (append '(("\\.h$" . objc-mode)
                ("\\.m$" . objc-mode))))
(require 'flymake-objc)		
  • flymake

以下をflymake-objc.elとしてload-pathの通った場所に.

(require 'flymake)

(defvar flymake-compiler "gcc")
(defvar flymake-compile-options nil)
(defvar flymake-compile-default-options (list "-Wall" "-Wextra" "-fsyntax-only"))

(defun flymake-objc-init ()
  (let* ((temp-file   (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
         (local-file  (file-relative-name
                       temp-file
                       (file-name-directory buffer-file-name)))
	 (options flymake-compile-default-options))
    (list flymake-compiler (append options (list local-file)))))

(push '("\\.m$" flymake-objc-init) flymake-allowed-file-name-masks)
(push '("\\.h$" flymake-objc-init) flymake-allowed-file-name-masks)

(add-hook 'objc-mode-hook
          '(lambda ()
	     (flymake-mode t)))

(provide 'flymake-objc)
  • yasnippet
    • ifなどをcc-modeからobjc-modeのsnippetフォルダへ移動
    • @interfaceや@implementation, #importのsnippetを書いた

例えば@interfaceのsnippet

#name : @interface class : superclass { ... } @end
# --

@interface $1 : $2
{
  $0
}

@end

こういうファイルを/path/to/snippets/text-mode/objc-mode/以下に保存する.



こんなところ.

10月24日NDAが変更され,情報交換やソースの公開が可能になったので楽しくなりそうだ.