Skip to content

Instantly share code, notes, and snippets.

@kirankulkarni
Created October 12, 2012 22:29
Show Gist options
  • Save kirankulkarni/3881996 to your computer and use it in GitHub Desktop.
Save kirankulkarni/3881996 to your computer and use it in GitHub Desktop.
Switching between header and source file in objective-C
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment