aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/overlays/kookie/emacs/base/default.el
blob: 906eca673043104c0182f599044b9b9e249507ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;; base.el
;;   Configure emacs-builtins and core key bindings
;;
;; Emacs has a lot of things built-in that are disabled by default.
;; This module enables these settings, to create an editor experience
;; that I find more pleasing.  If you want to get a taste of what it
;; is to use "kookie emacs", start by including this file.
;;
;;
;; This file is part of LIBKOOKIE, a collection of nix expressions.
;; LIBKOOKIE is licensed under the GPL-3.0 (or later) -- see LICENSE

(provide 'base)

;;; Setup consistent line numbering
(setq display-line-numbers-grow-only t)
(setq display-line-numbers-width-start t)
(global-display-line-numbers-mode t)

;;; Use spaces instead of tabs
(setq tab-width 2)
(setq-default indent-tabs-mode nil)
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)

;;; Hide startup splash
;; FIXME: this doesn't currently work...
(setq inhibit-startup-screen t)
(setq inhibit-splash-screen t)
(setq initial-scratch-message nil)

;;; Delete selections
(delete-selection-mode t)

;;; Change the swap/ autosave directory
(let ((backup-dir (concat user-emacs-directory "backups")))
  (make-directory backup-dir t)
  (setq backup-directory-alist (list (cons "." backup-dir)))
  (setq message-auto-save-directory backup-dir))

;;; Display and create symbol pairs
(show-paren-mode t)
(electric-pair-mode t)

;;; Don't soft-wrap lines
(setq-default truncate-lines t)

;;; Hide default UI elements
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

;;; Display column in the mode line
(column-number-mode t)

;;; Enable ido mode
(ido-mode t)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)

;;; Enable ruler-mode in all buffers
(add-hook 'find-file-hook (lambda () (ruler-mode 1)))

;;; Setup mitosis buffer splitting
(setq emacs-anchor default-directory)
(defun mitosis () (interactive) (make-frame))

;;; Distraction free mode and minimap
(require 'sublimity)
(require 'sublimity-attractive)

;;; OpenSCAD mode
(add-to-list 'auto-mode-alist '("\\.scad$" . scad-mode))

;;; Capn Proto mode
(add-to-list 'auto-mode-alist '("\\.capnp$" . protobuf-mode))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function definitions
;;;
;;; A set of functions to compliment emacs' builtin functionality, to
;;; create and navigate buffers.

(defun new-empty-buffer ()
  "Opens a new empty buffer."
  (interactive)
  (let ((buf (generate-new-buffer "untitled")))
    (switch-to-buffer buf)
    (funcall (and initial-major-mode))
    (setq buffer-offer-save t)))

(defun user-buffer-q ()
  "Check if a buffer is a user buffer"
  (interactive)
  (if (string-equal "*" (substring (buffer-name) 0 1))
      nil
    (if (string-equal major-mode "dired-mode")
        nil
      t
      )))

(defun next-user-buffer ()
  "Switch to the next user buffer."
  (interactive)
  (next-buffer)
  (let ((i 0))
    (while (< i 20)
      (if (not (user-buffer-q))
          (progn (next-buffer)
                 (setq i (1+ i)))
        (progn (setq i 100))))))

(defun previous-user-buffer ()
  "Switch to the previous user buffer."
  (interactive)
  (previous-buffer)
  (let ((i 0))
    (while (< i 20)
      (if (not (user-buffer-q))
          (progn (previous-buffer)
                 (setq i (1+ i)))
        (progn (setq i 100))))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Key bindings
;;;
;;; Custom set of key bindings to augment emacs' builtins

(global-set-key (kbd "C-x C-k") 'kill-current-buffer)
(global-set-key (kbd "C-x n") 'new-empty-buffer)
(global-set-key (kbd "C-<next>") 'next-user-buffer)
(global-set-key (kbd "C-<prior>") 'previous-user-buffer)
(global-set-key (kbd "M-s M-s") 'save-buffer)
(global-set-key (kbd "C-t") 'smex)