Emacs Configs

1 Packages

1.1 Installed packages:

  • aggressive-indent
  • anaconda-mode
  • auctex
  • dash
  • eclim
  • epl
  • f
  • flycheck
  • forest-blue-theme
  • google-this
  • highlight-indentation
  • ivy
  • ox-twbs
  • pkg-info
  • popup
  • pythonic
  • rainbow-delimiters
  • rainbow-mode
  • s
  • smartparens
  • yasnippet

Adding the melpa package repository to Emacs.

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

2 Themes

Using the Forest Blue-Theme

(load-theme 'forest-blue t)

3 Functions

3.1 Cut/Copy and Paste by Boruch Baum

3.1.1 Copy

(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))))

3.1.2 Cut

(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))))

3.1.3 Paste

(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))))))

3.2 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)))

3.3 Personal mode to overwrite Emacs' default keybindings

(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")

4 Mode customization

4.1 Global Modes

(global-hl-line-mode 1)
(my-keys-minor-mode 1)
(ivy-mode 1)
(show-paren-mode +1)
(menu-bar-mode -1)
(yas-global-mode 1)

4.2 Python

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

4.3 LaTeX

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

4.4 Org

(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-delimiteres in org-mode (add-hook 'org-mode-hook 'rainbow-delimiters-mode)

4.5 Ivy


4.6 Parenthesis

(require 'paren)
(setq show-paren-style 'parenthesis)

4.7 Hightlight Line

(set-face-background 'hl-line "#333333")
(set-face-foreground 'highlight nil)

4.8 Yasnippet

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