Created
August 25, 2019 09:54
-
-
Save numb3r3/cf0835412737a112af67664c51221d90 to your computer and use it in GitHub Desktop.
emacs config
This file contains hidden or 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
(setq warning-minimum-level :emergency) | |
(setq load-prefer-newer t) | |
;; package --- smarry | |
;;; Commentary: | |
;; package 包管理 | |
(require 'package) | |
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") | |
("tromey" . "http://tromey.com/elpa/") | |
("marmalade" . "http://marmalade-repo.org/packages/") | |
("melpa" . "http://melpa.milkbox.net/packages/"))) | |
(package-initialize) | |
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp")) | |
;; 显示行号 | |
(require 'linum) | |
(global-linum-mode t) | |
;;tab | |
(setq-default indent-tabs-mode nil) | |
(setq tab-width 4 c-basic-offset 4) | |
(setq-default tab-width 4) | |
;; web development | |
(setq coffee-tab-width 2) ; coffeescript | |
(setq javascript-indent-level 2) ; javascript-mode | |
(setq js-indent-level 2) ; js-mode | |
(setq js2-basic-offset 2) ; js2-mode, in latest js2-mode, it's alias of js-indent-level | |
(setq web-mode-markup-indent-offset 2) ; web-mode, html tag in html file | |
(setq web-mode-css-indent-offset 2) ; web-mode, css in html file | |
(setq web-mode-code-indent-offset 2) ; web-mode, js code in html file | |
(setq css-indent-offset 2) ; css-mode | |
;; 括号匹配 | |
(setq show-paren-delay 0) | |
(show-paren-mode t) | |
(setq show-paren-style 'parenthesis) | |
;; 括号匹配 | |
(setq show-paren-delay 0) | |
(show-paren-mode t) | |
(setq show-paren-style 'parenthesis) | |
;; 缩写yes no | |
(fset 'yes-or-no-p 'y-or-n-p) | |
;; 舒服的滚动 | |
(setq scroll-step 1 | |
scroll-margin 3 | |
scroll-conservatively 10000) | |
;; 关闭自动保存 | |
(setq auto-save-mode nil) | |
(setq auto-save-default nil) | |
;; 语法高亮 | |
(global-font-lock-mode t) | |
(setq auto-save-default nil) | |
;; 文件搜索 | |
(require 'ido) | |
(ido-mode t) | |
(setq ido-enable-flex-matching t) | |
;; smex | |
(autoload 'smex "smex" | |
"Smex is a M-x enhancement for Emacs, it provides a convenient interface to | |
your recently and most frequently used commands.") | |
(global-set-key (kbd "M-x") 'smex) | |
(put 'upcase-region 'disabled nil) | |
;; 补全 | |
(require 'auto-complete-config) | |
(ac-config-default) | |
(ac-set-trigger-key nil) | |
(setq ac-auto-start t) | |
(define-key ac-complete-mode-map "\t" nil) | |
;; 去除临时文件 | |
(setq make-backup-files nil) | |
(setq-default make-backup-files nil) | |
(setq auto-save-mode nil) | |
(setq auto-save-default nil) | |
(setq create-lockfiles nil) | |
;; 超过100字自动换行 | |
(setq default-fill-column 120) | |
;; 去除空格 | |
(add-hook 'before-save-hook 'delete-trailing-whitespace) | |
;; 结尾新增空行 | |
(add-hook 'enh-ruby-mode-hook (lambda () (local-set-key "\r" 'newline-and-indent))) | |
;; 不显示tutorial | |
(setq inhibit-startup-message t) | |
(setq initial-scratch-message "") | |
;; 同名文件提示 | |
(require 'uniquify) | |
(setq uniquify-buffer-name-style 'forward) | |
(menu-bar-mode -1) | |
;;golang | |
(require 'go-mode) | |
(require 'go-mode-autoloads) | |
(add-hook 'before-save-hook 'gofmt-before-save) | |
(add-hook 'go-mode-hook | |
(lambda () | |
(add-hook 'before-save-hook 'gofmt-before-save) | |
(setq tab-width 4) | |
(setq indent-tabs-mode 1))) | |
(setq gofmt-show-errors nil) | |
(add-to-list 'ac-modes 'go-mode) | |
;;主题 | |
(load-theme 'monokai t) | |
;; smartparens | |
(require 'smartparens-config) | |
(show-smartparens-global-mode t) | |
;; org mode增加状态 | |
(setq org-todo-keywords | |
'((sequence "TODO" "|" "DONE" "ABANDON"))) | |
(setq org-startup-indented t) | |
;; makrdown-model | |
(autoload 'markdown-mode "markdown-mode" | |
"Major mode for editing Markdown files" t) | |
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode)) | |
(add-to-list 'auto-mode-alist '("README\\.md\\'" . markdown-mode)) | |
;;window-numbering | |
(require 'window-numbering) | |
(window-numbering-mode 1) | |
;; copy file-name to clipboard | |
(defun copy-file-name () | |
"Copy the current buffer file name to the clipboard." | |
(interactive) | |
(let ((filename (if (equal major-mode 'dired-mode) | |
default-directory | |
(file-name-nondirectory buffer-file-name)))) | |
(when filename | |
(kill-new filename) | |
(message "Copied buffer file name '%s' to the clipboard." filename)))) | |
;; delete current buffer file | |
(defun delete-current-file () | |
"Delete the current buffer file" | |
(interactive) | |
(when (yes-or-no-p "sure?") | |
(delete-file (buffer-file-name (current-buffer))) | |
(kill-buffer (current-buffer)) | |
(message "delete and kill current buffer file") | |
) | |
) | |
;; recreate scratch buffer after kill it | |
(save-excursion | |
(set-buffer (get-buffer-create "*scratch*")) | |
(lisp-interaction-mode) | |
(make-local-variable 'kill-buffer-query-functions) | |
(add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)) | |
(defun kill-scratch-buffer () | |
;; The next line is just in case someone calls this manually | |
(set-buffer (get-buffer-create "*scratch*")) | |
;; Kill the current (*scratch*) buffer | |
(remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer) | |
(kill-buffer (current-buffer)) | |
;; Make a brand new *scratch* buffer | |
(set-buffer (get-buffer-create "*scratch*")) | |
(lisp-interaction-mode) | |
(make-local-variable 'kill-buffer-query-functions) | |
(add-hook 'kill-buffer-query-functions 'kill-scratch-buffer) | |
;; Since we killed it, don't let caller do that. | |
nil) | |
;;退出时需要确认 | |
;; (setq confirm-kill-emacs 'y-or-n-p) | |
;;emacs 配置文件使用lisp-mode | |
(add-to-list 'auto-mode-alist '("\\emacs\\'" . emacs-lisp-mode)) | |
;;自动跟踪link | |
(setq vc-follow-symlinks t) | |
;;rename current file | |
(defun rename-current-file (new-name) | |
"Renames both current buffer and file it's visiting to NEW-NAME." | |
(interactive "sNew name: ") | |
(let ((name (buffer-name)) | |
(filename (buffer-file-name))) | |
(if (not filename) | |
(message "Buffer '%s' is not visiting a file!" name) | |
(if (get-buffer new-name) | |
(message "A buffer named '%s' already exists!" new-name) | |
(progn | |
(rename-file name new-name 1) | |
(rename-buffer new-name) | |
(set-visited-file-name new-name) | |
(set-buffer-modified-p nil)))))) | |
;;ace-jump | |
(require 'ace-jump-mode) | |
(eval-after-load "ace-jump-mode" | |
'(ace-jump-mode-enable-mark-sync)) | |
(define-key global-map (kbd "M-s") 'ace-jump-line-mode) | |
(define-key global-map (kbd "C-h") 'ace-jump-mode) | |
(define-key global-map (kbd "C-x SPC") 'ace-jump-mode-pop-mark) | |
(require 'autopair) | |
(defvar autopair-modes '(go-mode python-mode web-mode)) | |
(defun turn-on-autopair-mode () (autopair-mode 1)) | |
(dolist (mode autopair-modes) (add-hook (intern (concat (symbol-name mode) "-hook")) 'turn-on-autopair-mode)) | |
;;自动括号 | |
(require 'paredit) | |
(defadvice paredit-mode (around disable-autopairs-around (arg)) | |
"Disable autopairs mode if paredit-mode is turned on" | |
ad-do-it | |
(if (null ad-return-value) | |
(autopair-mode 1) | |
(autopair-mode 0) | |
)) | |
(ad-activate 'paredit-mode) | |
;;python | |
(require 'flymake-python-pyflakes) | |
(add-hook 'python-mode-hook 'flymake-python-pyflakes-load) | |
(add-hook 'python-mode-hook 'guess-style-guess-tabs-mode) | |
(add-hook 'python-mode-hook (lambda () | |
(guess-style-guess-tab-width))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment