This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; A bunch of functions that help me (mchinen) | |
;; Parts taken from interwebs. | |
;; some documentation at michaelchinen.com | |
;; | |
;;auto-revert since I work on several computers on the same file. | |
(global-auto-revert-mode) | |
(menu-bar-mode nil) | |
(menu-bar-mode -1) | |
(setq-default truncate-lines nil) | |
(setq word-wrap t) | |
(setq-default indent-tabs-mode nil) | |
(setq-default tab-width 4) | |
(setq indent-line-function 'insert-tab) | |
(setq-default c-basic-offset 4) | |
(require 'find-file) ;; for the "cc-other-file-alist" variable | |
(nconc (cadr (assoc "\\.h\\'" cc-other-file-alist)) '(".m" ".mm")) | |
;; allow replace select-region with yank/delete etc | |
(delete-selection-mode 1) | |
(setq c-mode-hook | |
(function (lambda () | |
(setq indent-tabs-mode nil) | |
(setq c-indent-level 4)))) | |
(setq c++-mode-hook | |
(function (lambda () | |
(setq indent-tabs-mode nil) | |
(setq c-indent-level 4)))) | |
(add-hook 'objc-mode-hook | |
(lambda () | |
(set (make-local-variable 'cc-other-file-alist) '(("\\.m\\'" (".h")) ("\\.mm\\'" (".h")) ("\\.h\\'" (".m" ".mm" ".c" ".cpp")))))) | |
;; search in other directories for header | |
(setq cc-search-directories '("." "../include" ".." "/usr/include" "/usr/local/include/*" "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs" | |
"/System/Library/Frameworks" "/Library/Frameworks")) | |
;; | |
;; ===== Some basic XCode Integration ===== | |
;; | |
(setq auto-mode-alist | |
(cons '("\\.m$" . objc-mode) auto-mode-alist)) | |
(add-to-list 'auto-mode-alist '("\\.mm\\'" . objc-mode)) | |
;;(setq auto-mode-alist | |
;; (cons '("\\.mm$" . objc-mode) auto-mode-alist)) | |
;; | |
;; ===== Opening header files ===== | |
;; Allows to choose between objc-mode, c++-mode and c-mode | |
(defun bh-choose-header-mode () | |
(interactive) | |
(if (string-equal (substring (buffer-file-name) -2) ".h") | |
(progn | |
; ;; OK, we got a .h file, if a .m file exists we'll assume it's | |
; ; an objective c file. Otherwise, we'll look for a .cpp file. | |
; ; if there's no matching .m or .cpp, then we assume objc as it might be a protocol. | |
(let ((dot-m-file (concat (substring (buffer-file-name) 0 -1) | |
"m")) | |
(dot-mm-file (concat (substring (buffer-file-name) 0 -1) | |
"mm")) | |
(dot-cpp-file (concat (substring (buffer-file-name) 0 | |
-1) "cpp"))) | |
(if (or (file-exists-p dot-m-file) (file-exists-p dot-mm-file)) | |
(progn | |
(objc-mode) | |
) | |
(if (file-exists-p dot-cpp-file) | |
(c++-mode) | |
(objc-mode) | |
) | |
) | |
) | |
) | |
) | |
) | |
(add-hook 'find-file-hook 'bh-choose-header-mode) | |
(global-set-key (kbd "M-[ 5 d") 'windmove-left) | |
(global-set-key (kbd "M-[ 5 c") 'windmove-right) | |
(global-set-key (kbd "M-[ 5 a") 'windmove-up) | |
(global-set-key (kbd "M-[ 5 b") 'windmove-down) | |
;; ctrl-arrow window switching - you need to enable this in mac terminal somehow | |
;; press ctrl-x ctrl-o to swap to a header | |
(global-set-key (kbd "C-x C-o") 'ff-find-other-file) | |
;split 6 way | |
(fset 'split6 | |
"\C-x3\C-x3\C-x+\C-x2\C-[[1;3C\C-x2\C-[[1;3C\C-x2") | |
; mac copy paste | |
(defun copy-from-osx () | |
(shell-command-to-string "pbpaste")) | |
(defun paste-to-osx (text &optional push) | |
(let ((process-connection-type nil)) | |
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy"))) | |
(process-send-string proc text) | |
(process-send-eof proc)))) | |
(setq interprogram-cut-function 'paste-to-osx) | |
(setq interprogram-paste-function 'copy-from-osx) | |
;apportable | |
(fset 'app | |
(lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("#ifdef APPORTABLEOBOB#endif | |
" 0 "%d")) arg))) | |
(global-set-key (kbd "C-x C-a") 'app) | |
(put 'narrow-to-region 'disabled nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment