yuzu-emacs is my personal configuration for emacs. It disables some visual annoyances and sets some helpful functions and keybinds. Currently configured for C/C++, Ruby and Python.
Some quality-of-life improvements
(setq inhibit-startup-message t)
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(setq backup-directory-alist '(("." . "~/.emacs.d/emacs_saves")))
(setq ring-bell-function 'ignore)
(set-fringe-mode 0)
(eval-after-load 'tramp '(setenv "SHELL" "/bin/bash"))
(setq dired-kill-when-opening-new-dired-buffer t)
Certain modes will break with line-numbers-mode (e.g. ansi-term) so I’m only enabling it on some major modes rather than globally. Also using relative line numbers.
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(add-hook 'text-mode-hook 'display-line-numbers-mode)
(setq display-line-numbers 'relative)
(column-number-mode 1)
(global-whitespace-mode 1)
(global-prettify-symbols-mode t)
Set a different color for each matching pair of brackets
(set-face-foreground 'rainbow-delimiters-unmatched-face "red")
(set-face-foreground 'rainbow-delimiters-depth-1-face "black")
(set-face-foreground 'rainbow-delimiters-depth-2-face "blue")
(set-face-foreground 'rainbow-delimiters-depth-3-face "dark magenta")
(set-face-foreground 'rainbow-delimiters-depth-4-face "dark orange4")
(set-face-foreground 'rainbow-delimiters-depth-5-face "chocolate4")
(set-face-foreground 'rainbow-delimiters-depth-6-face "gray42")
(set-face-foreground 'rainbow-delimiters-depth-7-face "violetred4")
(set-face-foreground 'rainbow-delimiters-depth-8-face "dodgerblue4")
(set-face-foreground 'rainbow-delimiters-depth-9-face "dark goldenrod")
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(show-paren-mode 1)
(setq scroll-conservatively 100)
(add-to-list 'default-frame-alist '(font . "Iosevka Term Custom-13"))
(setq font-lock-maximum-decoration '((t . 1)))
(setq display-time-day-and-date t
display-time-24hr-format t)
(display-time)
(setq default-directory "~/")
(setq x-select-enable-clipboard t)
(electric-pair-mode t)
(global-subword-mode 1)
(with-eval-after-load 'electric
(electric-indent-mode -1))
(setq-default indent-tabs-mode nil)
(setq backward-delete-char-untabify-method nil)
(setq c-default-style "k&r")
(setq tab-width 4)
(setq standard-indent 4)
(setq c-basic-offset 4)
(setq python-indent-offset 4)
(setq sgml-basic-offset 4)
(setq ruby-indent-level 4)
(add-hook 'prog-mode-hook 'electric-indent-local-mode)
(defalias 'yes-or-no-p 'y-or-n-p)
(setq ido-enable-flex-matching nil)
(setq ido-create-new-buffer 'always)
(setq ido-everywhere t)
(ido-mode 1)
I don’t like the default buffer list. I’m using ido-switch-buffer on “C-x C-b” and ibuffer on “C-x b”
(global-set-key (kbd "C-x C-b") 'ido-switch-buffer)
(global-set-key (kbd "C-x b") 'ibuffer)
(add-to-list 'display-buffer-alist '("\\.pdf$" .
(display-buffer-pop-up-window-split-horizontally)))
(defun display-buffer-pop-up-window-split-horizontally (buffer alist)
"Call `display-buffer-pop-up-window', setting
`split-height-threshold' and `split-width-threshold' so that
the split is always horizontal."
(let ((split-height-threshold nil)
(split-width-threshold 0))
(display-buffer-pop-up-window buffer alist)))
(setq scheme-program-name "mit-scheme")
My preferred org-mode defaults
(use-package org
:config
(add-hook 'org-mode-hook 'org-indent-mode))
(use-package org-indent
:diminish org-indent-mode)
(use-package htmlize
:ensure t)
(setq org-latex-pdf-process
'("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))
(setq org-latex-toc-command "\\tableofcontents \\clearpage")
(setq org-latex-packages-alist '(("margin=1in" "geometry" nil)))
(setq org-latex-caption-above nil)
(setq org-html-table-caption-above nil)
(unless (boundp 'org-latex-classes)
(setq org-latex-classes nil))
(add-to-list 'org-latex-classes
'("ethz"
"\\documentclass[a4paper,11pt,titlepage]{memoir}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{fixltx2e}
\\usepackage{graphicx}
\\usepackage{longtable}
\\usepackage{float}
\\usepackage{wrapfig}
\\usepackage{rotating}
\\usepackage[normalem]{ulem}
\\usepackage{amsmath}
\\usepackage{textcomp}
\\usepackage{marvosym}
\\usepackage{wasysym}
\\usepackage{amssymb}
\\usepackage{hyperref}
\\usepackage{mathpazo}
\\usepackage{color}
\\usepackage{enumerate}
\\definecolor{bg}{rgb}{0.95,0.95,0.95}
\\tolerance=1000
[NO-DEFAULT-PACKAGES]
[PACKAGES]
[EXTRA]
\\linespread{1.1}
\\hypersetup{pdfborder=0 0 0}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(add-to-list 'org-latex-classes
'("article"
"\\documentclass[11pt,a4paper]{article}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{fixltx2e}
\\usepackage{graphicx}
\\usepackage{longtable}
\\usepackage{float}
\\usepackage{wrapfig}
\\usepackage{rotating}
\\usepackage[normalem]{ulem}
\\usepackage{amsmath}
\\usepackage{textcomp}
\\usepackage{marvosym}
\\usepackage{wasysym}
\\usepackage{amssymb}
\\usepackage{hyperref}
\\usepackage{mathpazo}
\\usepackage{color}
\\usepackage{enumerate}
\\definecolor{bg}{rgb}{0.95,0.95,0.95}
\\tolerance=1000
[NO-DEFAULT-PACKAGES]
[PACKAGES]
[EXTRA]
\\linespread{1.1}
\\pagenumbering{roman}
\\hypersetup{pdfborder=0 0 0}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")))
(add-to-list 'org-latex-classes '("ebook"
"\\documentclass[11pt, oneside]{memoir}
\\setstocksize{9in}{6in}
\\settrimmedsize{\\stockheight}{\\stockwidth}{*}
\\setlrmarginsandblock{1in}{1in}{*} % Left and right margin
\\setulmarginsandblock{1in}{1in}{*} % Upper and lower margin
\\checkandfixthelayout
% Much more laTeX code omitted
"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")))
Function to toggle transparency
(defconst frame-transparency 85)
(defun toggle-transparency ()
(interactive)
(let ((frame-alpha (frame-parameter nil 'alpha)))
(if (or (not frame-alpha)
(= (cadr frame-alpha) 100))
(set-frame-parameter nil 'alpha
`(,frame-transparency
,frame-transparency))
(set-frame-parameter nil 'alpha '(100 100)))))
(global-set-key (kbd "C-c t") 'toggle-transparency)
(defun config-visit ()
(interactive)
(find-file "~/.emacs.d/config.org"))
(global-set-key (kbd "C-c e") 'config-visit)
(defun config-reload ()
(interactive)
(org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
(global-set-key (kbd "C-c l") 'config-reload)
(defun kill-all-buffers ()
(interactive)
(mapc 'kill-buffer (buffer-list)))
(global-set-key (kbd "C-M-s-k") 'kill-all-buffers)
(defun kill-curr-buffer ()
(interactive)
(kill-buffer (current-buffer)))
(global-set-key (kbd "C-x C-k") 'kill-curr-buffer)
(defun find-next-file (&optional backward)
"Find the next file (by name) in the current directory.
With prefix arg, find the previous file."
(interactive "P")
(when buffer-file-name
(let* ((file (expand-file-name buffer-file-name))
(files (cl-remove-if (lambda (file) (cl-first (file-attributes file)))
(sort (directory-files (file-name-directory file) t nil t) 'string<)))
(pos (mod (+ (cl-position file files :test 'equal) (if backward -1 1))
(length files))))
(find-file (nth pos files)))))
(global-set-key (kbd "C-c C-n") 'find-next-file)
(global-set-key (kbd "C-c C-p") (lambda () (interactive) (find-next-file :backward)))
Taken from Xah Lee.
(defvar xah-brackets '("“”" "()" "[]" "{}" "<>" "<>" "()" "[]" "{}"
"⦅⦆" "〚〛" "⦃⦄" "‹›" "«»" "「」" "〈〉" "《》" "【】"
"〔〕" "⦗⦘" "『』" "〖〗" "〘〙" "「」" "⟦⟧" "⟨⟩" "⟪⟫"
"⟮⟯" "⟬⟭" "⌈⌉" "⌊⌋" "⦇⦈" "⦉⦊" "❛❜" "❝❞" "❨❩" "❪❫"
"❴❵" "❬❭" "❮❯" "❰❱" "❲❳" "〈〉" "⦑⦒" "⧼⧽" "﹙﹚" "﹛﹜"
"﹝﹞" "⁽⁾" "₍₎" "⦋⦌" "⦍⦎" "⦏⦐" "⁅⁆" "⸢⸣" "⸤⸥" "⟅⟆"
"⦓⦔" "⦕⦖" "⸦⸧" "⸨⸩" "⦅⦆")
"A list of strings, each element is a string of 2 chars, the left bracket and a matching right bracket.
Used by `xah-select-text-in-quote' and others.")
(defconst xah-left-brackets
(mapcar (lambda (x) (substring x 0 1)) xah-brackets)
"List of left bracket chars. Each element is a string.")
(defconst xah-right-brackets
(mapcar (lambda (x) (substring x 1 2)) xah-brackets)
"List of right bracket chars. Each element is a string.")
(defun xah-backward-left-bracket ()
"Move cursor to the previous occurrence of left bracket.
The list of brackets to jump to is defined by `xah-left-brackets'.
URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
Version: 2015-10-01"
(interactive)
(re-search-backward (regexp-opt xah-left-brackets) nil t))
(defun xah-forward-right-bracket ()
"Move cursor to the next occurrence of right bracket.
The list of brackets to jump to is defined by `xah-right-brackets'.
URL `http://xahlee.info/emacs/emacs/emacs_navigating_keys_for_brackets.html'
Version: 2015-10-01"
(interactive)
(re-search-forward (regexp-opt xah-right-brackets) nil t))
Inserts a newline above or below, like O and o in vim
(defun newline-above-and-move ()
"Inserts a new line above current line and moves cursor to that position"
(interactive)
(beginning-of-line)
(newline-and-indent)
(previous-line))
(global-set-key (kbd "M-O") 'newline-above-and-move)
(defun newline-below-and-move ()
"Inserts a new line below current line and moves cursor to that position"
(interactive)
(end-of-line)
(newline-and-indent))
(global-set-key (kbd "M-o") 'newline-below-and-move)
(setq-default compilation-scroll-output t)
(defun colorize-compilation-buffer ()
(read-only-mode nil)
(ansi-color-apply-on-region compilation-filter-start (point))
(read-only-mode 1))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
Hides minor modes to prevent cluttering modeline
(use-package diminish
:ensure t
:init
(diminish 'subword-mode)
(diminish 'visual-line-mode)
(diminish 'abbrev-mode)
(diminish 'auto-fill-function)
(diminish 'eldoc-mode))
Completion menu for keybinds
(use-package which-key
:ensure t
:diminish which-key-mode
:init
(which-key-mode))
Displays colour of a hex code as background colour behind said hex code
(use-package rainbow-mode
:ensure t
:init
(add-hook 'css-mode-hook 'rainbow-mode))
Sly REPL
(use-package sly
:ensure t)
(setq inferior-lisp-program "/usr/local/bin/sbcl")
Minibuffer for “execute-extended-commands”
(use-package smex
:ensure t
:init (smex-initialize)
:bind
("M-x" . smex))
Allow for editing files as sudo
(use-package sudo-edit
:ensure t
:config
(setq sudo-edit-local-method "sudo")
:bind
("s-C-e" . sudo-edit))
Display ^L page breaks as a horizontal line
(use-package page-break-lines
:ensure t
:diminish page-break-lines-mode)
Allow for editing with multiple cursors at the same time
(use-package multiple-cursors
:ensure t
:bind
("C-S-c C-S-c" . mc/edit-lines)
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)
("C-c C-<" . mc/mark-all-like-this))
Move line or region around using M-p M-n
(use-package move-text
:ensure t
:bind
("M-p" . move-text-up)
("M-n" . move-text-down))
Magical Git interface
(use-package magit
:ensure t
:config
(setq magit-auto-revert-mode nil))
Mode for OpenGL Shading Language
(use-package glsl-mode
:ensure t
:config
(add-to-list 'auto-mode-alist '("\\.fs$" . glsl-mode)))
simpc is a simple c mode that aims to be faster than the default c-mode.
(add-to-list 'auto-mode-alist '("\\.[hc]\\(pp\\)?\\'" . simpc-mode))
(defun astyle-buffer (&optional justify)
(interactive)
(let ((saved-line-number (line-number-at-pos)))
(shell-command-on-region
(point-max)
(point-min)
"astyle --style=kr"
nil
t)
(goto-line saved-line-number)))
(add-hook 'simpc-mode-hook
(lambda ()
(interactive)
(setq-local fill-paragraph-function 'astyle-buffer)))
Company is an autocompletion frontend
(use-package company
:ensure t
:config
(setq company-idle-delay 0)
(setq company-minimum-prefix-length 1)
:init
(add-hook 'after-init-hook 'global-company-mode))
(with-eval-after-load 'company
(define-key company-active-map (kbd "M-n") nil)
(define-key company-active-map (kbd "M-p") nil)
(define-key company-active-map (kbd "C-n") 'company-select-next)
(define-key company-active-map (kbd "C-p") 'company-select-previous))
Autocompletion backend for C and C++
(use-package company-irony
:ensure t
:config
(require 'company)
(add-to-list 'company-backends 'company-irony))
(use-package irony
:ensure t
:config
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'simpc-mode-hook 'irony-mode)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
(push 'c-mode irony-supported-major-modes)
(push 'c++-mode irony-supported-major-modes)
(push 'simpc-mode irony-supported-major-modes)
(use-package inf-ruby
:ensure t)
(use-package robe
:ensure t
:diminish robe-mode
:config
(require 'company)
(add-hook 'ruby-mode-hook 'robe-mode)
(add-to-list 'company-backends 'company-robe))
(use-package ruby-electric
:ensure t
:diminish ruby-electric-mode
:config
(add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t))))
(use-package rubocop
:ensure t
:init
(add-hook 'ruby-mode-hook 'rubocop-mode)
:diminish rubocop-mode)
(use-package pyvenv
:ensure t
:config
(pyvenv-mode 1))
Some keybinds to make life easier
(global-set-key (kbd "<menu>") 'smex)
(global-set-key (kbd "C-c o") 'browse-url-at-point)
(global-set-key (kbd "s-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "s-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "s-C-<down>") 'shrink-window)
(global-set-key (kbd "s-C-<up>") 'enlarge-window)
(global-set-key (kbd "C-9") 'xah-backward-left-bracket)
(global-set-key (kbd "C-0") 'xah-forward-right-bracket)
(global-set-key (kbd "C-c c") 'comment-line)
(global-set-key (kbd "C-c m") 'compile)
(global-set-key (kbd "C-c s") 'inf-ruby)
(global-set-key (kbd "C-.") 'duplicate-line)
(setq duplicate-line-final-position 1)
(global-set-key (kbd "C-s-.") 'copy-from-above-command)