Create a gist now

Instantly share code, notes, and snippets.

@mchinen /my .emacs file Secret
Last active Aug 29, 2015

What would you like to do?
;; A bunch of functions that help me (mchinen)
;; Parts taken from interwebs.
;; some documentation at
;;auto-revert since I work on several computers on the same file.
(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/"
"/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 ()
(if (string-equal (substring (buffer-file-name) -2) ".h")
; ;; 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)
(dot-mm-file (concat (substring (buffer-file-name) 0 -1)
(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))
(if (file-exists-p dot-cpp-file)
(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
; 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)
(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