;;; init.el --- Initialization file for emacs ;;; Commentary: Emacs startup file --- initialization file for emacs (require 'package) (setq package-enable-at-startup nil) (setq package-archives '(("org" . "http://orgmode.org/elpa/") ("gnu" . "http://elpa.gnu.org/packages/") ("melpa" . "https://melpa.org/packages/"))) (package-initialize) ;; Bootstrap `use-package` (unless (package-installed-p 'use-package) (package-refresh-contents) (package-install 'use-package)) (require 'use-package) ;; Some term enhancement (defadvice term-sentinel (around my-advice-term-sentinel (proc msg)) (if (memq (process-status proc) '(signal exit)) (let ((buffer (process-buffer proc))) ad-do-it (kill-buffer buffer)) ad-do-it)) (ad-activate 'term-sentinel) (defadvice ansi-term (before force-bash) (interactive (list "/usr/bin/fish"))) (ad-activate 'ansi-term) ;; Other configs (setq make-backup-files nil) (setq auto-save-default nil) ;; Splash Screen (setq inhibit-startup-screen t) (setq initial-scratch-message ";; Happy Hacking") ;; Show matching parens (setq show-paren-delay 0) (show-paren-mode 1) ;; Paragraph movement (global-set-key (kbd "s-j") 'forward-paragraph) (global-set-key (kbd "s-k") 'backward-paragraph) ;; Keybinding for term mode (add-hook 'term-mode (lambda () (global-set-key (kbd "s-v") 'term-paste))) ;; OrgMode Configs (setq org-html-validation-link nil) (setq org-todo-keywords '((sequence "TODO" "WORKING" "HOLD" "|" "DONE"))) (setq org-todo-keyword-faces '(("TODO" . "blue") ("WORKING" . "yellow") ("HOLD" . "red") ("DONE" . "green"))) ;; UI configurations (if (display-graphic-p) (progn (tool-bar-mode -1) (scroll-bar-mode -1) ) ) (tooltip-mode -1) (menu-bar-mode -1) (global-linum-mode 1) (add-to-list 'default-frame-alist '(font . "Iosevka-14")) (add-to-list 'default-frame-alist '(height . 24)) (add-to-list 'default-frame-alist '(width . 80)) ;; Vim mode (use-package evil :ensure t :config (evil-mode 1)) (use-package evil-escape :ensure t :init (setq-default evil-escape-key-sequence "jk") :config (evil-escape-mode 1)) ;; Anzu for search matching (use-package anzu :ensure t :config (global-anzu-mode 1) (global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp) (global-set-key [remap query-replace] 'anzu-query-replace)) ;; Theme (use-package doom-themes :ensure t :config (load-theme 'doom-molokai t)) ;; Helm (use-package helm :ensure t :init (setq helm-M-x-fuzzy-match t helm-mode-fuzzy-match t helm-buffers-fuzzy-matching t helm-recentf-fuzzy-match t helm-locate-fuzzy-match t helm-semantic-fuzzy-match t helm-imenu-fuzzy-match t helm-completion-in-region-fuzzy-match t helm-candidate-number-list 80 helm-split-window-inside-p t helm-move-to-line-cycle-in-source t helm-echo-input-in-header-line t helm-autoresize-max-height 0 helm-autoresize-min-height 20) :config (helm-mode 1)) ;; RipGrep (use-package helm-rg :ensure t) ;; Projectile (use-package projectile :ensure t :init (setq projectile-require-project-root nil) :config (projectile-mode 1)) ;; Helm Projectile (use-package helm-projectile :ensure t :init (setq helm-projectile-fuzzy-match t) :config (helm-projectile-on)) ;; Helm Gtags (use-package helm-gtags :defer t :ensure t :init (progn (setq helm-gtags-ignore-case t helm-gtags-auto-update t helm-gtags-prefix-key "SPC" helm-gtags-use-input-at-cursor t helm-gtags-pulse-at-cursor t) (add-hook 'c-mode-hook 'helm-gtags-mode))) ;; All The Icons (use-package all-the-icons :ensure t) ;; NeoTree (use-package neotree :ensure t :init (setq neo-theme (if (display-graphic-p) 'icons 'arrow))) ;; Which Key (use-package which-key :ensure t :init (setq which-key-separator " ") (setq which-key-prefix-prefix "+") :config (which-key-mode)) ;; Restart emacs from within emacs (use-package restart-emacs :ensure t) ;; For Haskell & Rust Support (use-package lsp-mode :defer t :ensure t :commands lsp) (use-package lsp-ui :commands lsp-ui-mode :config ((add-hook 'lsp-mode-hook 'lsp-ui-mode) (add-hook 'haskell-mode-hook 'flycheck-mode))) (use-package company-lsp :commands company-lsp) (use-package lsp-haskell :defer t :ensure t :config ((add-hook 'haskell-mode-hook #'lsp) (setq lsp-haskell-process-path-hie "~/.local/bin/hie-wrapper"))) (use-package rust-mode :defer t :ensure t) ;; Git Support (use-package magit :defer t :ensure t) (use-package evil-magit :defer t :ensure t) (use-package helm-git-grep :defer t :ensure t) (use-package helm-gitignore :defer t :ensure t) (use-package git-commit :defer t :ensure t) (use-package git-messenger :defer t :ensure t :config (define-key git-messenger-map [escape] 'git-messenger:popup-close)) (use-package gitattributes-mode :defer t) (use-package gitconfig-mode :defer t) (use-package gitignore-mode :defer t) ;; Custom keybinding (use-package general :ensure t :config (general-define-key :states '(normal visual insert emacs) :prefix "SPC" :non-normal-prefix "M-SPC" "/" '(helm-projectile-rg :which-key "ripgrep") "TAB" '(switch-to-prev-buffer :which-key "previous buffer") "SPC" '(helm-M-x :which-key "M-x") "pf" '(helm-projectile-find-file :which-key "find files") "pp" '(helm-projectile-switch-project :which-key "switch project") "pb" '(helm-projectile-switch-to-buffer :which-key "switch buffer") "pr" '(helm-show-kill-ring :which-key "show kill ring") ;; Buffers "bb" '(helm-mini :which-key "buffers list") ;; Window "wl" '(windmove-right :which-key "move right") "wh" '(windmove-left :which-key "move left") "wk" '(windmove-up :which-key "move up") "wj" '(windmove-down :which-key "move bottom") "w/" '(split-window-right :which-key "split right") "w-" '(split-window-below :which-key "split bottom") "wx" '(delete-window :which-key "delete window") "qz" '(delete-frame :which-key "delete frame") "qq" '(kill-emacs :which-key "quit") "qr" '(restart-emacs :which-key "restart emacs") ;; NeoTree "ft" '(neotree-toggle :which-key "toggle neotree") ;; Others "at" '(ansi-term :which-key "open terminal") ;; Gtags "mgc" '(helm-gtags-create-tags :which-key "create tag db") "mgd" '(helm-gtags-find-tag :which-key "find definitions") "mgf" '(helm-gtags-select-path :which-key "jump to a file in tag db") "mgG" '(helm-gtags-dwim-other-window :which-key "jump to location based on context") "mgi" '(helm-gtags-tags-in-this-function :which-key "present tags in current function") "mgl" '(helm-gtags-parse-file :which-key "jump to definitions in file") "mgn" '(helm-gtags-next-history :which-key "jump to next location in context stack") "mgp" '(helm-gtags-previous-history :which-key "jump to previous location in context stack") "mgr" '(helm-gtags-find-rtag :which-key "find references") "mgR" '(helm-gtags-resume :which-key "resume previous helm-gtags session") "mgs" '(helm-gtags-select :which-key "select any tag in project retrieved by gtags") "mgS" '(helm-gtags-show-stack :which-key "show stack of visited locations") "mgu" '(helm-gtags-update-tags :which-key "create tag db") ;; Git key bindings "gc" '(magit-clone :which-key "magit clone") "gff" '(magit-find-file :which-key "magit find file") "gfl" '(magit-log-buffer-file :which-key "magit log buffer file") "gfd" '(magit-diff-buffer-file-popup :which-key "magit diff buffer file popup") "gi" '(magit-init :which-key "magit initialize") "gL" '(magit-list-repositories :which-key "magit list repositories") "gm" '(magit-dispatch-popup "magit dispatch popup") "gs" '(magit-status "open Magit status buffer") "gS" '(magit-stage-file "magit stage file") "gU" '(magit-unstage-file "magit unstage file") "g/" '(helm-git-grep :which-key "open helm git grep") "g*" '(helm-git-grep-at-point :which-key "open helm git grep at point") )) ;; Fancy titlebar for MacOS (add-to-list 'default-frame-alist '(ns-transparent-titlebar . t)) (add-to-list 'default-frame-alist '(ns-appearance . dark)) (setq ns-use-proxy-icon nil) (setq frame-title-format nil) ;; Flycheck (use-package flycheck :ensure t :init (global-flycheck-mode)) ;; To disable flycheck while working with this file (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc)) ;; Company mode (use-package company :ensure t :init (setq company-minimum-prefix-length 3) (setq company-auto-complete nil) (setq company-idle-delay 0) (setq company-require-match 'never) (setq company-frontends '(company-pseudo-tooltip-unless-just-one-frontend company-preview-frontend company-echo-metadata-frontend)) (setq tab-always-indent 'complete) (defvar completion-at-point-functions-saved nil) :config (global-company-mode 1) (define-key company-active-map (kbd "TAB") 'company-complete-common-or-cycle) (define-key company-active-map (kbd "") 'company-complete-common-or-cycle) (define-key company-active-map (kbd "S-TAB") 'company-select-previous) (define-key company-active-map (kbd "") 'company-select-previous) (define-key company-mode-map [remap indent-for-tab-command] 'company-indent-for-tab-command) (defun company-indent-for-tab-command (&optional arg) (interactive "P") (let ((completion-at-point-functions-saved completion-at-point-functions) (completion-at-point-functions '(company-complete-common-wrapper))) (indent-for-tab-command arg))) (defun company-complete-common-wrapper () (let ((completion-at-point-functions completion-at-point-functions-saved)) (company-complete-common)))) ;; Powerline (use-package spaceline :ensure t :init (setq powerline-default-separator 'slant) :config (spaceline-emacs-theme) (spaceline-toggle-minor-modes-off) (spaceline-toggle-buffer-size-off) (spaceline-toggle-evil-state-on)) ;;;;;;;;;;;;;;;;;;;;;;; ;; Language Supports ;; ;;;;;;;;;;;;;;;;;;;;;;; ;;; C (defun c-lineup-arglist-tabs-only (ignored) "Line up argument lists by tabs, not spaces" (let* ((anchor (c-langelem-pos c-syntactic-element)) (column (c-langelem-2nd-pos c-syntactic-element)) (offset (- (1+ column) anchor)) (steps (floor offset c-basic-offset))) (* (max steps 1) c-basic-offset))) (add-hook 'c-mode-common-hook (lambda () ;; Add kernel style (c-add-style "linux-tabs-only" '("linux" (c-offsets-alist (arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)))))) (add-hook 'c-mode-hook (lambda () (let ((filename (buffer-file-name))) ;; Enable kernel mode for the appropriate files (when (and filename (string-match (expand-file-name "~/ged4k/linux-xlnx") filename)) (setq indent-tabs-mode t) (setq show-trailing-whitespace t) (c-set-style "linux-tabs-only"))))) (defun helm-gtags-dwim-other-window () ;; Enable helm-gtags-dwim in the other window (interactive) (let ((helm-gtags--use-otherwin t) (split-height-threshold nil) (split-width-threshold 140)) (helm-gtags-dwim))) ;;; init.el ends