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)
(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)
(push '("marmalade" . "http://marmalade-repo.org/packages/") package-archives)
@ -49,25 +37,61 @@
(or (file-exists-p package-user-dir)
(package-refresh-contents))
;; Install packages
(ensure-packages-installed '(org evil evil-surround magit evil-magit auto-complete yasnippet))
;; 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))))
;; tabbing
(setq-default indent-tabs-mode t)
(setq-default tab-width 4)
(ensure-package-installed 'use-package)
;; Evil mode <3
(require 'evil)
(evil-mode t)
;; Org-mode
(use-package org
:ensure t)
;; auto-complete
(require 'auto-complete)
(require 'auto-complete-config)
(ac-config-default)
;; Evil-mode
(use-package evil
:ensure t
: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
(require 'yasnippet)
(yas-global-mode 1)
(use-package yasnippet
: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
(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 <right>") 'windmove-right)
;; Magit
(global-set-key (kbd "C-x g") 'magit-status)
;; Window cycling
(defun cycle-window ()
"cycles windows"
(interactive)
@ -86,17 +106,6 @@
(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
;(defun term-handle-exit--close-buffer (&rest args)
; (when (null (get-buffer-process (current-buffer)))
@ -108,27 +117,40 @@
; (advice-add 'term-handle-exit :after #'term-handle-exit--close-buffer)
; Latex german
(defun evil-is-insert () (string= evil-state "insert"))
(defun latex-german-umlauts ()
"Sets keys like ä to write \"a"
(message "Latex German Umlauts loaded.")
(local-set-key (kbd "ä") (lambda () (interactive) (when (evil-is-insert) (insert "\"a"))))
(local-set-key (kbd "ö") (lambda () (interactive) (when (evil-is-insert) (insert "\"o"))))
(local-set-key (kbd "ü") (lambda () (interactive) (when (evil-is-insert) (insert "\"u"))))
(local-set-key (kbd "Ä") (lambda () (interactive) (when (evil-is-insert) (insert "\"A"))))
(local-set-key (kbd "Ö") (lambda () (interactive) (when (evil-is-insert) (insert "\"O"))))
(local-set-key (kbd "Ü") (lambda () (interactive) (when (evil-is-insert) (insert "\"U"))))
(local-set-key (kbd "ß") (lambda () (interactive) (when (evil-is-insert) (insert "\"s")))))
;; 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 'latex-german-umlauts)
(add-hook 'latex-mode-hook (lambda ()
(set-input-method "latex-german")
(local-set-key "\"" 'self-insert-command)))
;; Split windows horizontally preferred
(setq split-height-threshold 6)
(setq split-width-threshold 20)
;; Overlay windows
;; 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-same-window))
;; Change all prompts to y or n
(fset 'yes-or-no-p 'y-or-n-p)