summaryrefslogtreecommitdiff
path: root/basic.el
blob: 97b53450e1ebd82557d428fbed4c2fc4e5dc8538 (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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
;;; -*- lexical-binding: t; -*-

;;; Important in order to read passwords

(setq epg-pinentry-mode 'loopback)

;;; disable some default modes

(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(blink-cursor-mode -1)

;;; I use one single space to end a sentence.

(set 'sentence-end-double-space nil)

;;; Say y instead of yes

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

;;; Recursive minibuffers is almost indispensable for me.

(set 'enable-recursive-minibuffers t)

;;; Use spaces instead of tabs

(set-default 'indent-tabs-mode nil)

;;; Don't make noise when saving files

(setq save-silently t)

;;; no title on the frame

(setq frame-title-format ""
      icon-title-format "")

;;; major mode of the scratch buffer

(set 'initial-major-mode 'emacs-lisp-mode)

;;; echo quickly

(setq echo-keystrokes 0.002)

;;; Scroll conservatively please

(setq scroll-conservatively 30)

;;; remember my minibuffer

(require 'savehist)

(set 'savehist-file (expand-file-name "savehist" load-file-directory))
(set 'history-length 1024)
(set 'history-delete-duplicates t)
(set 'savehist-save-minibuffer-history t)

(savehist-mode)

;;; a large file threshold

(set 'large-file-warning-threshold (* 1024 1024 1024))

;;; don't use a GUI dialog box as that is distracting to me

(setq use-dialog-box nil)

;;; don't make noise
;;; and when two buffers have the same base name, include more parts to distinguish them

(setq uniquify-buffer-name-style 'forward
      ring-bell-function #'ignore
      visible-bell nil)

;;; mac specific settings

(setq ns-right-alternate-modifier 'none
      ns-pop-up-frames nil
      ns-use-native-fullscreen nil
      ns-use-proxy-icon nil)

;;; where to find the C source code of Emacs.

(setq find-function-C-source-directory "/Users/durand/w.emacs.d/emacs/src/")

;;; frame parameters

(setq initial-frame-alist
      '((width . 118)))
(set-frame-width nil 118)
(add-to-list 'default-frame-alist '(width . 118))
(add-to-list 'default-frame-alist '(font . "Droid Sans Mono for Powerline-20"))
(add-to-list 'default-frame-alist '(ns-transparent-titlebar . t))
(add-to-list 'default-frame-alist '(ns-appearance . dark))
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(setq frame-resize-pixelwise t)
(setq revert-without-query '(".*"))
(set-face-attribute 'variable-pitch nil :family "Avenir" :height 1.0)

;;; disable line numbers, as that is a performace killer for me.

(setq-default display-line-numbers-type nil)
(global-display-line-numbers-mode -1)

;;; display-buffer-alist

(setq display-buffer-alist
      `((,(rx (seq bos "*Help*" eos))
         (display-buffer-in-side-window)
         (side . bottom)
         (slot . 1)
         (window-height . 0.37))
        (,(rx (seq bos "*Messages*" eos))
         (display-buffer-in-side-window)
         (side . bottom)
         (slot . -1)
         (window-height . 0.37))
        (,(rx (seq bos "magit: "))
         (display-buffer-same-window))
        (,(rx (seq bos "*Flymake"))
         (display-buffer-at-bottom)
         (window-height . 0.2))))

;;; Custom kill buffer function

;;;###autoload
(defun durand-kill-current-buffer (&optional arg)
  "Kill the current buffer.

If the optional ARG is non-nil, and if there are more than one
window, then also delete the selected window."
  (interactive "P")
  (cond
   ((window-minibuffer-p (selected-window))
    ;;  this is the same as calling `abort-recursive-edit'.
    (throw 'exit t))
   (t (kill-buffer (current-buffer))))
  (cond
   ((and arg (not (one-window-p t)))
    (delete-window (selected-window)))))

(define-key global-map (vector ?\s-k) #'durand-kill-current-buffer)

;;; Repeating pops

;;;###autoload
(setq set-mark-command-repeat-pop t)

;;; I prefer going to the top first.

;; But I don't really like always going to the top. I am still
;; thinking about solutions.

(setq recenter-positions (list 'middle 'top 'bottom))

;;; Pulse the current line

;;;###autoload
(defface prot-pulse-line
  '((default :extend t)
    (((class color) (min-colors 88) (background light))
     :background "#8eecf4")
    (((class color) (min-colors 88) (background dark))
     :background "#004065")
    (t :inverse-video t))
  "Default face for `durand-pulse-pulse-line'.
I stole from Protesilaos' dotemacs.")

(require 'pulse)

;;;###autoload
(defun durand-pulse-pulse-line (&optional face)
  "Temporarily highlight the current line with optional FACE."
  (interactive)
  (let ((start (cond
                ((= (point) (point-max))
                 (save-excursion
                   (forward-line -1)
                   (point)))
                ((save-excursion
                   (forward-line 0)
                   (point)))))
        (end (save-excursion
               (forward-line 1)
               (point)))
        (pulse-delay .04)
        (face (or face 'prot-pulse-line)))
    (pulse-momentary-highlight-region start end face)))

(define-key global-map (vector 's-escape) #'durand-pulse-pulse-line)

;;;###autoload
(defun durand-pulse-recenter-top ()
  "Recenter to the top and pulse the line."
  (interactive)
  (recenter 0)
  (durand-pulse-pulse-line))

;;; auto-fill for texts

(set 'adaptive-fill-mode t)
(add-hook 'text-mode-hook #'auto-fill-mode)

;;; enable all commands

(set 'disabled-command-function nil)

;;; Comments relateed

(require 'newcomment)

(set 'comment-empty-lines nil)
(set 'comment-fill-column nil)
(set 'comment-multi-line t)
(set 'comment-style 'multi-line)

;;; Windows

(define-key global-map (vector ?\s-o) #'other-window)
(define-key global-map (vector ?\s-&) #'delete-other-windows)
(define-key global-map (vector ?\s-à) #'delete-window)
(define-key global-map (vector ?\s-f) #'find-file)
(define-key global-map (vector ?\s-v) #'durand-focus-completion-or-minibuffer)

;;; Package management

;;;###autoload
(defvar package-dir "/Users/durand/elisp_packages/"
  "The directory containing packages.")

;;;###autoload
(defmacro use-package (package-path package-name &rest configs)
  "Add PACKAGE-PATH to `load-path' and require PACKAGE-NAME.
The remaining CONFIGS are evaluated after the package is loaded."
  (declare (indent 2) (debug defun))
  `(progn
     (add-to-list 'load-path
      (expand-file-name ,package-path ,package-dir))
     (require ,package-name)
     ,@configs))