nixos-config/dotfiles/emacs/config.org

6.7 KiB

EMACS Configuration.

Configure use-package

Always compile the packages, and use the newest version available.

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

Workaround for a bug in EMACS 26. Where there is an issue installing some packages.

  (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")

Load Scripts

Load the typing-speed script.

  (load-file (concat user-emacs-directory "scripts/typing_speed.el"))

UI Prefrences

Tweak EMACS' window

Disable menu, scrollbar and minibuffer scrollbar.

  (tool-bar-mode -1)
  (menu-bar-mode -1)
  (scroll-bar-mode -1)
  (set-window-scroll-bars (minibuffer-window) nil nil)

Bind frame title to the name of the current project.

(setq frame-title-format '((:eval (projectile-project-name))))

Load theme

Use 'monokai' theme.

  (defun apply-theme ()
	"Make frames just slightly transparent."
	(interactive)
  (load-theme 'monokai t))

  (use-package monokai-theme
	:config
	(apply-theme))
  (setq ;; foreground and background
		monokai-foreground     "#ABB2BF"
		monokai-background     "#282C34"
		;; highlights and comments
		monokai-comments       "#F8F8F0"
		monokai-emphasis       "#282C34"
		monokai-highlight      "#FFB269"
		monokai-highlight-alt  "#1B1D1E"
		monokai-highlight-line "#1B1D1E"
		monokai-line-number    "#F8F8F0"
		;; colours
		monokai-blue           "#61AFEF"
		monokai-cyan           "#56B6C2"
		monokai-green          "#98C379"
		monokai-gray           "#3E4451"
		monokai-violet         "#C678DD"
		monokai-red            "#E06C75"
		monokai-orange         "#D19A66"
		monokai-yellow         "#E5C07B")
  (setq monokai-height-minus-1 0.8
		monokai-height-plus-1 1.1
		monokai-height-plus-2 1.15
		monokai-height-plus-3 1.2
		monokai-height-plus-4 1.3)

Configure packages that modify the look

powerline

Install and use EMACS' powerline

(use-package powerline)
(powerline-default-theme)

Environment specific configuration

ORG-mode Environment

Replace ORG-mode ellipsis with a downward arrow.

(setq org-ellipsis "↲")

Basic Configuration

Increase the garbage collector threshold, to speed up some operations.

  (setq gc-cons-threshold 20000000)

Treat CamelCaseSubWords as seperate words. Note: Check if this suits me.

  (add-hook 'prog-mode-hook 'subword-mode)

If a file starts with #!, make it executable.

  (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)

If saving a file in a directory doesn't exist, offer to create the parent directories recursively.

  (add-hook 'before-save-hook
			(lambda ()
			  (when buffer-file-name
				(let ((dir (file-name-directory buffer-file-name)))
				  (when (and (not (file-exists-p dir)) y-or-n-p (format "Directory %s does not exist, Create it?" dir))
					(make-directory dir t ))))))

Require having a new line.

  (setq require-final-newline t)

Make file sizes human-readable to dired buffers.

  (setq-default dired-listing-switches "-alh")

Refresh buffer when the file is changed, stoping buffers and file getting out of sync.

(global-auto-revert-mode t)

When pressing the middle mouse button, paste where the curser is rather than where the mouse is.

(setq mouse-yank-at-point 1)

Better increase and decrease text scale.

(global-set-key  (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)

Enable visual parantheses matching.

(show-paren-mode 1)

Enable Line numberings.

(global-display-line-numbers-mode)

Store backups and temperory files in temporary-file-directory. /tmp on Unix. Warning: /tmp on most Unix-like systems is VOLATILE, IN-MEMORY storage.

(setq backup-directory-alist `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms `((".*", temporary-file-directory t)))

Packages Configuration

ag

Set up ag on startup.

  (use-package ag)

company

Enable company-mode everywhere.

  (use-package company)
  (add-hook 'after-init-hook 'global-company-mode)

Use M-/ for completion.

  (global-set-key (kbd "M-/") 'company-complete-common)

flycheck

Install flycheck.

  (use-package flycheck)

magit

Use magit for git repos managment.

  (use-package magit
	:bind ("C-x g" . magit-status))

projectile

Use projectile for useful funcationality for project management.

  (use-package projectile)

undo-tree

Use undo-tree.

  (use-package undo-tree)

Environment Specific Packages.

Lisp Environment

Use paredit.

  (use-package paredit)

Use rainbow-delimiters.

  (use-package rainbow-delimiters)

Programming Environments Configuration

Use 4-spaced characters for tabs by default.

  (setq-default tab-width 4)

Use subword mode.

  (use-package subword
	:config (global-subword-mode 1))

C/C++ Environment

Set the tab width when using C/C++ mode.

  (setq-default c-basic-offset 4)

Lisp Environment

Uses lisp packages when lisp languages are enabled.

  (setq lispy-mode-hooks
		'(emacs-lisp-hook lisp-mode-hook))

  (dolist (hook lispy-mode-hooks)
	(add-hook hook (lambda()
					 (setq show-paren-style 'expression)
  (paredit-mode)
  (rainbow-delimeters-mode))))

Set tab with

ORG-mode Environment

This might not be a programming environment, but making a seperate section is an overkill.

Enable indentation in org source blocks.

  (setq org-src-tab-acts-natively t)

sh Environment

Indent with 4 spaces.

  (add-hook 'sh-mode-hook
			(lambda ()
			  (setq sh-basic-offset 4
					sh-indentation 4)))

Misc Configuration

Install speed-type for typing practice.

  (use-package speed-type)