dotfiles/emacs/.emacs.d/config.org

7.0 KiB

Emacs configure

Packages

Package Archives

Adding the melpa package repository to Emacs.

(require 'package)
(add-to-list 'package-archives 
    '("melpa" . "http://melpa.org/packages/"))
(package-initialize)

Installed packages:

  • aggressive-indent - Minor mode to aggressively keep your code always indented
  • anaconda-mode - Code navigation, documentation lookup and completion for Python
  • auctex - Integrated environment for TeX
  • counsel - Various completion functions using Ivy
  • eclim - An interface to the Eclipse IDE.
  • flycheck - On-the-fly syntax checking
  • forest-blue-theme - Emacs theme with a dark background.
  • google-this - A set of functions and bindings to google under point.
  • ivy - Incremental Vertical completYon
  • material-theme - A Theme based on the colors of the Google Material Design
  • ox-twbs - Bootstrap compatible HTML Back-End for Org
  • rainbow-delimiters - Highlight brackets according to their depth
  • rainbow-mode - Colorize color names in buffers
  • smartparens - Automatic insertion, wrapping and paredit-like navigation with user defined pairs.
  • swiper - Isearch with an overview. Oh, man!
  • yasnippet - Yet another snippet extension for Emacs.
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure t)

(use-package aggressive-indent)
(use-package anaconda-mode)
;; (use-package auctex) throws error with use-package
(use-package counsel)
(use-package eclim)
(use-package flycheck)
(use-package google-this)
(use-package ivy)
(use-package material-theme)
(use-package ox-twbs)
(use-package rainbow-delimiters)
(use-package rainbow-mode)
(use-package smartparens)
(use-package swiper)
(use-package yasnippet)

Themes

Using the Material-Theme.

(load-theme 'material t)

Changes the Emacs background to the terminals defaults. (Generally)

(add-hook 'window-setup-hook 
      '(lambda () 
         (set-face-background 'default "unspecified-bg")))

Functions

Cut/Copy and Paste by Boruch Baum

Copy

Copy the marked area to the clipboard.

(defun copy-to-xclipboard(arg)
  (interactive "P")
  (cond
   ((not (use-region-p))
    (message "Nothing to yank to X-clipboard"))
   ((and (not (display-graphic-p))
	 (/= 0 (shell-command-on-region
		(region-beginning) (region-end) "xsel -i -b")))
    (error "Is program `xsel' installed?"))
   (t
    (when (display-graphic-p)
      (call-interactively 'clipboard-kill-ring-save))
    (message "Yanked region to X-clipboard")
    (deactivate-mark))))

Cut

Cut the marked area to the clipboard.

(defun cut-to-xclipboard(arg)
  (interactive "P")
  (cond
   ((not (use-region-p))
    (message "Nothing to yank to X-clipboard"))
   ((and (not (display-graphic-p))
	 (/= 0 (shell-command-on-region
		(region-beginning) (region-end) "xsel -i -b")))
    (error "Is program `xsel' installed?"))
   (t
    (when (display-graphic-p)
    (call-interactively 'clipboard-kill-ring-save))
    (message "Yanked region to X-clipboard")
    (kill-region  (region-beginning) (region-end))
    (deactivate-mark))))

Paste

Paste from the clipboard.

(defun paste-from-xclipboard()
  "Uses shell command `xsel -o' to paste from x-clipboard. With
    one prefix arg, pastes from X-PRIMARY, and with two prefix args,
    pastes from X-SECONDARY."
  (interactive)
  (if (display-graphic-p)
      (clipboard-yank)
    (let*
	((opt (prefix-numeric-value current-prefix-arg))
	 (opt (cond
	       ((=  1 opt) "b")
	       ((=  4 opt) "p")
	       ((= 16 opt) "s"))))
      (insert (shell-command-to-string (concat "xsel -o -" opt))))))

Personal functions

Go back to indentation, if you are at the indentation, go to beginning of the line instead.

  (defun back-to-indentation-or-beginning () 
  "Go back to indentation, if at indentation go to beginning of line"
  (interactive)
   (if (= (point) (progn (back-to-indentation) (point)))
       (beginning-of-line)))

Sets the background of Emacs in terminal-mode to the terminals. Doesn't change it in window mode tho.

(defun transparent-terminal ()
  (unless (display-graphic-p (selected-frame))
    (set-face-background 'default "unspecified-bg" (selected-frame))))

Modes

Window Modes

(menu-bar-mode -1)

Python

Using Anaconda-mode as default python development mode

(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'anaconda-eldoc-mode)

LaTeX

Some default settings for LaTeX-Mode. AucTeX is needed.

(require 'tex)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

Org

Enable a Twitter Bootstrap mode as an export mode for Org-mode.

(require 'ox-twbs)

Use Evince as default pdf viewer.

(add-hook 'org-mode-hook
      '(lambda ()
         (delete '("\\.pdf\\'" . default) org-file-apps)
         (add-to-list 'org-file-apps '("\\.pdf\\'" . "evince %s"))))

Activate Syntax Highlighting in Org-mode.

(add-hook 'org-mode-hook 
      '(lambda () 
         (setq org-src-fontify-natively t)))

Add rainbow-delimiters in org-mode

(add-hook 'org-mode-hook 'rainbow-delimiters-mode)

Ivy/Counsel/Swiper

(counsel-mode 1)

Parenthesis

(require 'paren)
(setq show-paren-style 'parenthesis)
(show-paren-mode +1)

Highlight line

Globaly highlight the current line in a slightly darker shade of grey.

(global-hl-line-mode 1)
(set-face-background 'hl-line "#141b1e")
(set-face-foreground 'highlight nil)

Yasnippet

(require 'yasnippet)
(setq yas-snippet-dirs
  '("~/.emacs.d/snippets/"))
(yas-global-mode 1)

Personal mode

(defvar my-keys-minor-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-a") 'back-to-indentation-or-beginning)
    (define-key map (kbd "C-c M-w") 'copy-to-xclipboard)
    (define-key map (kbd "C-c C-w") 'cut-to-xclipboard)
    (define-key map (kbd "C-c M-y") 'paste-from-xclipboard)
    map)
  "my-keys-minor-mode keymap.")

(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  :init-value t
  :lighter " my-keys")

(my-keys-minor-mode 1)