Skip to content

Instantly share code, notes, and snippets.

@lumin3000
Created January 28, 2012 04:48
Show Gist options
  • Select an option

  • Save lumin3000/1692678 to your computer and use it in GitHub Desktop.

Select an option

Save lumin3000/1692678 to your computer and use it in GitHub Desktop.
my init.el for osx emacs 2011
;;Emacs outshines all other editing software in approximately the same way that the noonday sun does the stars.
;;It is not just bigger and brighter; it simply makes everything else vanish.
;; -Neal Stephenson, "In the Beginning was the Command Line"
;;配置路径
(add-to-list 'load-path "~/.emacs.d")
;;显示相关设置
;;字体
(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.
'(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 140 :width normal :foundry "unknown" :family "Monospace")))))
;;光标
(setq-default cursor-type 'bar)
;;最大化,gnu/linux下可用
;; (when (eq system-type 'gnu/linux)
;; (defun my-maximized ()
;; (interactive)
;; (x-send-client-message
;; nil 0 nil "_NET_WM_STATE" 32
;; '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
;; (interactive)
;; (x-send-client-message
;; nil 0 nil "_NET_WM_STATE" 32
;; '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
;; (my-maximized))
;;摘掉菜单,工具栏和滚动条
;;M-` or F10 菜单唤出热键
(toggle-menu-bar-mode-from-frame)
(toggle-tool-bar-mode-from-frame)
(toggle-scroll-bar -1)
(tool-bar-mode nil)
;;开启菜单
(global-set-key (kbd "C-<f10>") 'menu-bar-mode)
;;全屏,为保证linux和darwin兼容性,使用统一全屏函数名称
;;darwin下的全屏使用 http://unknownplace.org/memo/2009/12/17/1/
(when (eq system-type 'gnu/linux)
(defun ns-toggle-fullscreen ()
(interactive)
(shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen")))
(global-set-key (kbd "M-RET") 'ns-toggle-fullscreen)
;;显示行号
(global-linum-mode t)
;;透明
(set-frame-parameter (selected-frame) 'alpha '(90 50))
(add-to-list 'default-frame-alist '(alpha 90 50))
;;字体尺寸变化
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
;;杂项
;;不显示起始提示信息(包括scratch)
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
;;视觉响铃
(setq visiable-bell t)
;;高亮选中文本
(setq-default transient-mark-mode t)
;;显示列号
(column-number-mode t)
;;显示当前时间
(display-time)
;;一打开就起用 text 模式
(setq default-major-mode 'text-mode)
;;dired模式中不显示隐藏文件
(setq dired-listing-switches "-l")
;;为文件最后加上换行
(setq require-final-newline t)
;;文件相关
;;对文件不进行备份
(setq-default make-backup-files nil)
;;记录最近查看的文件,ido相关
(recentf-mode 1)
(defun recentf-ido-find-file ()
"Find a recent file using ido."
(interactive)
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
(when file
(find-file file))))
(global-set-key (kbd "C-x f") 'recentf-ido-find-file)
;;记录上次访问文件的光标位置
(require 'saveplace)
(setq-default save-place t)
;;buffer相关
;;解决buffer重名的问题
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;;bury-buffer
(global-set-key (kbd "C-x y") 'bury-buffer)
;;ibuffer代替buffer列表
(global-set-key (kbd "C-x C-b") 'ibuffer)
;;frame相关
(defun pre-other-window ()
"Find the previous window."
(interactive)
(other-window -1)
)
(global-set-key (kbd "C-x M-o") 'pre-other-window)
;;和系统剪贴板通用
(setq x-select-enable-clipboard t)
;;使用强大的hippie做自动完成
;; (global-set-key (kbd "M-/") 'hippie-expand)
;; (delete 'try-expand-line hippie-expand-try-functions-list)
;; (delete 'try-expand-list hippie-expand-try-functions-list)
;;插入当前时间
(defun insert-date ()
"Insert a time-stamp according to locale's date and time format."
(interactive)
(insert (format-time-string "%c" (current-time))))
;;图片相关
;;自动显示图片
(auto-image-file-mode)
;;网络相关
;;linux下用ff浏览
(when (eq system-type 'gnu/linux)
(global-set-key (kbd "C-c b") 'browse-url-firefox))
(when (eq system-type 'darwin)
(global-set-key (kbd "C-c b") 'browse-url-default-macosx-browser))
;;抓页面源代码,这个抓回来的不能正常显示中文,只显示unicode,解决方法待研究
(require 'thingatpt)
(defun view-url ()
"Open a new buffer containing the contents of URL."
(interactive)
(let* ((default (thing-at-point-url-at-point))
(url (read-from-minibuffer "URL: " default)))
(switch-to-buffer (url-retrieve-synchronously url))
(rename-buffer url t)
(cond ((search-forward "<?xml" nil t) (xml-mode))
((search-forward "<html" nil t) (html-mode)))))
(global-set-key (kbd "C-c C-b") 'view-url)
;;通用编程相关
;;自动提示配对的括号
(show-paren-mode 1)
;;提示文件尾的空行
(set-default 'indicate-empty-lines t)
;;不允许用tab做缩进
(set-default 'indent-tabs-mode nil)
;;快捷开启空格显示模式
(global-set-key (kbd "C-c SPC") 'whitespace-mode)
;;定制编辑区良好缩进
(defun untabify-buffer ()
(interactive)
(untabify (point-min) (point-max)))
(defun indent-buffer ()
(interactive)
(indent-region (point-min) (point-max)))
(defun cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
(interactive)
(indent-buffer)
(untabify-buffer)
(delete-trailing-whitespace))
(global-set-key (kbd "C-c n") 'cleanup-buffer)
;;用正则排列行
(global-set-key (kbd "C-x \\") 'align-regexp)
;;归并到上一行
(global-set-key (kbd "C-x ^") 'join-line)
;;新建下一行并缩进
(defun next-newline ()
(interactive)
(move-end-of-line nil)
(newline-and-indent))
(global-set-key (kbd "C-S-j") 'next-newline)
;;新建上一行并缩进
(defun last-newline ()
(interactive)
(forward-line -1)
(move-end-of-line nil)
(newline-and-indent))
(global-set-key (kbd "C-M-j") 'last-newline)
;;找到isearch匹配的部分
(define-key isearch-mode-map (kbd "C-o")
(lambda () (interactive)
(let ((case-fold-search isearch-case-fold-search))
(occur (if isearch-regexp isearch-string (regexp-quote isearch-string))))))
;;ido mode
(ido-mode t)
(setq ido-enable-prefix nil
ido-enable-flex-matching t
ido-create-new-buffer 'always
ido-use-filename-at-point 'guess
ido-max-prospects 10)
(add-to-list 'load-path "~/.emacs.d/vendor/textmate.el")
(require 'textmate)
(textmate-mode)
(add-to-list 'load-path "~/.emacs.d/vendor/coffee-mode")
(require 'coffee-mode)
(add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode))
(add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode))
(defun coffee-custom ()
"coffee-mode-hook"
(set (make-local-variable 'tab-width) 2))
(add-hook 'coffee-mode-hook
'(lambda() (coffee-custom)))
(require 'sr-speedbar)
(setq sr-speedbar-right-side nil)
(setq sr-speedbar-width 30)
(setq speedbar-show-unknown-files t)
(setq dframe-update-speed t) ; prevent the speedbar to update the current state, since it is always changing
;;el-get: https://github.com/dimitri/el-get
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
(unless (require 'el-get nil t)
(url-retrieve
"https://raw.github.com/dimitri/el-get/master/el-get-install.el"
(lambda (s)
(end-of-buffer)
(eval-print-last-sexp))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment