You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

12 KiB

LICENSE NOTICE AND CONFIGURATION COMMENTARY

;; Copyright (C) 2018-2020 Robin Wils

;; Author: Robin Wils
;; Maintainer: Robin Wils
;; Created: 14 Jul, 2018
;; Version: 0.1.3

;; This config is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.

;; This config is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this config. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;; Quick Start / installation:
;; 1. Place emacs-init.org into your .emacs.d directory.
;; 2. Replace your .emacs file with my .emacs one.
;; (It is recommended to backup your .emacs file before you do this)

;;; Code:

INITIALIZE PACKAGES

(package-initialize)

REPOSITORIES

The official repository misses a lot of packages. MELPA is a more popular repository which contains more packages.

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

FASTER STARTUP

Emacs should load faster if with this configured. This is only recommended if your machine has enough RAM. It should work on the most modern machines.

(setq gc-cons-threshold 64000000)
(add-hook 'after-init-hook
          #'(lambda () (setq gc-cons-threshold 800000)))

USE-PACKAGE

Install use-package if it is not installed.

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

Require use-package.

(eval-when-compile (require 'use-package))

VARIABLES

(setq
 ;; Personal information
 user-full-name "Robin Wils"
 user-mail-address "mrwils@tutanota.com"

 ;; No startup message.
 inhibit-startup-message t

 ;; No startup-screen
 inhibit-startup-screen t

 ;; Empty scratch buffer
 initial-scratch-message nil

 ;; End sentences with one space
 sentence-end-double-space nil

 ;; No backups
 make-backup-files nil

 ;; Disable dialogs
 use-dialog-box nil

 ;; Disable emacs beep
 visible-bell 1

 ;; stop emacs from creating .#lock file links
 create-lockfiles nil

 ;; Indentation variables
 custom-tab-width 2
 big-custom-tab-width 4)


(setq-default
 ;; Mark column 100 in the header (Clean code matters)
 header-line-format (list " " (make-string 99 ?-) "|")

 ;; Force the messages to 0
 message-log-max nil

 ;; Set the tab-width
 tab-width custom-tab-width)

 ;; Don't use tabs
 ;; use spaces instead
 ;; indent-tabs-mode nil)

HIDE GUI ELEMENTS

;; No cursor blink
(blink-cursor-mode -1)

;; Hide the toolbar
(tool-bar-mode -1)

;; Hide the menu bar (recommended)
;; (menu-bar-mode -1)

BETTER DEFAULTS

Better dired (change default config)

(add-hook 'dired-mode-hook
          (lambda ()
            (dired-hide-details-mode)
            (dired-sort-toggle-or-edit)))
;; Don't ask for recursive copies, just do it.
(setq dired-recursive-copies 'always)
;; Same thing for recursive deleting.
(setq dired-recursive-deletes 'always)
;; Make it possible to copy from one buffer to another.
(setq dired-dwim-target t)
;; Don't let Enter and ^ create a new buffer

;; Did not work
;;(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file)
;;(define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file "..")))

Better keys - Xah Fly Keys

I use Xah Fly Keys Dvorak. QWERTY and other layout support for this mode exists.

(use-package xah-fly-keys
  :ensure t
  :config
  (setq xah-fly-use-control-key nil)
  (setq xah-fly-use-meta-key nil)
  (define-key key-translation-map (kbd "ESC") (kbd "C-g"))
  (xah-fly-keys-set-layout "dvorak")
  (xah-fly-keys 1)

  (defun xah-replace-invisible-char ()
    "Query replace some invisible Unicode chars.
  The chars to be searched are:
   ZERO WIDTH NO-BREAK SPACE (65279, #xfeff)
   ZERO WIDTH SPACE (codepoint 8203, #x200b)
   RIGHT-TO-LEFT MARK (8207, #x200f)
   RIGHT-TO-LEFT OVERRIDE (8238, #x202e)
   LEFT-TO-RIGHT MARK ‎(8206, #x200e)
   OBJECT REPLACEMENT CHARACTER (65532, #xfffc)

  Search begins at cursor position. (respects `narrow-to-region')

  URL `http://ergoemacs.org/emacs/elisp_unicode_replace_invisible_chars.html'
  Version 2018-09-07"
    (interactive)
    (query-replace-regexp "\ufeff\\|\u200b\\|\u200f\\|\u202e\\|\u200e\\|\ufffc" "")))

Better modes

Xah Lee has some great modes which are better as the defaults.

(use-package xah-css-mode
  :ensure t
  :config
  :hook
  (css-mode . xah-css-mode)
  (css-mode . untabify-whole-buffer))

Better autosave

See http://ergoemacs.org/emacs/emacs_auto_save.html for more info.

(defun xah-save-all-unsaved ()
  "Save all unsaved files. no ask.
Version 2019-11-05"
  (interactive)
  (save-some-buffers t ))

;; when switching out of emacs, all unsaved files will be saved
(add-hook 'focus-out-hook 'xah-save-all-unsaved)

;; stop creating those #auto-save# files
(setq auto-save-default nil)

Use async processes when it is possible

(use-package async :ensure t :init (dired-async-mode 1))

Show line numbers

(global-linum-mode 1)
;; Start line numbers at 0
(require 'linum)
(setq linum-format
      (lambda (line)
        (propertize (number-to-string (1- line)) 'face 'linum)))

;; Stop line numbers from slowing down org-mode
(with-eval-after-load "linum"
  ;; set `linum-delay' so that linum uses `linum-schedule' to update linums.
  (setq linum-delay t)

  ;; create a new var to keep track of the current update timer.
  (defvar-local my-linum-current-timer nil)

  ;; rewrite linum-schedule so it waits for 1 second of idle time
  ;; before updating, and so it only keeps one active idle timer going
  (defun linum-schedule ()
    (when (timerp my-linum-current-timer)
      (cancel-timer my-linum-current-timer))
    (setq my-linum-current-timer
          (run-with-idle-timer 1 nil #'linum-update-current))))

Open files as root if necessary

This didn't work correctly with Xah Fly Keys.

  ;; (defadvice find-file (after find-file-sudo activate)
  ;;   "Find file as root if necessary."
  ;;   (unless (and buffer-file-name
  ;;                (file-writable-p buffer-file-name))
  ;;     (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))

Better performance for big files

(use-package vlf :ensure t)

OWN HOOK FUNCTIONS

Untabify whole buffer

Removes all the tabs in a buffer.

(defun untabify-whole-buffer()
  "Untabifies a whole buffer."
  (interactive)
  (untabify (point-min) (point-max)))

LOAD OTHER SECRET FILES

This file contains some (setq) variables. There is probably a better and more secure way to do this.

(defun load-if-exists (file)
  "load the elisp file only if it exists and if it is readable"
  (if (file-readable-p file)
      (load-file file)))
;; For example: (load-if-exists "~/.secrets.el")

SETUP SOME DEFAULTS

Kill the Messages buffer on startup

(if (get-buffer "*Messages*")
    (kill-buffer "*Messages*"))

Disable Completions buffer

(add-hook 'minibuffer-exit-hook
          '(lambda ()
             (let ((buffer "*Completions*"))
               (and (get-buffer buffer)
                    (kill-buffer buffer)))))

Unset the default suspend-frame shortcut

The default C-z command minimizes GNU emacs. I don't like that.

(global-unset-key "\C-z")

Replace typing "yes" or "no" with typing "y" or "n"

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

Make it possible to hide minor modes

(use-package diminish :ensure t)

THEME

I like the darktooth theme and the Hack font. The Hack font needs to be installed on your system though.

I want to automate the font installation in the future.

(use-package darktooth-theme
  :ensure t
  :config (load-theme 'darktooth t))

  ;; (setq default-frame-alist
  ;;   '((background-color . "#282828")
  ;; (foreground-color . "#EEEEEE")))

  ;; (set-face-foreground 'mode-line "#EEEEEE")
  ;; (set-face-background 'mode-line "#111111")
  ;; (set-face-background 'mode-line-inactive "#444444")

  ;; Emacs font
  (add-to-list 'default-frame-alist
               '(font . "Hack-8"))

PROGRAMMING

Lisp

(use-package slime
  :ensure t
  :commands (slime slime-lisp-mode-hook)
  :config
  (setq inferior-lisp-program "sbcl" slime-contribs '(slime-fancy)))

Godot

(use-package gdscript-mode
   :ensure t
   :config
   (standard-display-ascii ?\t ">|  ")
   ;; Save all buffers and format them with gdformat anytime Godot executable is run.
   (setq gdscript-gdformat-save-and-format t))
;;   :config
;;   (setq gdscript-tabs-mode nil))

SPELLING AND GRAMMAR

Flycheck and flyspell

(use-package flycheck
  :ensure t
  :defer 2
  :diminish flycheck-mode " ✓"
  :commands global-flycheck-mode
  :config
  (progn
    (global-flycheck-mode 1)
    (setq-default flycheck-disabled-checkers
                  '(html-tidy
                    emacs-lisp-checkdoc))))

(use-package flyspell
  :defer 2
  :init
  :config
  (progn
    (setq ispell-program-name "aspell")
    (add-hook 'text-mode-hook 'flyspell-mode)))

Trailing whitespace

Remove trailing whitespace

(add-hook 'before-save-hook 'delete-trailing-whitespace)

ORG MODE

Don't use org builtin package, use repository one instead

(assq-delete-all 'org package--builtins)

ox-hugo

Hugo support in org-mode

(use-package ox-hugo :ensure t :after ox)

org-mode better html export support

(use-package htmlize :ensure t)

MORE PACKAGES

IRC - ERC

Use the erc-tls command to launch ERC erc-tls uses SSL, erc doesn't.

TODO: add ZNC.

#+BEGIN_SRC emacs-lisp (defalias 'erc 'erc-tls) (use-package erc :defer t :config ;; load my sensitve nickserv passwords (load-if-exists "~/.erc-secrets.el")

(setq ;; server to use if none is provided erc-server "irc.serverchan.club" ;; server which you can choose from in the menu erc-server-history-list '("irc.serverchan.club" "irc.lainchan.org" "irc.freenode.net") ;; port to use if none is provided erc-port 6697 ;; nickname to use if none is provided erc-nick "rmw" ;; full-name to use if none is provided ;; (my name is stored in the user-full-name variable) erc-user-full-name user-full-name ;; nickserv-passwords. ;; (I do this in my secret file) ;; (setq erc-nickserv-passwords ;; '((freenode (("nick-one" . "password") ;; ("nick-two" . "password"))) ;; (lainchan (("nickname" . "password"))))) ;; away nickname to use erc-away-nickname "rmw-away" ;; erc channels to autojoin erc-autojoin-channels-alist '(("serverchan.club" "#scoots") ("lainchan.org" "#lainchan") ("freenode.net" "#librelounge"))))

;; SSL support (require 'tls) (setq tls-program '("openssl s_client -connect %h:%p -no_ssl2 -ign_eof -CAfile home/ootput.private/certs/CAs.pem -cert home/ootput.private/certs/nick.pem" "gnutls-cli –priority secure256 –x509cafile home/ootput.private/certs/CAs.pem –x509certfile home/ootput.private/certs/nick.pem -p %p %h" "gnutls-cli –priority secure256 -p %p %h"))

#+END_SR