Last active
November 30, 2017 05:46
-
-
Save Pooh3Mobi/44457184d0291e881018f70e2c6cac4a to your computer and use it in GitHub Desktop.
emacs setting for clojure
This file contains 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; general | |
;;; | |
;;; setup language env | |
(set-language-environment "UTF-8") | |
;;; setup your user-emacs-directory | |
(let* ((user-init-dir (file-name-as-directory (or (getenv "EMACS_USER_DIRECTORY") | |
user-emacs-directory)))) | |
(setq user-emacs-directory user-init-dir)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; setup package.el | |
;;; | |
(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) | |
;; (add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/")) | |
(package-initialize) | |
(unless package-archive-contents (package-refresh-contents)) | |
(when (not (require 'use-package nil t)) | |
(package-install 'use-package)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; basic configurations | |
;;; | |
;;; enable use-package | |
(eval-when-compile | |
(require 'use-package)) | |
(require 'diminish) | |
(require 'bind-key) | |
(require 'zenburn-theme) | |
(setq use-package-always-ensure t) | |
(setq use-package-always-pin "melpa-stable") | |
(setq use-package-verbose t) | |
;;; load your preferred theme | |
(use-package zenburn-theme | |
:if window-system | |
:config | |
(load-theme 'solarized-dark t)) | |
;;; set up exec-path | |
(use-package exec-path-from-shell | |
:if (memq window-system '(mac ns x)) | |
:config | |
(exec-path-from-shell-initialize)) | |
;;; global keymap | |
(use-package bind-key | |
:config | |
(bind-keys :map global-map | |
("C-h" . delete-backward-char))) | |
(use-package mykie | |
:config | |
(setq mykie:use-major-mode-key-override t) | |
(mykie:initialize)) | |
;;; happy (((()))) !!! | |
(use-package paren | |
:init | |
(setq show-paren-style 'parenthesis) | |
(show-paren-mode 1)) | |
;;; yasnippet | |
(use-package yasnippet | |
:bind (:map yas-minor-mode-map | |
("<tab>" . nil) | |
("TAB" . nil) | |
("C-i" . nil) | |
("C-o" . yas-expand)) | |
:config | |
(yas-global-mode 1)) | |
;;; comapany-mode! | |
(use-package company | |
:bind (:map company-mode-map | |
("C-i" . company-complete) | |
:map company-active-map | |
("C-n" . company-select-next) | |
("C-p" . company-select-previous) | |
("C-s" . company-search-words-regexp) | |
("C-h" . nil) | |
:map company-search-map | |
("C-n" . company-select-next) | |
("C-p" . company-select-previous) | |
("C-h" . nil)) | |
:config | |
(setq company-idle-delay 0.1 | |
company-minimum-prefix-length 2 | |
company-selection-wrap-around t)) | |
;;; magit | |
(use-package magit | |
:bind (("C-x g" . magit-status))) | |
(use-package subword | |
:commands subword-mode) | |
;;; answering just 'y' or 'n' will do | |
(defalias 'yes-or-no-p 'y-or-n-p) | |
;;; turn off graphical user interface if you want | |
;; (dolist (mode '(menu-bar-mode tool-bar-mode scroll-bar-mode)) | |
;; (when (fboundp mode) (funcall mode -1))) | |
;;; some useful settings | |
(setq visible-bell t | |
font-lock-maximum-decoration t | |
truncate-partial-width-windows nil | |
echo-keystrokes 0.1 | |
create-lockfiles nil | |
;; disable to buckup funciton | |
backup-inhibited t | |
delete-auto-save-files t | |
;; completion ignore case (lower/upper) | |
completion-ignore-case t | |
read-file-name-completion-ignore-case t | |
inhibit-startup-message t) | |
;; show me empty lines after buffer end | |
(set-default 'indicate-empty-lines t) | |
(setq-default indicate-buffer-boundaries 'right) | |
(setq uniquify-buffer-name-style 'post-forward) | |
;; whitespace | |
(use-package whitespace | |
:defer t | |
:config | |
(setq whitespace-style '(face | |
trailing | |
tabs | |
spaces | |
empty | |
space-mark | |
tab-mark)) | |
(setq whitespace-display-mappings | |
'((space-mark ?\u3000 [?\u25a1]) | |
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t]))) | |
(setq whitespace-space-regexp "\\(\u3000+\\)") | |
(global-whitespace-mode 1) | |
(setq-default tab-width 4 indent-tabs-mode nil)) | |
;;; cleanup whitespace before file save | |
(add-hook 'before-save-hook 'whitespace-cleanup) | |
;;; modeline | |
(setq display-time-string-forms | |
'((format | |
"%s/%s(%s) %s:%s" month day dayname 24-hours minutes)) | |
line-number-mode t | |
column-number-mode t) | |
(display-time-mode 1) | |
;; http://flex.phys.tohoku.ac.jp/texi/eljman/eljman_142.html | |
(setq-default | |
mode-line-format | |
'("" | |
mode-line-mule-info | |
mode-line-modified | |
" " | |
mode-line-buffer-identification | |
" / " | |
(line-number-mode "L%l ") | |
(column-number-mode "C%c ") | |
(-3 . "%p") | |
" / " | |
mode-name | |
minor-mode-alist "%n" mode-line-process | |
" / " | |
global-mode-string | |
)) | |
(setq-default | |
header-line-format | |
'("" | |
(:propertize (:eval (shorten-directory default-directory 30)) | |
face mode-line-folder-face) | |
(:propertize "%b" | |
face mode-line-filename-face))) | |
(defun shorten-directory (dir max-length) | |
"Show up to `max-length' characters of a directory name `dir'." | |
(let ((path (reverse (split-string (abbreviate-file-name dir) "/"))) | |
(output "")) | |
(when (and path (equal "" (car path))) | |
(setq path (cdr path))) | |
(while (and path (< (length output) (- max-length 4))) | |
(setq output (concat (car path) "/" output)) | |
(setq path (cdr path))) | |
(when path | |
(setq output (concat ".../" output))) | |
output)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; helm | |
;;; | |
(use-package helm | |
:bind (("M-x" . helm-M-x) | |
:map helm-map | |
("C-h" . nil)) | |
:init | |
(setq helm-quick-update t | |
helm-buffers-fuzzy-matching t | |
helm-ff-transformer-show-only-basename nil)) | |
(use-package helm-projectile | |
:commands (helm-projectile-find-file helm-projectile-switch-to-buffer) | |
:init | |
(mykie:set-keys nil | |
"C-x C-f" | |
:default (call-interactively 'find-file) | |
:C-u helm-projectile-find-file | |
:C-u*2! helm-ls-git-ls | |
"C-x b" | |
:default (call-interactively 'switch-to-buffer) | |
:C-u helm-projectile-switch-to-buffer) | |
:config | |
(use-package projectile | |
:config | |
(projectile-mode 1)) | |
(use-package helm-ls-git)) | |
(use-package helm-ag | |
:bind ("C-x C-g" . helm-do-ag-project-root)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; programming languages | |
;;; | |
(use-package aggressive-indent | |
:commands aggressive-indent-mode) | |
(defun my/prog-mode-hook () | |
(aggressive-indent-mode 1) | |
(company-mode 1)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; lisp | |
;;; | |
(use-package paredit | |
:bind (:map paredit-mode-map | |
("C-h" . paredit-backward-delete)) | |
:config | |
(defun conditionally-enable-paredit-mode () | |
(if (eq this-command 'eval-expression) | |
(paredit-mode 1))) | |
(add-hook 'minibuffer-setup-hook 'conditionally-enable-paredit-mode)) | |
(use-package eldoc | |
:commands eldoc-mode | |
:init | |
(setq eldoc-idle-delay 0.1 | |
eldoc-minor-mode-string "")) | |
(use-package rainbow-delimiters | |
:commands rainbow-delimiters-mode) | |
(defun my/lisp-mode-defaults () | |
(paredit-mode 1) | |
(rainbow-delimiters-mode 1) | |
(eldoc-mode 1)) | |
(defun my/lisp-mode-hook () | |
(my/lisp-mode-defaults)) | |
(use-package lisp-mode | |
:ensure nil | |
:mode (("\\.lisp\\'" . lisp-mode) | |
("\\.el\\'" . emacs-lisp-mode)) | |
:init | |
(add-hook 'emacs-lisp-mode-hook 'my/prog-mode-hook) | |
(add-hook 'emacs-lisp-mode-hook 'my/lisp-mode-hook)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;; | |
;;; | |
;;; clojure | |
;;; | |
(use-package clojure-mode | |
:mode (("\\.clj\\'" . clojure-mode) | |
("\\.cljc\\'" . clojurec-mode) | |
("\\.cljx\\'" . clojurex-mode) | |
("\\.cljs\\'" . clojurescript-mode)) | |
:config | |
(add-hook 'clojure-mode-hook #'yas-minor-mode) | |
(add-hook 'clojure-mode-hook #'subword-mode) | |
(add-hook 'clojure-mode-hook #'company-mode) | |
(add-hook 'clojure-mode-hook #'clj-refactor-mode) | |
(add-hook 'clojure-mode-hook #'cider-mode) | |
(add-hook 'clojure-mode-hook #'my/prog-mode-hook) | |
(add-hook 'clojure-mode-hook #'my/lisp-mode-hook) | |
(add-hook 'clojure-mode-hook | |
(lambda () | |
(setq-local company-backends | |
'((company-capf :with company-dabbrev-code | |
:with company-yasnippet)))))) | |
(use-package cider | |
:diminish cider-mode | |
:pin melpa | |
:bind (:map cider-mode-map | |
("C-x *" . my/zou-go) | |
("C-x @" . my/split-window-below-and-switch-to-repl) | |
("C-x #" . my/split-window-right-and-switch-to-repl) | |
("C-c C-s" . cider-browse-spec) | |
("C-c s" . cider-browse-spec) | |
("C-c C-S" . cider-browse-spec-all) | |
("C-c S" . cider-browse-spec-all) | |
:map cider-repl-mode-map | |
("C-x *" . my/zou-go)) | |
:commands (cider-mode cider-jack-in) | |
:config | |
(use-package dash | |
:config | |
(defun my/find-cider-repl-buffer () | |
(-first | |
(lambda (b) | |
(with-current-buffer b | |
(derived-mode-p 'cider-repl-mode))) | |
(buffer-list)))) | |
(defun my/split-window-below-and-switch-to-repl () | |
(interactive) | |
(let* ((window (split-window-below)) | |
(buffer (my/find-cider-repl-buffer))) | |
(set-window-buffer window buffer))) | |
(defun my/split-window-right-and-switch-to-repl () | |
(interactive) | |
(let* ((window (split-window-right)) | |
(buffer (my/find-cider-repl-buffer))) | |
(set-window-buffer window buffer))) | |
(add-hook 'cider-repl-mode-hook #'company-mode) | |
(add-hook 'cider-repl-mode-hook #'my/lisp-mode-hook) | |
(add-hook 'cider-mode-hook #'cider-company-enable-fuzzy-completion) | |
(add-hook 'cider-repl-mode-hook #'cider-company-enable-fuzzy-completion) | |
(setq nrepl-log-messages t | |
cider-repl-display-help-banner nil | |
cider-repl-display-in-current-window t | |
cider-repl-use-clojure-font-lock t | |
cider-repl-use-pretty-printing t | |
cider-repl-result-prefix ";;=> " | |
cider-save-file-on-load t | |
cider-font-lock-dynamically '(macro core function var) | |
cider-overlays-use-font-lock t) | |
(defun my/zou-go () | |
(interactive) | |
(with-current-buffer (cider-current-connection "clj") | |
(if current-prefix-arg | |
(progn | |
(save-some-buffers) | |
(cider-interactive-eval | |
"(zou.framework.repl/reset)")) | |
(cider-interactive-eval | |
"(zou.framework.repl/go)"))))) | |
(use-package clj-refactor | |
:pin melpa | |
:diminish clj-refactor-mode | |
:commands clj-refactor-mode | |
:config | |
(cljr-add-keybindings-with-prefix "C-c C-m")) | |
(message "init.el loaded!!") | |
(add-hook 'after-init-hook | |
(lambda () | |
(message "init time: %.3f sec" | |
(float-time (time-subtract after-init-time before-init-time))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment