Skip to content

Instantly share code, notes, and snippets.

@lorefnon
Last active January 22, 2017 19:36
Show Gist options
  • Save lorefnon/900064446ff6441d3c939180615a7eae to your computer and use it in GitHub Desktop.
Save lorefnon/900064446ff6441d3c939180615a7eae to your computer and use it in GitHub Desktop.
My emacs config
(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.
'(show-paren-mode t)
'(tool-bar-mode nil)
'(tooltip-mode nil))
(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.
)
;; (setq warning-minimum-level :emergency)
(setq debug-on-error t)
;; el-get basic setup:
;; ===================
;; Detects el-get and installs if required
;;
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))
;; (require 'package)
;; (add-to-list 'package-archives
;; '("melpa" . "http://melpa.org/packages/"))
;; (package-refresh-contents)
;; (package-initialize)
(require 'el-get)
(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
(require 'linum)
(global-linum-mode)
(delete-selection-mode 1)
(el-get-bundle helm
:checkout "v2.4.0"
:features (helm helm-config)
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) ; rebind tab to run persistent action
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) ; make TAB work in terminal
(define-key helm-map (kbd "C-z") 'helm-select-action) ; list actions using C-z
(setq helm-move-to-line-cycle-in-source t ; move to end or beginning of source when reaching top or bottom of source.
helm-ff-search-library-in-sexp t ; search for library in `require' and `declare-function' sexp.
helm-scroll-amount 8 ; scroll 8 lines other window using M-<next>/M-<prior>
helm-ff-file-name-history-use-recentf t
helm-echo-input-in-header-line t
helm-autoresize-max-height 0
helm-autoresize-min-height 20
helm-M-x-fuzzy-match t
helm-buffers-fuzzy-matching t
helm-recentf-fuzzy-match t
helm-find-file-ignore-thing-at-point t)
(helm-autoresize-mode t)
(helm-mode t)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-x C-m") 'helm-M-x)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x b") 'helm-mini)
(global-set-key (kbd "C-x C-b") 'helm-buffers-list)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-h f") 'helm-apropos)
(global-set-key (kbd "C-h r") 'helm-info-emacs)
(global-set-key (kbd "C-h C-l") 'helm-locate-library)
(global-set-key (kbd "C-c h o") 'helm-occur)
(global-set-key (kbd "C-c h x") 'helm-register)
(global-set-key (kbd "C-c h x") 'helm-recentf)
(global-set-key (kbd "C-c h g") 'helm-google-suggest))
(el-get-bundle! magit
:checkout "2.10.0"
(global-set-key (kbd "C-c m s") 'magit-status)
(global-set-key (kbd "C-c m l") 'magit-log-head)
(global-set-key (kbd "C-c m L") 'magit-log)
(global-set-key (kbd "C-c m b") 'magit-blame)
(global-set-key (kbd "C-c m d") 'magit-diff))
(el-get-bundle! git-timemachine
:checkout "3.0"
(global-set-key (kbd "C-c m t") 'git-timemachine))
(el-get-bundle! projectile
:checkout "v0.14.0"
(el-get-bundle! neotree
:checkout "0.5.1"
(global-set-key (kbd "C-c n t") 'neotree-toggle)
(global-set-key (kbd "C-c n f") 'neotree-find)
(global-set-key (kbd "C-c n r") 'neotree-rename-node)
;; Disable linum mode in neotree
(add-hook 'neotree-mode-hook
(lambda () (with-current-buffer " *NeoTree*"
(setq-local linum-mode nil))))
;; Open neotree at projectile root
(defun neotree-project-dir ()
"Open NeoTree using the git root."
(interactive)
(let ((project-dir (projectile-project-root))
(file-name (buffer-file-name)))
(neotree-toggle)
(if project-dir
(if (neo-global--window-exists-p)
(progn
(neotree-dir project-dir)
(neotree-find file-name)))
(message "Could not find git project root."))))
(global-set-key (kbd "C-c n .") 'neotree-project-dir)
;; When switching projects with projectile reset neotree root to new project
(setq projectile-switch-project-action 'neotree-projectile-action)))
(el-get-bundle! multiple-cursors
(global-set-key (kbd "C-c |") 'mc/edit-lines)
(global-set-key (kbd "C-c >") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c <") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C->") 'mc/mark-all-like-this))
(el-get-bundle! auto-complete
(ac-config-default))
(el-get-bundle! js2-mode
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-jsx-mode)))
(el-get-bundle! helm-ag)
(el-get-bundle! helm-projectile
:checkout "v0.14.0"
(helm-projectile-on)
(global-set-key (kbd "C-c p p") 'helm-projectile-switch-project)
(global-set-key (kbd "C-c p f") 'helm-projectile-find-file)
(global-set-key (kbd "C-c p d") 'helm-projectile-find-dir)
(global-set-key (kbd "C-c p a") 'helm-projectile-ag))
(el-get-bundle! helm-descbinds
:checkout "1.12")
(el-get-bundle! persp-projectile
:checkout "v0.2.0"
(define-key projectile-mode-map (kbd "C-c P s") 'projectile-persp-switch-project))
(el-get-bundle! yasnippet
:checkout "0.11.0")
(el-get-bundle! purcell/ibuffer-projectile :url "https://raw.githubusercontent.com/purcell/ibuffer-projectile/master/ibuffer-projectile.el")
(el-get-bundle! color-theme-solarized
:shallow t
(color-theme-solarized))
(el-get-bundle! markdown-mode
:shallow t)
(el-get-bundle! web-mode
:shallow t)
(el-get-bundle! move-text
:url "https://raw.githubusercontent.com/emacsfodder/move-text/2.0.1/move-text.el"
(move-text-default-bindings))
(el-get-bundle undo-tree-mode
:url "https://raw.githubusercontent.com/emacsmirror/undo-tree/a3e81b682053a81e082139300ef0a913a7a610a2/undo-tree.el"
:features (undo-tree)
(global-undo-tree-mode)
(defun undo-tree-visualizer-update-linum (&rest args)
(linum-update undo-tree-visualizer-parent-buffer))
(advice-add 'undo-tree-visualize-undo :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-redo :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-undo-to-x :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualize-redo-to-x :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualizer-mouse-set :after #'undo-tree-visualizer-update-linum)
(advice-add 'undo-tree-visualizer-set :after #'undo-tree-visualizer-update-linum))
(el-get-bundle! god-mode
:shallow t
(global-set-key (kbd "C-c G") 'god-local-mode)
;; Change modeline color in god mode
(defun c/god-mode-update-cursor ()
(let ((limited-colors-p (> 257 (length (defined-colors)))))
(cond (god-local-mode (progn
(set-face-foreground 'mode-line "red")
(set-face-background 'mode-line "white")
(set-face-foreground 'mode-line-inactive "black")))
(t (progn
(set-face-foreground 'mode-line "white")
(set-face-background 'mode-line "black")
(set-face-foreground 'mode-line-inactive "black"))))))
(add-hook 'god-mode-enabled-hook 'c/god-mode-update-cursor)
(add-hook 'god-mode-disabled-hook 'c/god-mode-update-cursor))
(put 'dired-find-alternate-file 'disabled nil)
(global-set-key (kbd "C-c b f") 'find-file-at-point)
(global-set-key (kbd "C-c b e") 'eval-buffer)
(global-set-key (kbd "C-c b r") 'revert-buffer)
(global-set-key (kbd "C-c /") 'comment-region)
(global-set-key (kbd "C-c \\") 'uncomment-region)
(global-set-key (kbd "C-<return>") 'cua-rectangle-mark-mode)
(global-hl-line-mode)
(setq-default truncate-lines t)
(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)
(setq c-basic-offset 4) ; indents 4 chars
(setq tab-width 4) ; and 4 char wide for TAB
(setq indent-tabs-mode nil) ; And force use of spaces
(add-hook 'before-save-hook 'whitespace-cleanup)
(defun smart-beginning-of-line ()
"Move point to first non-whitespace character or beginning-of-line.
Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
(interactive)
(let ((oldpos (point)))
(back-to-indentation)
(and (= oldpos (point))
(beginning-of-line))))
(global-set-key [home] 'smart-beginning-of-line)
(global-set-key "\C-a" 'smart-beginning-of-line)
(defun tmp-buffer()
"Make a temporary buffer and switch to it - Like C-n for Sublime etc"
(interactive)
(switch-to-buffer (get-buffer-create (concat "tmp-" (format-time-string "%m.%dT%H.%M.%S")))))
(global-set-key (kbd "C-c T") 'tmp-buffer)
(setq backup-directory-alist `(("." . "~/.emacs-bkup")))
;; --------------------------------------------------------------------------------
(setq js-es6-import-regex "import.*from\\s-+\\('\\|\"\\)\\(.*\\)\\('\\|\"\\)")
(setq js-cjs-import-regex "require(\\('\\|\"\\)\\(.*\\)\\('\\|\"\\))")
(setq js-lodash-util-usage-regex "_\\.\\<(.*)\\>")
(defun js-visit-rel-import-at-point ()
"Visit local file being imported through ES6/CommonJS import statement at point"
(interactive)
(let ((line (thing-at-point 'line)))
(catch 'reg-iter-loop
(dolist (reg (list js-es6-import-regex js-cjs-import-regex))
(if (string-match reg line)
(let* ((import-target (match-string 2 line))
(target-file-name (concat import-target ".js")))
(if (string= (substring target-file-name 0 1) ".")
(find-file target-file-name)
(message "Path not relative"))
(throw 'reg-iter-loop t)))))))
(global-set-key (kbd "C-c b j i") 'js-visit-rel-import-at-point)
(defun js-inject-util-used-at-point ()
"Inject lodash utility as import:
converts: _.map -> map
injects: import {map} from 'lodash'"
(interactive)
(let ((line (thing-at-point 'line)))
(dolist (item
(list
(list "_\\.\\<(.*)\\>" "import {.*} from \\('\\|\"\\)lodash\\('\\|\"\\)"))))
(if (string-match js-lodash-util-usage-regex line)
())))
(el-get-bundle flycheck
:checkout "30"
(defun my/use-eslint-from-node-modules ()
(let ((root (locate-dominating-file
(or (buffer-file-name) default-directory)
(lambda (dir)
(let ((eslint (expand-file-name "node_modules/eslint/bin/eslint.js" dir)))
(and eslint (file-executable-p eslint)))))))
(when root
(let ((eslint (expand-file-name "node_modules/eslint/bin/eslint.js" root)))
(setq-local flycheck-javascript-eslint-executable eslint)))))
(add-hook 'flycheck-mode-hook #'my/use-eslint-from-node-modules)
(global-flycheck-mode))
(el-get 'sync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment