Skip to content

yuzu-eva/yuzu-emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

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.

QoL section

Some quality-of-life improvements

Disable annoyances

Disable default startup screen

(setq inhibit-startup-message t)

Disable most GUI elements

(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

Change directory where backups are saved

(setq backup-directory-alist '(("." . "~/.emacs.d/emacs_saves")))

Disable ring-bell

(setq ring-bell-function 'ignore)  

Disable fringes

(set-fringe-mode 0)

Use bash for TRAMP

(eval-after-load 'tramp '(setenv "SHELL" "/bin/bash"))

Kill dired-buffer when changing directory

(setq dired-kill-when-opening-new-dired-buffer t)

Visual improvements

Enable line number

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)

Enable column number

(column-number-mode 1)

Enable whitespace-mode

(global-whitespace-mode 1)

Enable prettify symbols

(global-prettify-symbols-mode t)  

Enable rainbow-delimiters in all programming modes

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 parent parentheses

(show-paren-mode 1)

Enable conservative scrolling

(setq scroll-conservatively 100)  

Set font

(add-to-list 'default-frame-alist '(font . "Iosevka Term Custom-13"))

Keep syntax-highlighting to a minimum

(setq font-lock-maximum-decoration '((t . 1)))

Display date-time in status bar

(setq display-time-day-and-date t
   display-time-24hr-format t)
(display-time)

Ease of use

Set default directory

(setq default-directory "~/")

Enable copy-pasting outside of emacs

(setq x-select-enable-clipboard t)

Enable pair-matching

(electric-pair-mode t)  

Enable subword-mode

(global-subword-mode 1)

Indentation

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

Change yes/no prompt to just y/n

(defalias 'yes-or-no-p 'y-or-n-p)  

Enable ido mode

(setq ido-enable-flex-matching nil)
(setq ido-create-new-buffer 'always)
(setq ido-everywhere t)
(ido-mode 1)

Change default buffer-list

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)

Display PDFs to the right instead of below current window

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

Use MIT-Scheme

(setq scheme-program-name "mit-scheme")

Org mode

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

Custom functions

Toggle Transparency

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)

Config edit/reload

edit

(defun config-visit ()
  (interactive)
  (find-file "~/.emacs.d/config.org"))
(global-set-key (kbd "C-c e") 'config-visit)

reload

(defun config-reload ()
  (interactive)
  (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
(global-set-key (kbd "C-c l") 'config-reload)

Kill all buffers

(defun kill-all-buffers ()
  (interactive)
  (mapc 'kill-buffer (buffer-list)))
(global-set-key (kbd "C-M-s-k") 'kill-all-buffers)

Always kill current buffer

(defun kill-curr-buffer ()
  (interactive)
  (kill-buffer (current-buffer)))
(global-set-key (kbd "C-x C-k") 'kill-curr-buffer)

Find-next-file

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

Moving around brackets

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

Insert newline above/below

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)

Compilation mode

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

Use-Package section

Initialize diminish

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

Initialize which-key

Completion menu for keybinds

(use-package which-key
  :ensure t
  :diminish which-key-mode
  :init
  (which-key-mode))

Initialize rainbow-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))

Initialize sly

Sly REPL

(use-package sly
  :ensure t)
 (setq inferior-lisp-program "/usr/local/bin/sbcl")

Initialize smex

Minibuffer for “execute-extended-commands”

(use-package smex
  :ensure t
  :init (smex-initialize)
  :bind
  ("M-x" . smex))

Initialize sudo-edit

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

Initialize page-break-lines

Display ^L page breaks as a horizontal line

(use-package page-break-lines
  :ensure t
  :diminish page-break-lines-mode)

Initialize multiple-cursors

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

Initialize move-text

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

Initialize magit

Magical Git interface

(use-package magit
  :ensure t
  :config
  (setq magit-auto-revert-mode nil))

Initialize GLSL-mode

Mode for OpenGL Shading Language

(use-package glsl-mode
  :ensure t
  :config
  (add-to-list 'auto-mode-alist '("\\.fs$" . glsl-mode)))

Programming section

Initialize simpc

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

Initialize company

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

Initialize company-irony

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)

Initialize inf-ruby

(use-package inf-ruby
  :ensure t)

Initialize robe

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

Initialize ruby-electric

(use-package ruby-electric
  :ensure t
  :diminish ruby-electric-mode
  :config
  (add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t))))

Initialize rubocop

(use-package rubocop
  :ensure t
  :init
  (add-hook 'ruby-mode-hook 'rubocop-mode)
  :diminish rubocop-mode)

Initialize pyvenv

(use-package pyvenv
  :ensure t
  :config
  (pyvenv-mode 1))

Custom keybinds

Some keybinds to make life easier

Make <menu> do M-x

(global-set-key (kbd "<menu>") 'smex)

Open URL in browser

(global-set-key (kbd "C-c o") 'browse-url-at-point)

More comfortable resize bindings

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

Xah Lee bracket movement

(global-set-key (kbd "C-9") 'xah-backward-left-bracket)
(global-set-key (kbd "C-0") 'xah-forward-right-bracket)

Comment / uncomment line rebind

(global-set-key (kbd "C-c c") 'comment-line)

Bind compile command to C-c m

(global-set-key (kbd "C-c m") 'compile)

inf-ruby command to C-c s

(global-set-key (kbd "C-c s") 'inf-ruby)

duplicate-line to C-.

(global-set-key (kbd "C-.") 'duplicate-line)
(setq duplicate-line-final-position 1)

copy-from-above-command to C-s-.

(global-set-key (kbd "C-s-.") 'copy-from-above-command)

About

My emacs configuration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published