summaryrefslogtreecommitdiffstats
path: root/init.el
blob: 6325bb40dd7df43a3df37ba326ae1a57c6e73a44 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;; Emacs initialization file

;; Remember the initialization directory
(setq ravi/init-dir (file-name-directory (or load-file-name (buffer-file-name))))
(defun ravi/emacs-file (filename)
  (expand-file-name filename ravi/init-dir)
  )

;; Initialize some customizations early on to avoid flicker
(when window-system
  (tooltip-mode -1)
  (tool-bar-mode -1))
;; Open in full-screen of possible
(when (fboundp 'toggle-frame-maximized)
  (setq frame-resize-pixelwise t)
  (toggle-frame-maximized))
(menu-bar-mode -1)
(setq warning-suppress-types nil)
(set-face-background 'default "black")
(set-face-foreground 'default "white")
(add-to-list 'default-frame-alist '(background-mode . dark))
(require 'cl)
(defun font-candidate (&rest fonts)
  "Return existing font which first match."
  (find-if (lambda (f) (find-font (font-spec :name f))) fonts))
(let ((fontval (font-candidate '"Inconsolata" "Source Code Pro" "Anonymous Pro")))
  (when fontval (set-face-attribute 'default nil :font fontval)))
(when (find-font (font-spec :name "Symbola"))
  (set-fontset-font "fontset-default" nil
                    (font-spec :size 20 :name "Symbola")))
(setq custom-file (concat ravi/init-dir "custom.el"))

;; Initialize package handling: currently using only the official repository and MELPA
(setq package-archives
      '(("gnu"         . "http://elpa.gnu.org/packages/")
        ;("original"    . "http://tromey.com/elpa/")
        ("org"         . "http://orgmode.org/elpa/")
        ;("marmalade"   . "http://marmalade-repo.org/packages/")
        ("melpa"       . "http://melpa.org/packages/")))
(add-to-list 'load-path (ravi/emacs-file "lisp/"))
(add-to-list 'load-path (ravi/emacs-file "site-lisp/"))
(setq autoload-file (concat ravi/init-dir "loaddefs.el"))
(setq package-user-dir (concat ravi/init-dir "elpa"))

(package-initialize)

(defvar ravi/default-install-packages
  (list 'yasnippet 'use-package 'bind-key 'diminish)
  "Libraries that should be installed by default.")

(unless package-archive-contents
  (package-refresh-contents))
(dolist (package ravi/default-install-packages)
  (unless (package-installed-p package)
    (package-install package)))

;; Settings from M-x customize
(load custom-file 'noerror)

(require 'bind-key)
(require 'use-package)
(require 'diminish)

;; Show full frame windows for certain commands
(use-package fullframe
  :ensure t
  )

;; ---------------------------------------------------------------------
;; Stolen from purcell/emacs.d/init-utils.el
(defmacro after-load (feature &rest body)
  "After FEATURE is loaded, evaluate BODY."
  (declare (indent defun))
  `(eval-after-load ,feature
     '(progn ,@body)))

(defun sanityinc/string-all-matches (regex str &optional group)
  "Find all matches for `REGEX' within `STR', returning the full match string or group `GROUP'."
  (let ((result nil)
        (pos 0)
        (group (or group 0)))
    (while (string-match regex str pos)
      (push (match-string group str) result)
      (setq pos (match-end group)))
    result))
;; ---------------------------------------------------------------------

(defvar ravi/use-helm-instead-of-ido t
  "Prefer helm to ido")

(when (file-exists-p (ravi/emacs-file "local.el"))
  (load-file (ravi/emacs-file "local.el"))
  )

;; Auto indent mode must be enabled before autopair and yasnippet
(use-package auto-indent-mode
  :config (auto-indent-global-mode)
  :diminish auto-indent-mode
  :disabled t ;; this mode tries to do way too much
  :ensure t
  )

(use-package s :ensure t)
(require 's)
(require 'ravi-ergodox-mode)
(if (s-contains? "Ergodox" (shell-command-to-string "xinput"))
    (progn
      (ravi-ergodox-mode)
      (diminish 'ravi-ergodox-mode))
  (progn
    ;; Temporary key-bindings
    (if (and (boundp 'ravi/use-helm-instead-of-ido) ravi/use-helm-instead-of-ido)
        (progn
          (bind-key "<f9>" 'helm-find-files)
          (bind-key "<f8>" 'helm-mini))
      (progn
        (bind-key "<f9>" 'ido-find-file)
        (bind-key "<f8>" 'ido-switch-buffer)))
    (bind-key "<f12>" 'undo-tree-undo)))

(use-package free-keys
  :ensure t
  :commands free-keys)

(defun ravi/add-variables-from-dir-locals (varname hack-varname &optional make-it-local)
  "Add variable from dir-locals.el to an existing variable as a buffer-local variable"
  (let ((basic-var (symbol-value varname)))
    (when (and (boundp hack-varname)
               (listp (symbol-value hack-varname)))
      (when make-it-local
        (make-local-variable varname))
      (set varname (append basic-var (symbol-value hack-varname))))))

(require 'ravi-init-ido)
(require 'ravi-init-helm)
(require 'ravi-init-marks)
(require 'ravi-init-appearance)
(require 'ravi-init-files)
(require 'ravi-init-vc)
(require 'ravi-init-function)
(require 'ravi-init-insertion)
(require 'ravi-init-navigation)
(require 'ravi-init-cpp)
(require 'ravi-init-python)
(require 'ravi-init-layouts)
(require 'ravi-init-org)
(require 'ravi-init-tex)
(require 'ravi-init-repl)
(require 'ravi-init-dired)
(require 'ravi-init-mu)
(require 'ravi-init-web)