Refactored emacs config to use "use-package"

This commit is contained in:
madmaurice 2017-05-17 20:43:49 +02:00
parent 078dc3b90b
commit 40e95992de

View file

@ -1,16 +1,4 @@
(package-initialize) (package-initialize)
(defun ensure-packages-installed (packages)
"Ensure packages are installed"
(mapcar
(lambda (package)
(if (package-installed-p package)
nil
(if (y-or-n-p (format "Package %s is missing. Install it? " package))
(package-install package)
package)))
packages))
(require 'package) (require 'package)
(push '("marmalade" . "http://marmalade-repo.org/packages/") package-archives) (push '("marmalade" . "http://marmalade-repo.org/packages/") package-archives)
@ -49,25 +37,61 @@
(or (file-exists-p package-user-dir) (or (file-exists-p package-user-dir)
(package-refresh-contents)) (package-refresh-contents))
;; Install packages ;; Install use-package
(ensure-packages-installed '(org evil evil-surround magit evil-magit auto-complete yasnippet)) (defun ensure-package-installed (package)
"Ensure packages are installed"
(if (package-installed-p package)
nil
(progn
(package-refresh-contents)
(package-install package))))
;; tabbing (ensure-package-installed 'use-package)
(setq-default indent-tabs-mode t)
(setq-default tab-width 4)
;; Evil mode <3 ;; Org-mode
(require 'evil) (use-package org
(evil-mode t) :ensure t)
;; auto-complete ;; Evil-mode
(require 'auto-complete) (use-package evil
(require 'auto-complete-config) :ensure t
(ac-config-default) :demand t
:config (evil-mode 1))
;; Auto-Complete
(use-package auto-complete
:ensure t
:demand t
:config (progn
(require 'auto-complete-config)
(ac-config-default)))
;; Yasnippet ;; Yasnippet
(require 'yasnippet) (use-package yasnippet
(yas-global-mode 1) :demand t
:config (yas-global-mode 1))
;; Magit
(use-package magit
:bind ("C-x g" . magit-status))
;; Easy terminal
(setq my/default-shell (or (executable-find "zsh") (executable-find "bash")))
(defun term-split ()
"creates terminal window below"
(interactive)
(let ((window (split-window-below -7)))
(select-window window)
(term my/default-shell)))
(use-package term
:bind ("C-x t" . term-split))
;; tabbing (doesn't really work yet)
(setq-default indent-tabs-mode t)
(setq-default tab-width 4)
(setq-default LateX-indent-level 4)
;; Window movement ;; Window movement
(global-set-key (kbd "C-x <up>") 'windmove-up) (global-set-key (kbd "C-x <up>") 'windmove-up)
@ -75,10 +99,6 @@
(global-set-key (kbd "C-x <left>") 'windmove-left) (global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right) (global-set-key (kbd "C-x <right>") 'windmove-right)
;; Magit
(global-set-key (kbd "C-x g") 'magit-status)
;; Window cycling
(defun cycle-window () (defun cycle-window ()
"cycles windows" "cycles windows"
(interactive) (interactive)
@ -86,17 +106,6 @@
(global-set-key (kbd "<C-tab>") 'cycle-window) (global-set-key (kbd "<C-tab>") 'cycle-window)
;; Easy terminal
(defun term-split ()
"creates terminal window below"
(interactive)
(let ((window (split-window-below -7)))
(select-window window)
(term "/bin/zsh")))
;(set-window-dedicated-p window t)))
(global-set-key (kbd "C-x t") 'term-split)
;; Kill term buffer on exit ;; Kill term buffer on exit
;(defun term-handle-exit--close-buffer (&rest args) ;(defun term-handle-exit--close-buffer (&rest args)
; (when (null (get-buffer-process (current-buffer))) ; (when (null (get-buffer-process (current-buffer)))
@ -108,27 +117,40 @@
; (advice-add 'term-handle-exit :after #'term-handle-exit--close-buffer) ; (advice-add 'term-handle-exit :after #'term-handle-exit--close-buffer)
; Latex german ;; Latex german
(defun evil-is-insert () (string= evil-state "insert")) (quail-define-package "latex-german" "UTF-8" "LaGe" t
(defun latex-german-umlauts () "Transforms umlauts to the better latex notation.
"Sets keys like ä to write \"a" ä -> \"a
(message "Latex German Umlauts loaded.") ö -> \"o
(local-set-key (kbd "ä") (lambda () (interactive) (when (evil-is-insert) (insert "\"a")))) ü -> \"u
(local-set-key (kbd "ö") (lambda () (interactive) (when (evil-is-insert) (insert "\"o")))) Ä -> \"A
(local-set-key (kbd "ü") (lambda () (interactive) (when (evil-is-insert) (insert "\"u")))) Ö -> \"O
(local-set-key (kbd "Ä") (lambda () (interactive) (when (evil-is-insert) (insert "\"A")))) Ü -> \"U
(local-set-key (kbd "Ö") (lambda () (interactive) (when (evil-is-insert) (insert "\"O")))) ß -> \"s"
(local-set-key (kbd "Ü") (lambda () (interactive) (when (evil-is-insert) (insert "\"U")))) nil t nil nil nil nil nil nil nil nil t)
(local-set-key (kbd "ß") (lambda () (interactive) (when (evil-is-insert) (insert "\"s"))))) (quail-define-rules
("ä" ["\"a"])
("ö" ["\"o"])
("ü" ["\"u"])
("Ä" ["\"A"])
("Ö" ["\"O"])
("Ü" ["\"U"])
("ß" ["\"s"])
)
(add-hook 'latex-mode-hook 'latex-german-umlauts) (add-hook 'latex-mode-hook (lambda ()
(set-input-method "latex-german")
(local-set-key "\"" 'self-insert-command)))
;; Split windows horizontally preferred ;; Split windows horizontally preferred
(setq split-height-threshold 6) (setq split-height-threshold 6)
(setq split-width-threshold 20) (setq split-width-threshold 20)
;; Overlay windows ;; Overlay windows (What does it do?)
(add-to-list 'display-buffer-alist (add-to-list 'display-buffer-alist
'("*Apropos*" display-buffer-same-window)) '("*Apropos*" display-buffer-same-window))
(add-to-list 'display-buffer-alist (add-to-list 'display-buffer-alist
'("*Help*" display-buffer-same-window)) '("*Help*" display-buffer-same-window))
;; Change all prompts to y or n
(fset 'yes-or-no-p 'y-or-n-p)