kanizaのブログ

コンピュータ、ソフトウェア、映画、音楽関連や家族のことなど、思いついたことを書きます。

EmacsからXcodeのブレークポイントを追加する

Carbon EmacsObjective-Cのコードを書きつつXcodeデバッグをしていると、Emacsで見えているファイルの行にブレークポイントを追加したくなることがよくある。そこで、AppleScript経由で現在の行をXcodeブレークポイントとして追加するEmacs Lispを作ってみた。すぐにはXcodeで該当行のマークが表示されないけど、プロジェクトのツリーにも反映されてるし、ソースを表示し直したりすればちゃんと表示される。

興味ある人は試してみてください。

(defun xcode-add-breakpoint-at-line ()
  (interactive)
  (let ((line (number-to-string (line-number-at-pos)))
	(file-path buffer-file-name))
    (do-applescript (concat
     "tell application \"Xcode\"
        activate
        tell front project
          repeat with r in file references
            set p to full path of r
            if \"" file-path "\" = p then
              set bp to make new file breakpoint with properties {line number:" line "}
              set file reference of bp to r
              set enabled of bp to true
              exit repeat
            end if
         end repeat
	end tell
     end tell"))))