Skip to content

Instantly share code, notes, and snippets.

@Fykec
Created November 25, 2013 03:10
Show Gist options
  • Save Fykec/7635697 to your computer and use it in GitHub Desktop.
Save Fykec/7635697 to your computer and use it in GitHub Desktop.
simple emacs config for mac
;; Yinjiaji's Emacs config in Mac OS X
;; Email: yinjiaji110@gmail.com
;;
;;Unicad
;;(load "~/.emacs.d/unicad.elc")
;;(require 'unicad)
;;ido-mode
(require 'ido)
(ido-mode t)
;;Disable Menu Bar
(menu-bar-mode -1)
;;Set up copy and paste
;;http://www.lingotrek.com/2010/12/integrate-emacs-with-mac-os-x-clipboard.html
(setq x-select-enable-clipboard t)
(defun mac-copy ()
(shell-command-to-string "pbpaste"))
(defun mac-paste (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 'mac-paste)
(setq interprogram-paste-function 'mac-copy)
;;line number display in left-margin of buffer
;(add-to-list 'load-path "~/.emacs.d/linum.el")
;(require 'linum)
;(global-linum-mode 1)
;(setq linum-format "%d ");;left a space between line number and real text
;;;;;;;;;;;;;;;;;;;;;;;Objc Related;;;;;;;;;;;;;;;;;;;;;;;
;;Auto into objc-mode
(add-to-list 'auto-mode-alist '("\\.mm?$" . objc-mode))
(add-to-list 'auto-mode-alist '("\\.h$" . objc-mode))
;;Switch between header (.h) and source (.m) file
;;-- Obj-C switch between header and source ---
(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)
(global-set-key (kbd "RET") 'newline-and-indent))
(add-hook 'objc-mode-hook 'objc-mode-customizations)
(put 'upcase-region 'disabled nil)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(scalable-fonts-allowed t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(when (eq system-type 'darwin)
;; default Latin font (e.g. Consolas)
(set-face-attribute 'default nil :family "Bitstream Vera Sans Mono")
;; default font size (point * 10)
;; WARNING! Depending on the default font,
;; if the size is not supported very well, the frame will be clipped
;; so that the beginning of the buffer may not be visible correctly.
(set-face-attribute 'default nil :height 165)
;; use specific font for Korean charset.
;; if you want to use different font size for specific charset,
;; add :size POINT-SIZE in the font-spec.
; (set-fontset-font t 'hangul (font-spec :name "NanumGothicCoding"))
;; you may want to add different for other charset in this way.
)
;;Perl config
;; M-SPC not available, window manager take it away
(global-set-key (kbd "M-'") 'just-one-space)
(global-set-key (kbd "C-M-=") 'pde-indent-dwim)
;; nearest key to dabbrev-expand
(global-set-key (kbd "M-;") 'hippie-expand)
(global-set-key (kbd "C-;") 'comment-dwim)
(global-set-key (kbd "C-c f") 'comint-dynamic-complete)
(autoload 'comint-dynamic-complete "comint" "Complete for file name" t)
(setq comint-completion-addsuffix '("/" . ""))
(setq-default indent-tabs-mode nil)
(defalias 'perl-mode 'cperl-mode)
(defun pde-perl-mode-hook ()
(abbrev-mode t)
(add-to-list 'cperl-style-alist
'("PDE"
(cperl-auto-newline . t)
(cperl-brace-offset . 0)
(cperl-close-paren-offset . -4)
(cperl-continued-brace-offset . 0)
(cperl-continued-statement-offset . 4)
(cperl-extra-newline-before-brace . nil)
(cperl-extra-newline-before-brace-multiline . nil)
(cperl-indent-level . 4)
(cperl-indent-parens-as-block . t)
(cperl-label-offset . -4)
(cperl-merge-trailing-else . t)
(cperl-tab-always-indent . t)))
(cperl-set-style "PDE"))
(global-set-key (kbd "C-c s") 'compile-dwim-compile)
(global-set-key (kbd "C-c r") 'compile-dwim-run)
(setq compilation-buffer-name-function 'pde-compilation-buffer-name)
(autoload 'compile-dwim-run "compile-dwim" "Build and run" t)
(autoload 'compile-dwim-compile "compile-dwim" "Compile or check syntax" t)
(autoload 'executable-chmod "executable"
"Make sure the file is executable.")
(defun pde-perl-mode-hook ()
;; chmod when saving
(when (and buffer-file-name
(not (string-match "\\.\\(pm\\|pod\\)$" (buffer-file-name))))
(add-hook 'after-save-hook 'executable-chmod nil t))
(set (make-local-variable 'compile-dwim-check-tools) nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment