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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
;;; misc.el --- Hosting miscellaneous configuration -*- lexical-binding: t -*-
;; Author: William Carroll <wpcarro@gmail.com>
;;; Commentary:
;; This is the home of any configuration that couldn't find a better home.
;;; Code:
;; disable custom variable entries from being written to ~/.emacs.d/init.el
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
;; integrate Emacs with X11 clipboard
(setq x-select-enable-primary t)
(setq x-select-enable-clipboard t)
(general-def 'insert
"s-v" #'x-clipboard-yank
"C-S-v" #'x-clipboard-yank)
;; transparently edit compressed files
(auto-compression-mode t)
;; autowrap when over the fill-column
(add-hook 'fundamental-mode-hook 'turn-on-auto-fill)
;; link to Emacs source code
(setq find-function-C-source-directory "~/programming/emacs/src")
;; change emacs prompts from "yes or no" -> "y or n"
(fset 'yes-or-no-p 'y-or-n-p)
;; open photos in Emacs
(auto-image-file-mode 1)
;; disable line-wrapping
(setq-default truncate-lines 1)
;; shell file indentation
(setq sh-basic-offset 2)
(setq sh-indentation 2)
;; disable company mode when editing markdown
;; TODO: move this out of wpc-misc.el and into a later file to call
;; `(disable company-mode)'
(add-hook 'markdown-mode-hook (company-mode -1))
;; create file bookmarks
(set-register ?e '(file . "~/.emacs.d/wpc/packages"))
(set-register ?n '(file . "~/programming/nixify/configuration.nix"))
(set-register ?d '(file . "~/Dropbox/dotfiles"))
(set-register ?s '(file . "~/.slate.js"))
(set-register ?D '(file . "~/Dropbox"))
(set-register ?o '(file . "~/Dropbox/org/")) ;; TODO: change this to `(getenv "ORG_DIRECTORY")'
(set-register ?v '(file . "~/.config/nvim/init.vim"))
(set-register ?e '(file . "~/.emacs.d/init.el"))
(set-register ?z '(file . "~/.zshrc"))
(set-register ?a '(file . "~/aliases.zsh"))
(set-register ?f '(file . "~/functions.zsh"))
(set-register ?l '(file . "~/variables.zsh"))
(set-register ?x '(file . "~/.Xresources"))
(set-register ?i '(file . "~/.config/i3/config"))
(set-register ?m '(file . "~/.tmux.conf"))
(set-register ?p `(file . ,wpc/current-project))
;; persist history etc b/w Emacs sessions
(setq desktop-save 'if-exists)
(desktop-save-mode 1)
(setq desktop-globals-to-save
(append '((extended-command-history . 30)
(file-name-history . 100)
(grep-history . 30)
(compile-history . 30)
(minibuffer-history . 50)
(query-replace-history . 60)
(read-expression-history . 60)
(regexp-history . 60)
(regexp-search-ring . 20)
(search-ring . 20)
(shell-command-history . 50)
tags-file-name
register-alist)))
;; config Emacs to use $PATH values
(use-package exec-path-from-shell
:if (memq window-system '(mac ns))
:config
(exec-path-from-shell-initialize))
;; Emacs autosave, backup, interlocking files
(setq auto-save-default nil
make-backup-files nil
create-lockfiles nil)
;; ensure code wraps at 80 characters by default
(setq-default fill-column wpc/fill-column)
(put 'narrow-to-region 'disabled nil)
;; trim whitespace on save
(add-hook 'before-save-hook #'delete-trailing-whitespace)
;; use tabs instead of spaces
(setq-default indent-tabs-mode nil)
;; automatically follow symlinks
(setq vc-follow-symlinks t)
;; fullscreen settings
(setq ns-use-native-fullscreen nil)
;; auto-close parens, brackets, quotes
(electric-pair-mode 1)
(use-package oauth2
:init
;; necessary to remove warnings: https://emacs.stackexchange.com/questions/37036/where-are-these-variables-defined-bytecomp-warnings
(defvar url-http-extra-headers ())
(defvar oauth--token-data ())
(defvar url-callback-function ())
(defvar url-callback-arguments ()))
; (use-package smex
; :config
; (general-define-key "M-x" #'smex)
; (general-add-hook 'ido-setup-hook #'wpc/bind-ido-keys)
; (smex-initialize))
(use-package flx-ido
:after (smex)
:config
(flx-ido-mode 1)
(setq ido-enable-flex-matching t
ido-use-faces nil))
(use-package swiper
:config
(general-define-key
"C-s" #'swiper
"C-r" #'swiper))
(use-package yasnippet
:config
(yas-global-mode 1))
(use-package ace-window
:config
(general-define-key "C-x o" #'ace-window)
(setq aw-keys '(?a ?s ?d ?f ?j ?k ?k ?\;)))
(use-package projectile
:config
(projectile-mode t))
(use-package counsel
:config
(defun wpc/counsel-git-grep ()
(interactive)
(let ((maybe-symbol (wpc/string-symbol-at-point)))
(if (string= maybe-symbol "nil")
(counsel-git-grep)
(counsel-git-grep nil maybe-symbol)))))
;; search Google, Stackoverflow from within Emacs
(use-package engine-mode
:config
(defengine google
"http://www.google.com/search?ie=utf-8&oe=utf-8&q=%s"
:keybinding "g")
(defengine stack-overflow
"https://stackoverflow.com/search?q=%s"
:keybinding "s"))
;; Microsoft's Language Server Protocol (LSP)
(use-package lsp-ui
:config
(add-hook 'lsp-mode-hook #'lsp-ui-mode))
(use-package company-lsp
:config
(push 'company-lsp company-backends))
(defun wpc/frame-name ()
"Return the name of the current frame."
(frame-parameter nil 'name))
;; Having difficulty starting the server using systemd or calling
;; `emacs --daemon' in ~/.profile, ~/.xsessionrc, and similar files.
;; systemd has issues syncing the socket-name, so it becomes messy. I also
;; experienced strange initialization where things like wpc-org and other
;; modules wouldn't get loaded.
;;
;; Even if I resolved the socket-name resolution issue, I couldn't find an
;; elegant way to reuse GUI frames. GUIs for me have the advantage of supporting
;; True Color, support additional keys for KBDs (i.e. super), and aren't limited
;; by the terminal for rendering certain things.
;;
;; For these reasons, it seems preferable to start the server from here. I'm
;; considering starting emacs in my ~/.xsessionrc so that the server will be
;; running after X initializes.
(server-start)
(provide 'wpc-misc)
;;; wpc-misc.el ends here
|