Skip to content

Instantly share code, notes, and snippets.

@dolftax
Last active July 6, 2019 16:58
Show Gist options
  • Save dolftax/75d21ae9231e850447437d044e95d5a1 to your computer and use it in GitHub Desktop.
Save dolftax/75d21ae9231e850447437d044e95d5a1 to your computer and use it in GitHub Desktop.
dolftax's dotemacs
;;; Emacs configuration file
;;; Code:
;; -------------------------------------------------
;; Base editor configurations
;; -------------------------------------------------
;; Scrollbars, menubars, toolbars. Hide'em
(if (display-graphic-p)
(progn
(tool-bar-mode -1)
(scroll-bar-mode -1)
(mouse-wheel-mode t)))
;; Remove menu bar
(menu-bar-mode -1)
;; Base text mode and other configuration
(setq inhibit-startup-message t)
(setq major-mode 'text-mode)
(setq make-backup-files nil)
;; Trim whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Line and column numbers
(global-linum-mode t)
(line-number-mode t)
(column-number-mode t)
(size-indication-mode t)
;; Change behaviour of yes or no
(fset 'yes-or-no-p 'y-or-n-p)
;; Disable tab mode
(setq-default indent-tabs-mode nil)
;; Set default font
(set-default-font "Menlo 14")
;; Syntax highlighting
(setq font-lock-maximum-decoration t)
;; Delete selection
(delete-selection-mode 1)
;; Do not test recent files on startup
(setq recentf-keep '(file-remote-p file-readable-p))
;; more useful frame title, that show either a file or a
;; buffer name (if the buffer isn't visiting a file)
(setq frame-title-format
'("emacs - " (:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
;; Stop creating backups
(setq make-backup-files nil)
;; Startup *scratch* buffer
(setq initial-major-mode 'text-mode)
(setq initial-scratch-message "// Use this buffer for notes\n// Find files : C-x C-f\n// Recent files : C-c f\n\n")
;; Install packages
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(package-initialize)
;; Install packages
(defun ensure-package-installed (&rest packages)
"Assure every package is installed, ask for installation if it’s not.
Return a list of installed packages or nil for every skipped package."
(mapcar
(lambda (package)
;; (package-installed-p 'evil)
(if (package-installed-p package) nil
(package-install package)))
packages))
;; make sure to have downloaded archive description.
;; Or use package-archive-contents as suggested by Nicolas Dudebout
(or (file-exists-p package-user-dir)
(package-refresh-contents))
;; Install packages
(ensure-package-installed
'exec-path-from-shell
'go-mode
'go-guru
'magit
'js2-mode
'json-mode
'web-mode
'markdown-mode
'helm
'helm-core
'flycheck
'flymake
'flymake-go
'monokai-theme
'yaml-mode
'toml-mode
'async
'dash
'popup
'powerline
)
;; Copy to clipboard
(setq select-enable-clipboard t)
;; Start maximised
(add-to-list 'default-frame-alist '(fullscreen . maximized))
;; Exec path from shell
(exec-path-from-shell-initialize)
;; JS mode
;; http://www.flycheck.org/manual/latest/index.html
(require 'flycheck)
(require 'flymake)
;; turn on flychecking globally
(add-hook 'after-init-hook #'global-flycheck-mode)
;; disable jshint since we prefer eslint checking
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
;; use eslint with web-mode for jsx files
(flycheck-add-mode 'javascript-eslint 'web-mode)
;; customize flycheck temp file prefix
(setq-default flycheck-temp-prefix ".flycheck")
;; disable json-jsonlist checking for json files
(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(json-jsonlist)))
;; Web mode config
;; Web mode
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 4)
(setq web-mode-enable-comment-keywords t)
(setq web-mode-enable-current-element-highlight t)
;; Powerline config
(require 'powerline)
(powerline-default-theme)
;; Helm
(require 'helm-config)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-x r b") 'helm-filtered-bookmarks)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(helm-mode 1)
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) ; rebind tab to do persistent action
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) ; make TAB works in terminal
(define-key helm-map (kbd "C-z") 'helm-select-action) ; list actions using C-z
;; Whitespace
(require 'whitespace)
(setq whitespace-line-column 120) ;; limit line length
(setq whitespace-style '(face tabs empty trailing space-before-tab space-after-tab))
(add-hook 'prog-mode-hook 'whitespace-mode)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(add-hook 'before-save-hook 'whitespace-cleanup)
;; Recent files
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 100)
;; Line numbers
(add-hook 'prog-mode-hook 'linum-mode)
(setq linum-format "%4d ")
;; Replace switch-buffer with helm-for-files
(global-set-key (kbd "C-x b") 'helm-for-files)
;; Start eshell or swit[1;5B]ch to it if it's active.
(global-set-key (kbd "C-x m") 'eshell)
;; rename buffer & visited file
(global-set-key (kbd "C-c r") 'rename-file-and-buffer)
;; Recent files
(global-set-key (kbd "C-c f") 'helm-recentf)
;; JS indent mode
(setq js-indent-level 2)
(setq js2-indent-switch-body t)
(put 'erase-buffer 'disabled nil)
;; Magit
(global-set-key (kbd "C-x g") 'magit-status)
;; Path
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (replace-regexp-in-string
"[ \t\n]*$"
""
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq eshell-path-env path-from-shell) ; for eshell users
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
;; GOPATH
(setenv "GOPATH" "/Users/Jai/go")
;; Add a directory to the load path so we can put extra files there
(add-to-list 'load-path "~/.emacs.d/lisp/")
;; Go mode
;; Define function to call when go-mode loads
(exec-path-from-shell-copy-env "GOPATH")
(defun my-go-mode-hook ()
(add-hook 'before-save-hook 'gofmt-before-save) ; gofmt before every save
(setq gofmt-command "goimports") ; gofmt uses invokes goimports
(if (not (string-match "go" compile-command)) ; set compile command default
(set (make-local-variable 'compile-command)
"go build -v && go test -v && go vet"))
;; guru settings
(go-guru-hl-identifier-mode) ; highlight identifiers
;; Key bindings specific to go-mode
(local-set-key (kbd "M-.") 'godef-jump) ; Go to definition
(local-set-key (kbd "M-*") 'pop-tag-mark) ; Return from whence you came
(local-set-key (kbd "M-p") 'compile) ; Invoke compiler
(local-set-key (kbd "M-P") 'recompile) ; Redo most recent compile cmd
(local-set-key (kbd "M-]") 'next-error) ; Go to next error (or msg)
(local-set-key (kbd "M-[") 'previous-error)) ; Go to previous error or msg
;; Connect go-mode-hook with the function we just defined
(add-hook 'go-mode-hook 'my-go-mode-hook)
;; If the go-guru.el file is in the load path, this will load it.
(require 'go-guru)
(require 'flymake-go)
(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.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(custom-enabled-themes (quote (monokai)))
'(custom-safe-themes
(quote
("c3d4af771cbe0501d5a865656802788a9a0ff9cf10a7df704ec8b8ef69017c68" "3629b62a41f2e5f84006ff14a2247e679745896b5eaa1d5bcfbc904a3441b0cd" default)))
'(package-selected-packages
(quote
(dockerfile-mode terraform-mode protobuf-mode go-guru powerline toml-mode yaml-mode monokai-theme flycheck helm markdown-mode web-mode json-mode js2-mode magit go-mode exec-path-from-shell))))
(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.
)
(global-auto-revert-mode t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment