Skip to content

Instantly share code, notes, and snippets.

@mitghi
Last active January 31, 2020 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitghi/606434f590cec993854212653f4d2dbb to your computer and use it in GitHub Desktop.
Save mitghi/606434f590cec993854212653f4d2dbb to your computer and use it in GitHub Desktop.
Emacs init file
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(when no-ssl
(warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)
(defun GlobalModes ()
"Global Modes"
(set-exec-path)
(package-initialize)
(require 'neotree)
(require 'auto-complete)
(require 'auto-complete-config)
(require 'yasnippet)
(require 'clang-format)
)
;; Bereich : Defaults
(setq aw-dispatch-always t)
(setq popup-use-optimized-column-computation nil)
(setq inhibit-startup-message t)
(setq show-paren-delay 0)
;; d e b u g
;; (setq-default cursor-type 'bar)
;; Bereich : Paths
(setq EMACS_PATH (concat (getenv "HOME") "/.emacs.d"))
(setq SNIPPET_PATH (concat EMACS_PATH "/snippets"))
(setq PLUGINS_PATH (concat EMACS_PATH "/plugins"))
;; Bereich : Mappings
(setq KEY_MAPPING
'(("<f5>" . interactive-compile)
("<f8>" . neotree-toggle)
("C-h" . delete-backward-char)
("M-h" . backward-kill-word)
("C-," . (lambda () (interactive)(other-window -1)))
("C-." . (lambda () (interactive)(other-window 1)))
("C-C ," . (lambda () (interactive)(other-window -1)))
("C-C ." . (lambda () (interactive)(other-window 1)))
("C-M-," . (lambda () (interactive)(other-window -1)))
("C-M-." . (lambda () (interactive)(other-window 1)))
("M-." . (lambda () (interactive)(other-window 1)))
("M-," . (lambda () (interactive)(other-window -1)))
("C-S-c C-S-c" . mc/edit-lines)
("C-x >" . mc/mark-next-like-this)
("C-x <" . mc/mark-previous-like-this)
("C-c C-<" . mc/mark-all-like-this)
("<f9>" . zoom-window-zoom)
("C-'" . ac-start)
("M-p" . ace-window)
("\M-?" . help-command)
("C-c SPC" . ace-jump-mode)
("C-c y" . yas-expand)
("<f6>" . imenu-list-smart-toggle)
("C-c i" . clang-format-region)
("C-c u" . clang-format-buffer)
("C-;" . (lambda () (interactive) (move-end-of-line 1) (newline nil)))))
;; Bereich: Initializers
(defun Initializers ()
(defun interactive-compile ()
(interactive)
(setq-local compilation-read-command nil)
(call-interactively 'compile))
(add-to-list 'custom-theme-load-path (concat EMACS_PATH "/themes/"))
(add-to-list 'load-path PLUGINS_PATH)
(add-to-list 'load-path (concat EMACS_PATH "/yasnippet"))
(add-to-list 'yas-snippet-dirs SNIPPET_PATH)
)
(defun Customizers ()
(when (display-graphic-p) (progn
(tool-bar-mode 0)
(scroll-bar-mode 0)
(set-fringe-mode 0)))
(setq inhibit-startup-screen t)
(setq visible-bell nil)
(setq ring-bell-function 'ignore)
(show-paren-mode t)
(ac-config-default)
(yas-global-mode 1)
(mapcar (lambda (x)
(let* ((key (car x)) (fn (cdr x)))
(global-set-key (kbd key) fn))) KEY_MAPPING)
(define-key neotree-mode-map (kbd "i") #'neotree-enter-horizontal-split)
(define-key neotree-mode-map (kbd "I") #'neotree-enter-vertical-split))
(defun DisplayConfigurations ()
(setq custom-safe-themes t)
(load-theme 'hickey)
;; d e b u g
;; Set default font
(set-default-font "Menlo 14")
;; (add-to-list 'default-frame-alist
;; '(font . "Hack 10"))
;; (set-face-background 'show-paren-match-face "#aaaaaa")
;; (set-face-attribute 'show-paren-match-face nil
;; :weight 'bold :underline nil :overline nil :slant 'normal)))
;; d e b u g
)
(defun ModeConfigurations ()
;; smartparens mode configuration
;; (smartparens-global-mode)
;; (sp-with-modes '(c-mode c++-mode)
;; (sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET")))
;; (sp-local-pair "/*" "*/" :post-handlers '((" | " "SPC")
;; ("* ||\n[i]" "RET"))))
(require 'gotests))
;; Bereich: Miscellaneous
(defun set-exec-path ()
"Setup PATH variable"
(when window-system
(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)
(setq exec-path (split-string path-from-shell path-separator)))
(setenv "PATH" (concat "/usr/local/bin:" (getenv "PATH")))))
;; Bereich: Modes
(defun go-mode-setup ()
(setq-default)
(setq tab-width 2)
(setq standard-indent 2)
(setq indent-tabs-mode nil)
(setq compile-command "go build -v && go test -v && go vet")
(setq gofmt-command "goimports")
(setq imenu-generic-expression
'(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)
("func" "^func *\\(.*\\) {" 1)))
(imenu-add-to-menubar "Index")
(add-hook 'go-mode-hook 'go-eldoc-setup)
;; * d e b u g *
;;
;; go-autocomplete setup
(require 'go-mode)
(require 'go-autocomplete)
(require 'go-eldoc)
(require 'go-guru)
;; gotests setup
(require 'gotests)
(yas-minor-mode)
(when (memq window-system '(mac ns))
(setq exec-path-from-shell-arguments '("-i"))
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-env "GOPATH"))
;; setup go-eldoc
;;
;; * d e b u g *
;;
(go-eldoc-setup)
;; set compile shortcut
(define-key (current-local-map) "\C-c\C-c" 'compile)
(add-hook 'before-save-hook 'gofmt-before-save)
;; setup local key-bindings
(local-set-key (kbd "C-c C-o") 'ff-find-other-file)
(local-set-key (kbd "M-.") 'godef-jump)
(local-set-key (kbd "M-*") 'pop-tag-mark)
(local-set-key (kbd "C-c TAB") 'ac-complete-go)
(local-set-key (kbd "C-c C-r") 'go-remove-unused-imports)
(local-set-key (kbd "C-c i") 'go-goto-imports)
(local-set-key (kbd "C-c (") 'go-goto-opening-parenthesis)
)
(defun python-mode-setup ()
(setq indent-tabs-mode t)
(setq python-indent-offset 2)
(setq tab-width 2))
(defun c-mode-setup ()
(require 'auto-complete-c-headers)
(setq tab-width 4)
(setq standard-indent 4)
(setq indent-tabs-mode nil)
(setq c-basic-offset 4)
(setq compile-command "make")
(add-to-list 'ac-sources 'ac-source-c-headers)
(add-to-list 'achead:include-directories '"/usr/include")
(require 'c-eldoc)
(add-hook 'c-mode-hook 'c-turn-on-eldoc-mode)
(setq c-eldoc-cpp-command "/usr/bin/clang++")
(setq c-eldoc-cpp-normal-arguments "-stdlib=libc++ -x c - -fsyntax-only")
(setq c-eldoc-includes "-I./ -I../ -I/usr/local/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include")
;; set coding style
;; (setq c-default-style "bsd" c-basic-offset 4)
(local-set-key (kbd "C-c o") 'ff-find-other-file)
(add-hook 'c-mode-common-hook '(lambda () (c-toggle-auto-state 1)))
)
;; JAVA mode setup section
(defun gradle-build-and-run ()
(interactive)
(gradle-run "build run"))
(defun java-mode-setup ()
(require 'eclim)
(require 'eclimd)
(require 'gradle-mode)
(require 'auto-complete)
(require 'auto-complete-config)
(ac-config-default)
;; set custom variables for eclim
(custom-set-variables '(eclim-eclipse-dirs '("/Users/mitghi/eclipse-workspace"))
'(eclim-executable "/Users/mitghi/.p2/pool/plugins/org.eclim_2.8.0/bin/eclim")
'(eclimd-default-workspace "/Applications/Eclipse.app/Contents/Eclipse"))
;; setup eclim
(global-eclim-mode)
;; activate gradle mode
(gradle-mode 1)
;; setup autocompletion
(require 'ac-emacs-eclim-source)
(ac-emacs-eclim-config)
;; set custom keys
(define-key gradle-mode-map (kbd "C-c C-r") 'gradle-build-and-run)
(define-key eclim-mode-map (kbd "C-c C-c") 'eclim-problems-correct))
(defun javascript-mode-hook ()
(local-set-key (kbd "C-c e") 'eslint-fix)
)
;; TODO
;; (defun swift-mode-setup ()
;; (require 'ac-swift)
;; ;; (require 'company-sourcekit)
;; (add-hook 'swift-mode-hook 'ac-swift-setup)
;; (eval-after-load "auto-complete"
;; '(add-to-list 'ac-modes 'swift-mode))
;; ;; (company-mode t)
;; ;; (company-sourcekit t)
;; ;; (add-to-list 'company-backends 'company-sourcekit)
;; )
;; Bereich: Setup
(GlobalModes)
(Initializers)
(Customizers)
(DisplayConfigurations)
(ModeConfigurations)
;; Bereich: Hooks
(add-hook 'c-mode-hook 'c-mode-setup)
(add-hook 'c++-mode-hook 'c-mode-setup)
(add-hook 'go-mode-hook 'go-mode-setup)
(add-hook 'python-mode-hook 'python-mode-setup)
(add-hook 'java-mode-hook 'java-mode-setup)
(add-hook 'javascript-mode-hook 'javascript-mode-hook)
;; (add-hook 'swift-mode-hook 'swift-mode-setup)
(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.
'(custom-safe-themes
(quote
("72a81c54c97b9e5efcc3ea214382615649ebb539cb4f2fe3a46cd12af72c7607" "2d5c40e709543f156d3dee750cd9ac580a20a371f1b1e1e3ecbef2b895cf0cd2" "8530b2f7b281ea6f263be265dd8c75b502ecd7a30b9a0f28fa9398739e833a35" "ed92c27d2d086496b232617213a4e4a28110bdc0730a9457edf74f81b782c5cf" "0f302165235625ca5a827ac2f963c102a635f27879637d9021c04d845a32c568" "3ed2e1653742e5059e3d77af013ee90c1c1b776d83ec33e1a9ead556c19c694b" "9a3c51c59edfefd53e5de64c9da248c24b628d4e78cc808611abd15b3e58858f" "a455366c5cdacebd8adaa99d50e37430b0170326e7640a688e9d9ad406e2edfd" "be5b03913a1aaa3709d731e1fcfd4f162db6ca512df9196c8d4693538fa50b86" "da8e6e5b286cbcec4a1a99f273a466de34763eefd0e84a41c71543b16cd2efac" "fe349b21bb978bb1f1f2db05bc87b2c6d02f1a7fe3f27584cd7b6fbf8e53391a" "840db7f67ce92c39deb38f38fbc5a990b8f89b0f47b77b96d98e4bf400ee590a" "fbefbb459aad35c984468485fedad0484bc1cc930f5de69d91b4fbb55eb25749" "80a23d559a5c5343a0882664733fd2c9e039b4dbf398c70c424c8d6858b39fc5" "9d9b2cf2ced850aad6eda58e247cf66da2912e0722302aaa4894274e0ea9f894" "5057614f7e14de98bbc02200e2fe827ad897696bfd222d1bcab42ad8ff313e20" "89f545ddc104836b27167696db89b371f23893d5b2f038d43383d877ee678d3d" "3cd28471e80be3bd2657ca3f03fbb2884ab669662271794360866ab60b6cb6e6" "9b59e147dbbde5e638ea1cde5ec0a358d5f269d27bd2b893a0947c4a867e14c1" "c48551a5fb7b9fc019bf3f61ebf14cf7c9cdca79bcb2a4219195371c02268f11" "f9f2ea69700b0c660f1a6507bbd0aec13e213b7618336ff20852f617991ae369" "e0d42a58c84161a0744ceab595370cbe290949968ab62273aed6212df0ea94b4" "58c6711a3b568437bab07a30385d34aacf64156cc5137ea20e799984f4227265" "e9776d12e4ccb722a2a732c6e80423331bcb93f02e089ba2a4b02e85de1cf00e" "987b709680284a5858d5fe7e4e428463a20dfabe0a6f2a6146b3b8c7c529f08b" "96998f6f11ef9f551b427b8853d947a7857ea5a578c75aa9c4e7c73fe04d10b4" default)))
'(cycle-themes-mode t)
'(eclim-eclipse-dirs (quote ("/Users/
'(eclim-executable "/Users/mitghi/.p2/pool/plugins/org.eclim_2.8.0/bin/eclim")
'(eclimd-default-workspace "/Applications/Eclipse.app/Contents/Eclipse")
'(package-selected-packages
(quote
(rjsx-mode json-mode web-mode flycheck react-snippets eslint-fix js2-mode nodejs-repl cider green-screen-theme immaterial-theme hydandata-light-theme dakrone-light-theme darkmine-theme flatui-dark-theme github-modern-theme panda-theme subatomic-theme rebecca-theme nimbus-theme tangotango-theme challenger-deep-theme planet-theme zenburn-theme color-theme-modern github-theme magit creamsody-theme edit-server android-mode java-imports ac-emacs-eclim company-emacs-eclim gradle-mode eclim javap-mode cpputils-cmake zoom-window swift3-mode company-rtags company-irony-c-headers c-eldoc company-c-headers company-irony irony-eldoc irony haskell-mode seti-theme clang-format ecb imenu-list flycheck-color-mode-line flymake-go swift-mode sublime-themes smartparens neotree gotest godoctor go-snippets go-rename go-imports go-impl go-imenu go-guru go-fill-struct go-eldoc go-autocomplete exec-path-from-shell company-sourcekit auto-complete-clang auto-complete-c-headers ace-window ace-jump-mode)))
'(show-paren-mode t))
(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.
'(default ((t (:background nil)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment