资源说明:My emacs configuration
#+TITLE: Emacs Configuration #+AUTHOR: Trevor Bernard #+EMAIL: trevor@bernard.gg #+LANGUAGE: en * Configuration #+BEGIN_QUOTE This is my emacs, there are many like it, but this one is mine... #+END_QUOTE ** Getting Started The very first thing you need to have installed is a recent version of Emacs. I believe the minimum supported version is Emacs 24 otherwise you'll have to install =package.el= and you're on your own. I strongly suggest you remap your cap locks key to control to help reduce the onset of Emacs pinky. I even go further and have a new key binding for =M-x=, so you are hitting =Ctrl= instead of =Alt=. You will need the following already installed for this configuration to run correctly. Install the [[https://github.com/tonsky/FiraCode][Fira Code Retina]] font because it's beautiful and makes for a wonderful font. You will need ispell installed in order to user Flymake mode. Clojure mode requires [[https://leiningen.org/][leiningen]]. ** Emacs Initialization I use melpa and melpa stable for my packages. #+BEGIN_SRC emacs-lisp (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) #+END_SRC I don't like my cider to be bleeding edge since it's caused compatability problems in the past so pin it to melpa-stable. #+BEGIN_SRC emacs-lisp (add-to-list 'package-pinned-packages '(cider . "melpa-stable") t) #+END_SRC Install my packages if they aren't installed. #+BEGIN_SRC emacs-lisp (package-initialize) (when (not package-archive-contents) (package-refresh-contents)) (defvar my-packages '(ag bnf-mode cider clj-refactor clojure-mode company dockerfile-mode dracula-theme eclim flycheck-plantuml gradle-mode htmlize magit markdown-mode paredit plantuml-mode projectile projectile-rails protobuf-mode rainbow-delimiters robe rvm yaml-mode) "A list of packages to ensure are installed at launch.") (dolist (p my-packages) (when (not (package-installed-p p)) (package-install p))) #+END_SRC I like to have my Emacs clean, chrisp and minimal. Removing the menu bar, tool bar, and scroll bar frees some space and it helps remove dependency on the mouse. Protip: Learn the Emacs navigation key strokes until they are second nature. You can thank me later. #+BEGIN_SRC emacs-lisp (setq inhibit-startup-message t) (dolist (mode '(menu-bar-mode tool-bar-mode scroll-bar-mode)) (when (fboundp mode) (funcall mode -1))) (when window-system (set-frame-font "Fira Code Retina 16" nil t) (load-theme 'dracula t)) #+END_SRC ** Personal Dats me. #+BEGIN_SRC emacs-lisp (setq user-full-name "Trevor Bernard" user-mail-address "trevor@bernard.gg") #+END_SRC ** Key Bindings Ignore minimize functionality when you're in a GUI because it's very annoying to accidently minimize your window. #+BEGIN_SRC emacs-lisp (when window-system (global-set-key "\C-z" 'ignore) (global-set-key "\C-x\C-z" 'ignore)) #+END_SRC *** Invoke M-x without the Alt key M-x is one of the most wildly used key combinations in Emacs but it's also the most annoying. You have to scrunch your left thumb and fore finger in the most uncomfortable RSI inducing way. I choose to rebind M-x to C-x C-m because of an article Steve Yegge wrote called: [[https://sites.google.com/site/steveyegge2/effective-emacs][Effective Emacs]]. This allows you to keep your fingers on the home row if you have caps lock mapped to control. With some practice, it will become intuitive. #+BEGIN_SRC emacs-lisp (global-set-key "\C-x\C-m" 'execute-extended-command) (global-set-key "\C-c\C-m" 'execute-extended-command) #+END_SRC * Preferences ** Global Preferences #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/.emacs.d/lisp/") (set-fringe-mode 10) ; breathing room (setq make-backup-files nil) ; stop creating backup~ files (setq auto-save-default nil) ; stop creating #autosave# files (setq interprogram-paste-function 'x-selection-value) ; (global-auto-revert-mode t) ; Auto revert buffers (ido-mode 1) (column-number-mode 1) ; Show column number (delete-selection-mode 1) ; Allow delete of selection (fset 'yes-or-no-p 'y-or-n-p) ; Shorten confirmation message (global-font-lock-mode 1) ; Syntax Highlighting (show-paren-mode 1) ; Highlight parenthesis ;; Highlight selected Regions (transient-mark-mode 1) ;; Make pgup/dn remember current line (setq scroll-preserve-screen-position t) #+END_SRC Use spaces in favour of tabs because they are evil. But when there are tabs show them as 8 spaces. #+BEGIN_SRC emacs-lisp (setq-default indent-tabs-mode nil) (setq-default c-basic-offset 4) (setq-default tab-width 8) #+END_SRC Limit the default fill mode to 80 characters #+BEGIN_SRC emacs-lisp (setq-default set-fill-column 80) (setq-default truncate-lines nil) #+END_SRC Ignore the stupid ring bell feature. #+BEGIN_SRC emacs-lisp (setq ring-bell-function 'ignore) #+END_SRC Allow functions without issuing warnings #+BEGIN_SRC emacs-lisp (put 'downcase-region 'disabled nil) (put 'narrow-to-region 'disabled nil) (put 'upcase-region 'disabled nil) #+END_SRC * Mac specific configuration #+BEGIN_SRC emacs-lisp (defun set-exec-path-from-shell-PATH () (let ((path-from-shell (shell-command-to-string "$SHELL -i -c 'echo $PATH'"))) (setenv "PATH" path-from-shell) (setq exec-path (split-string path-from-shell path-separator)))) (defun my-mac-config () ;; Mac's ls doesn't support --dired (setq dired-use-ls-dired nil) ;; make sure path is correct when launched as application (set-exec-path-from-shell-PATH) (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin")) (setq exec-path (append exec-path '("/usr/local/bin"))) ;; Move to trash when deleting stuff (setq delete-by-moving-to-trash t trash-directory "~/.Trash/emacs") ;; Don't open files from the workspace in a new frame (setq ns-pop-up-frames nil) ;; Use aspell for spell checking: brew install aspell --lang=en (setq ispell-program-name "/usr/local/bin/aspell") ;; Open up links in Google Chrome (setq browse-url-browser-function 'browse-url-default-macosx-browser)) (when (equal system-type 'darwin) (my-mac-config)) #+END_SRC * Programming Languages Bind projectile to =C-c p= and enable by default. #+begin_src emacs-lisp (setq projectile-keymap-prefix (kbd "C-c p")) (projectile-mode) #+end_src ** Magit ** Clojure #+BEGIN_SRC emacs-lisp (require 'cider) (require 'clojure-mode) (require 'company) (setq nrepl-log-messages t) (setq cider-repl-use-clojure-font-lock t) (setq cider-repl-display-help-banner nil) (defun my-cider-repl-mode-hook () (company-mode 1) (paredit-mode 1) (rainbow-delimiters-mode 1)) (defun my-cider-mode-hook () (company-mode 1) (eldoc-mode 1)) (defun my-clojure-mode-hook () (setq show-trailing-whitespace 1) (setq clojure-align-forms-automatically t) (clj-refactor-mode 1) (rainbow-delimiters-mode 1) (linum-mode t) (paredit-mode 1) (subword-mode t) (eldoc-add-command 'paredit-backward-delete 'paredit-close-round)) (add-hook 'cider-repl-mode-hook 'my-cider-repl-mode-hook) (add-hook 'cider-mode-hook 'my-cider-mode-hook) (add-hook 'clojure-mode-hook 'my-clojure-mode-hook) #+END_SRC I have long since used this key binding to jack into a repl. My fingers are programmed this way. #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-c C-j") 'cider-jack-in) #+END_SRC When you hit =f3= at the end of the sexp in Clojure, it will copy and evaluate the function into the current repl. I no longer use this function but it might be useful to someone eventually. #+BEGIN_SRC emacs-lisp (defun my-last-expression () "Return the last sexp." (buffer-substring-no-properties (save-excursion (backward-sexp) (point)) (point))) (defun cider-execute-in-current-repl (expr) (if (not (get-buffer (cider-current-connection))) (message "No active nREPL connection.") (progn (set-buffer (cider-current-repl)) (goto-char (point-max)) (insert expr) (cider-repl-return)))) (defun cider-eval-expression-at-point-in-repl () (interactive) (let ((form (my-last-expression))) ;; Eat white (while (string-match "\\`\s+\\|\n+\\'" form) (setq form (replace-match "" t t form))) (cider-execute-in-current-repl form))) (eval-after-load 'cider-repl-mode-hook '(local-set-key '[f3] 'cider-eval-expression-at-point-in-repl)) #+END_SRC ** ClojureScript This is required for re-frame cider intergration. #+BEGIN_SRC elisp (setq cider-cljs-lein-repl "(do (require 'figwheel-sidecar.repl-api) (figwheel-sidecar.repl-api/start-figwheel!) (figwheel-sidecar.repl-api/cljs-repl))") #+END_SRC ** Elisp #+BEGIN_SRC emacs-lisp (defun my-emacs-lisp-mode-hook () (paredit-mode 1) (eldoc-mode 1)) (add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook) #+END_SRC ** Paredit Some handy dandy paredit shortcuts On mac ^-left and ^-right are bought to Misson Control. Go to System Preferences > Keyboard > Shortcuts > Mission Control and change the settings for "Move left a space" and "Move right a space" or disable them completely. #+BEGIN_SRC emacs-lisp (eval-after-load 'paredit '(progn (define-key paredit-mode-map (kbd "C-") 'paredit-forward-slurp-sexp) (define-key paredit-mode-map (kbd "C- ") 'paredit-forward-barf-sexp) (define-key paredit-mode-map (kbd "C- ") 'paredit-backward-kill-word))) #+END_SRC ** PlantUML Easily create beautiful UML Diagrams from simple textual description. #+BEGIN_SRC elisp (add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode)) (add-to-list 'auto-mode-alist '("\\.puml\\'" . plantuml-mode)) (setq plantuml-default-exec-mode 'jar) (setq plantuml-jar-path (expand-file-name "~/plantuml.jar")) (add-to-list 'org-src-lang-modes '("plantuml" . plantuml)) #+END_SRC ** Org Mode I almost exclusively use =C-j= in place of hitting the enter key. The problem is that it's bound to =org-return-indent= function. This is very annoying in when you are in =org-mode=. So instead of trying to remap my brain, I'll remap it to =newline=. #+BEGIN_SRC emacs-lisp (defun my-org-mode-hook () (turn-on-auto-fill) (define-key org-mode-map (kbd "C-j") 'org-return) (require 'ox-confluence) ;; export to confluence (org-babel-do-load-languages 'org-babel-load-languages '((clojure . t) (plantuml . t) (ruby . t) (shell . t)))) (add-hook 'org-mode-hook 'my-org-mode-hook) #+END_SRC ** JavaScript #+BEGIN_SRC emacs-lisp (defun my-js-mode-hook () (setq js-indent-level 2)) (add-hook 'javascript-mode 'my-js-mode-hook) (add-hook 'js2-mode 'my-js-mode-hook) #+END_SRC ** CSS #+BEGIN_SRC emacs-lisp (autoload 'css-mode "css-mode" nil t) (defun my-css-mode-hook () (setq css-indent-level 2) (setq css-indent-offset 2)) (add-hook 'css-mode-hook 'my-css-mode-hook) #+END_SRC ** Markdown #+BEGIN_SRC emacs-lisp (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 '("\\.markdown\\'" . markdown-mode)) (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)) (defun my-markdown-hook () (auto-fill-mode t) (flyspell-mode t)) (add-hook 'markdown-mode-hook 'my-markdown-hook) #+END_SRC ** Git Use diff-mode when editing a git commit message #+BEGIN_SRC emacs-lisp (add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . diff-mode)) #+END_SRC ** Python #+BEGIN_SRC emacs-lisp ;; (elpy-enable) ;; (add-hook 'python-mode-hook 'elpy-enable) #+END_SRC ** Ruby Since starting at Introhive, I wanted to continue using Emacs as my primary editor but alas, I've been primary programming in RubyMine... For now... #+begin_src emacs-lisp (defun my-ruby-mode-hook () (robe-mode) (global-company-mode t) (push 'company-robe company-backends) (rvm-activate-corresponding-ruby) (projectile-rails)) (add-hook 'ruby-mode 'my-ruby-mode-hook) #+end_src ** Java #+BEGIN_SRC elisp (require 'eclim) (setq eclimd-autostart t) (defun my-java-mode-hook () (eclim-mode t) ) (add-hook 'java-mode-hook 'my-java-mode-hook) #+END_SRC
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。