(require 'package) (package-initialize) (require 'cl) (setq gc-cons-threshold (* 16 1024 1024)) (setq gc-cons-percentage 0.3) ;; Change all prompts to y or n (fset 'yes-or-no-p 'y-or-n-p) ;; my prompt (defun my/yes-or-whatever-p (prompt) (string= "yes" (downcase (read-from-minibuffer (concat prompt "(yes or whatever) "))))) ;; Ask if you want to quit emacs (setq confirm-kill-emacs 'my/yes-or-whatever-p) ;; Nope function (defun nope () (interactive) (message "Nope!")) (defun silence () (interactive)) ;; Helper function (defun string-ends-with-p (string suffix) "Return t if STRING ends with SUFFIX." (and (string-match (rx-to-string `(: ,suffix eos) t) string) t)) ;; Quote (setq initial-scratch-message (concat ";; Simplicity and elegance are unpopular because\n" ";; they require hard work and discipline to achieve\n" ";; and education to be appreciated.\n" ";;\n" ";; - Dijkstra\n\n")) ;; Set frame title (setq frame-title-format "%b (%m)") ;; Default frame size (setq initial-frame-alist '( (width . 110) (height . 40) )) ;; Use cperl-mode instead of perl-mode (defalias 'perl-mode 'cperl-mode) ;; Disable use of abbrev in cperl-mode (what the heck...) (add-hook 'cperl-mode-hook (lambda () (setq-local local-abbrev-table nil))) ;; Treat - as part of work in elisp (add-hook 'emacs-lisp-mode-hook (lambda () (modify-syntax-entry ?- "w"))) ;; Enable backup (setq make-backup-files t) (setq version-control t backup-by-copying t backup-directory-alist '(("." . "~/.saves")) delete-old-versions t kept-new-versions 6 kept-old-versions 2) (setq-default grep-command (concat "grep " "-rnH " "--binary-files=without-match " "--exclude-dir=.git ")) ;; Scroll behaviour (setq scroll-step 1 scroll-margin 5 scroll-conservatively 9999) ;; Auto-fill in text (add-hook 'text-mode-hook 'turn-on-auto-fill) (setq-default fill-column 80) ;; Allow "/" for search in package-menu (define-key package-menu-mode-map (kbd "/") 'swiper) (push '("melpa" . "http://melpa.milkbox.net/packages/") package-archives) (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]) '(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"]) '(blink-cursor-mode nil) '(cperl-close-paren-offset -2) '(cperl-electric-parens nil) '(cperl-electric-parens-mark nil) '(cperl-indent-level 2) '(cperl-indent-parens-as-block t) '(cperl-under-as-char t) '(custom-enabled-themes (quote (heroku))) '(custom-safe-themes (quote ("4f2ede02b3324c2f788f4e0bad77f7ebc1874eff7971d2a2c9b9724a50fb3f65" default))) '(dired-listing-switches "-lh") '(inhibit-startup-screen t) '(package-selected-packages (quote (evil-indent-plus company delight evil-org org-bullets counsel powerline-evil powerline origami projectile terminal-here swiper neotree ivy heroku-theme use-package yasnippet evil-surround org evil-magit magit makefile-runner evil)))) (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. '(company-preview ((t (:foreground "black")))) '(company-preview-common ((t (:inherit company-preview)))) '(company-preview-search ((t (:inherit company-preview)))) '(company-scrollbar-bg ((t (:background "dim gray")))) '(company-scrollbar-fg ((t (:background "gray")))) '(company-template-field ((t (:foreground "dark orange")))) '(company-tooltip ((t (:background "dim gray" :foreground "black")))) '(company-tooltip-annotation ((t (:foreground "gray19")))) '(company-tooltip-common ((t (:inherit company-preview)))) '(company-tooltip-selection ((t (:background "dark gray")))) '(ivy-current-match ((t (:foreground "gold")))) '(minibuffer-prompt ((t (:foreground "dark orange" :weight bold)))) '(neo-dir-link-face ((t (:foreground "#fce94f")))) '(neo-expand-btn-face ((t (:foreground "#ffe070")))) '(neo-root-dir-face ((t (:foreground "#fff3c6" :weight bold)))) '(org-ellipsis ((t (:foreground "LightGoldenrod")))) '(powerline-active1 ((t (:inherit mode-line)))) '(powerline-active2 ((t (:inherit mode-line)))) '(powerline-evil-emacs-face ((t (:inherit powerline-evil-base-face :background "gray30" :foreground "white")))) '(powerline-evil-insert-face ((t (:inherit powerline-evil-base-face :background "forest green")))) '(powerline-evil-motion-face ((t (:inherit powerline-evil-base-face :background "white" :foreground "black")))) '(powerline-evil-normal-face ((t (:inherit powerline-evil-base-face :background "white" :foreground "grey22")))) '(powerline-evil-replace-face ((t (:inherit powerline-evil-base-face :background "dark red"))))) ;; Disable unnecessary UI (when window-system (scroll-bar-mode -1) (tool-bar-mode -1)) (menu-bar-mode -1) ;; Buffer cleanup (defun buffer-cleanup-whitespace () "Remove trailing whitespaces upon save" (let ((whitespace-style '(empty trailing))) (whitespace-cleanup))) (add-hook 'before-save-hook 'buffer-cleanup-whitespace) (setq-default show-trailing-whitespace t) ;; Buffer Menu does trailing whitespace, don't show them (add-hook 'buffer-menu-mode-hook (lambda () (setq-local show-trailing-whitespace nil))) ;; ensure repo cache is up1date (or (file-exists-p package-user-dir) (package-refresh-contents)) ;; Install use-package (defun ensure-package-installed (package) "Ensure packages are installed" (if (package-installed-p package) nil (progn (package-refresh-contents) (package-install package)))) (ensure-package-installed 'use-package) ;; *.tex files are Latex-Files (add-to-list 'auto-mode-alist '("\\.tex\\'" . latex-mode)) ;; Extra Latex keybindings (defun my/latex-keybindings () (define-key latex-mode-map (kbd "") 'recompile)) (add-hook 'latex-mode-hook 'my/latex-keybindings) ;; show parens (show-paren-mode t) ;; highlight line (global-hl-line-mode) ;; No tabs - tabs are evil (setq-default indent-tabs-mode nil) (use-package delight :ensure t :demand t) (use-package let-alist :ensure t :demand t) ;; powerline (use-package powerline :ensure t :demand t) (use-package powerline-evil :ensure t :demand t :config (powerline-evil-vim-color-theme)) ;; theme (use-package heroku-theme :ensure t) ;; Open .org files in org directory (defun my/counsel-org-agenda () "Open .org files in org directory" (interactive) (find-file (concat (file-name-as-directory org-directory) (ivy-read "Org files: " (remove-if-not (lambda (e) (string-ends-with-p e ".org")) (directory-files org-directory)))))) ;; Org-mode (use-package org :ensure t :config (setq org-directory "~/org/") (setq org-agenda-files (concat org-directory "agenda")) (setq org-default-notes-file (concat org-directory "notes.org")) (global-set-key (kbd "C-c c") 'org-capture) (setq org-capture-templates '( ("t" "Todo" entry (file+headline org-default-notes-file "Todos") "* TODO %U %?\n ") ("f" "Fix me" entry (file+headline "~/org/fixmes.org" "Fixmes") "* TODO %?\n %a\n %i") )) (global-set-key (kbd "") 'my/counsel-org-agenda) (setq org-todo-keywords '((sequence "TODO" "WORK" "BLOC" "REVI" "|" "ABAN" "DONE"))) (setq org-todo-keyword-faces '(("TODO" . "firebrick2") ("WORK" . "yellow") ("BLOC" . "orange red") ("REVI" . "dodger blue") ("ABAN" . "slate blue") ("DONE" . "green3"))) (setq org-ellipsis " ▼") (dolist (face '(org-level-1 org-level-2 org-level-3 org-level-4 org-level-5)) (set-face-attribute face nil :weight 'semi-bold :height 1.0)) (dolist (kv '(("t" . "TODO") ("w" . "WORK") ("b" . "BLOC") ("r" . "REVI") ("a" . "ABAN") ("d" . "DONE"))) (define-key org-mode-map (kbd (concat "C-c t " (car kv))) `(lambda () (interactive) (org-todo ,(cdr kv))))) (add-hook 'org-mode-hook (lambda () (linum-mode 0) (setq-local line-spacing 0.2) (setq-local fill-column 80) (auto-fill-mode 1)))) ;; Org Bullets (use-package org-bullets :ensure t :after org :config (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))) ;; Evil-mode (defun my/evil-go-back () (interactive) (evil--jump-backward 1)) (defun my/evil-go-forward () (interactive) (evil--jump-forward 1)) (defun my/kill-current-buffer () (interactive) (kill-buffer (current-buffer))) (defun my/kill-window-or-buffer () "Closes current window if not last" (interactive) (if (one-window-p (selected-window)) (kill-buffer (current-buffer)) ;; If last window, just kill buffer (delete-window (selected-window)))) ;; else delete window (defun my/swiper-thing-at-point (thing) (interactive) (swiper (format "\\<%s\\>" (thing-at-point thing)))) (use-package evil :ensure t :demand t :config (evil-mode 1) (setq evil-ex-substitute-global t) (define-key evil-normal-state-map "/" 'swiper) (evil-ex-define-cmd "q" 'my/kill-window-or-buffer) (evil-ex-define-cmd "wq" (lambda () (interactive) (save-buffer) (my/kill-window-or-buffer))) (define-key evil-normal-state-map "gb" 'my/evil-go-back) (define-key evil-normal-state-map "gn" 'my/evil-go-forward) (define-key evil-motion-state-map [down-mouse-1] 'silence) (define-key evil-motion-state-map [mouse-1] 'silence) (define-key evil-insert-state-map (kbd "") 'nope) (define-key evil-insert-state-map (kbd "") 'nope) (define-key evil-insert-state-map (kbd "") 'nope) (define-key evil-insert-state-map (kbd "") 'nope) (define-key evil-normal-state-map (kbd "#") (lambda () (interactive) (my/swiper-thing-at-point 'word))) (define-key evil-normal-state-map (kbd "*") (lambda () (interactive) (my/swiper-thing-at-point 'symbol))) (setq-default evil-cross-lines t)) ;; Evil-indent-textobject, but better (use-package evil-indent-plus :ensure t :demand t :config (evil-indent-plus-default-bindings)) ;; Evil-org (use-package evil-org :ensure t :after org :delight :config (add-hook 'org-mode-hook 'evil-org-mode) (add-hook 'evil-org-mode-hook (lambda () (evil-org-set-key-theme '(navigation insert shift todo heading))))) (use-package evil-surround :ensure t :demand t :config (global-evil-surround-mode t)) (use-package projectile :ensure t :demand t :delight '(:eval (concat " Project[" (projectile-project-name) "]")) :config (projectile-global-mode t) (setq projectile-completion-system 'ivy)) ;; Company mode (use-package company :ensure t :demand t :delight :config (global-company-mode) (setq company-global-modes '(not git-commit-mode)) (setq company-minimum-prefix-length 2) (setq company-idle-delay 0.5)) ;; Auto-Complete ;;(use-package auto-complete ;; :ensure t ;; :demand t ;; :delight ;; :disabled ;; :config ;; (require 'auto-complete-config) ;; (setq ac-ignore-case nil) ;; (setq ac-sources '(ac-source-filename ;; ac-source-functions ;; ac-source-yasnippet ;; ac-source-variables ;; ac-source-symbols ;; ac-source-features ;; ac-source-words-in-all-buffer ;; ac-source-dictionary)) ;; (global-auto-complete-mode)) ;; folding ;; (use-package origami ;; :ensure t ;; :demand t ;; :config (progn ;; (setq origami-show-fold-header t) ;; (define-key evil-normal-state-map "z" 'origami-toggle-node) ;; (global-origami-mode))) ;; ivy (defun my/save-imenu-jump (item) "WIP: Tells evil-jump to save position before jumping via imenu (or counsel-imenu)" (evil--jumps-push)) (use-package ivy :ensure t :demand t :delight :config (ivy-mode 1) (setq ivy-use-virtual-buffers t) (setq ivy-count-format "(%d/%d) ") (advice-add 'imenu :before 'my/save-imenu-jump) (define-key ivy-minibuffer-map (kbd "") 'ivy-immediate-done) (set-face-attribute 'ivy-current-match nil :foreground "gold")) (use-package counsel :ensure t :demand t :config (global-set-key (kbd "C-c l") 'counsel-locate) (global-set-key (kbd "C-c m") 'counsel-imenu) (global-set-key (kbd "C-c _") 'counsel-git-grep)) ;; Quickly open external terminal (use-package terminal-here :ensure t :bind ("C-x t" . terminal-here-launch)) ;; swiper (use-package swiper :ensure t :demand t :bind ("C-s" . swiper)) ;; Neotree (use-package neotree :ensure t :bind ("C-x n" . neotree-show) :config (setq neo-theme 'ascii) (evil-define-key 'normal neotree-mode-map (kbd "+") 'neotree-create-node) (evil-define-key 'normal neotree-mode-map (kbd "g") 'neotree-refresh) (evil-define-key 'normal neotree-mode-map (kbd "d") 'neotree-delete-node) (evil-define-key 'normal neotree-mode-map (kbd "c") 'neotree-rename-node) (evil-define-key 'normal neotree-mode-map (kbd "TAB") 'neotree-enter) (evil-define-key 'normal neotree-mode-map (kbd "RET") 'neotree-enter) (evil-define-key 'normal neotree-mode-map (kbd "q") 'neotree-hide) (evil-define-key 'normal neotree-mode-map (kbd "DEL") 'neotree-select-up-node)) ;; Yasnippet (use-package yasnippet :ensure t :demand t :delight yas-minor-mode :config (yas-global-mode 1)) ;; avy - Disabled because it makes emacs laggy :( ;;(use-package avy ;; :ensure t ;; :demand t ;; :bind ("C-c f" . avy-goto-line) ;; :disabled ;; :config ;; (setq avy-keys '(?w ?a ?s ?d ?q ?e)) ;; (dolist (face avy-lead-faces) ;; (set-face-attribute face nil :background "gray28" :foreground "light blue" :weight 'bold))) ;; Magit (use-package magit :ensure t :bind ("C-x g" . magit-status) :config ;; Use insert mode in commit window (evil-set-initial-state 'git-commit-mode 'insert) ;; Magit fullscreen (defadvice magit-status (around magit-fullscreen activate) (window-configuration-to-register :magit-fullscreen) ad-do-it (delete-other-windows)) (defun magit-quit-fullscreen () (interactive) (kill-buffer) (jump-to-register :magit-fullscreen)) (define-key magit-status-mode-map (kbd "q") 'magit-quit-fullscreen)) ;; Undo-Tree (use-package undo-tree :delight :config (global-undo-tree-mode) (add-hook 'global-undo-tree-mode-hook (lambda () (linum-mode -1)))) ;; delight (delight 'abbrev-mode) ;; tabbing (setq-default tab-width 4) (setq-default LateX-indent-level 4) ;; (add-hook 'latex-mode-hook ;; (lambda () (setq indent-tabs-mode t))) ;; Activate line numbers (global-linum-mode t) ;; compilation buffer ; Set buffer scrolling (setq compilation-scroll-output 'first-error) (setq compilation-window-height 10) ;(defun my/compilation-bury-buffer-without-error (buffer string) ; (cond ((string-match "finished" string) ; (message "Build maybe successful: closing window.") ; (run-with-timer 3 nil ; 'delete-window ; (get-buffer-window buffer t))) ; (t (message "Compilation exited abnormaly: %s" string)))) ; ;(setq compilation-finish-function 'my/compilation-bury-buffer-without-error) ;(defun my/setup-compilation-window () ; (when (not (get-buffer-window "*compilation*")) ; (save-selected-window ; (save-excursion ; (let* ((w (split-window-vertically)) ; (h (window-height w))) ; (select-window w) ; (switch-to-buffer "*compilation*") ; (shrink-window (- h compilation-window-height))))))) ;(add-hook 'compilation-mode-hook 'my/setup-compilation-window) ;; Move between windows (global-set-key (kbd "C-x ") 'windmove-up) (global-set-key (kbd "C-x ") 'windmove-down) (global-set-key (kbd "C-x ") 'windmove-left) (global-set-key (kbd "C-x ") 'windmove-right) ; Whitespace mode toggle (global-set-key (kbd "C-x C-l") 'whitespace-mode) (defalias 'wsm 'whitespace-mode) (defun cycle-window () "cycles windows" (interactive) (select-window (next-window))) ;; (defun check-for-open-buffers () ;; (interactive) ;; (or (dolist ;; (buffer (buffer-list)) ;; (cond ;; ((string-match "^\\*.*\\*$" (buffer-name buffer)) ;; nil) ;; ((null (buffer-modified-p buffer)) ;; nil) ;; (t ;; (yes-or-no-p (format "Buffer %s is open. Exit anyway?" (buffer-name buffer)))))))) ;; Latex german (quail-define-package "latex-german" "UTF-8" "LaGe" t "Transforms umlauts to the better latex notation. ä -> \"a ö -> \"o ü -> \"u Ä -> \"A Ö -> \"O Ü -> \"U ß -> \"s" nil t nil nil nil nil nil nil nil nil t) (quail-define-rules ("ä" ["\"a"]) ("ö" ["\"o"]) ("ü" ["\"u"]) ("Ä" ["\"A"]) ("Ö" ["\"O"]) ("Ü" ["\"U"]) ("ß" ["\"s"]) ) (add-hook 'latex-mode-hook (lambda () (set-input-method "latex-german") (local-set-key "\"" 'self-insert-command))) ;; Treat _ as part of word in some modes (defun treat-underscore () (modify-syntax-entry ?_ "w")) (add-hook 'prog-mode-hook 'treat-underscore) ;; Split windows horizontally preferred (setq split-height-threshold 6) (setq split-width-threshold 20) ;; Overlay windows (What does it do?) (add-to-list 'display-buffer-alist '("*Apropos*" display-buffer-same-window)) (add-to-list 'display-buffer-alist '("*Help*" display-buffer-in-side-window)) (add-to-list 'display-buffer-alist '("*evil-jumps*" display-buffer-in-side-window)) (add-to-list 'display-buffer-alist '("*compilation*" (display-buffer-reuse-window display-buffer-in-side-window) (side . bottom) (size . 0.2))) (add-to-list 'display-buffer-alist '("*undo-tree*" (display-buffer-reuse-window display-buffer-in-side-window) (side . right) (size . 0.2))) ;; Insert time, german format (defun time-german () (interactive) (insert (format-time-string "%H:%M"))) (global-set-key (kbd "C-c C-d") 'time-german) ;; Load local emacs settings (let ((local-config (concat user-emacs-directory "init.local"))) (when (file-exists-p (concat local-config ".el")) (load local-config)))