-
Notifications
You must be signed in to change notification settings - Fork 59
/
jmax.el
410 lines (309 loc) · 13.5 KB
/
jmax.el
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
;;; jmax.el --- Customization for jmax -*- lexical-binding: t; -*-
;; Copyright (C) 2015 John Kitchin
;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
;; URL: https://github.com/jkitchin/jmax
;; Version: 0.1
;; Keywords: org-mode
;; Package-Requires: ()
;; This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
;;* Packages
(defcustom jmax-user-theme 'leuven
"User defined theme to load")
(require 'cl) ;; common-lisp functions
(require 'saveplace) ;; When you visit a file, point goes to the
;; last place where it was when you
;; previously visited the same file.
(require 'ffap) ;; find-file-at-point
(require 'uniquify) ;; overrides Emacs' default mechanism for
;; making buffer names unique (using suffixes
;; like <2>, <3> etc.) with a more sensible
;; behaviour which use parts of the file
;; names to make the buffer names
;; distinguishable.
(require 'ansi-color) ;; translates ANSI SGR (Select Graphic
;; Rendition) escape sequences like "Esc [ 30
;; m" into EmacsOverlays, TextProperties, or
;; XEmacsExtents with face colours, bold,
;; etc.
;; diminish keeps the modeline tidy
(require 'diminish)
;; sensible undo
(require 'undo-tree)
(global-undo-tree-mode)
(diminish 'undo-tree-mode)
;; we load the custom file if it exists.
(setq custom-file (expand-file-name "user/custom.el" starter-kit-dir))
(when (file-exists-p custom-file)
(load custom-file))
;; bookmarks
(require 'bookmark)
(setq bookmark-default-file (expand-file-name "user/bookmarks" starter-kit-dir)
bookmark-save-flag 1)
;; saner regex syntax
(require 're-builder)
(setq reb-re-syntax 'string)
;; disable auto-fill
(auto-fill-mode -1)
(require 'words)
;; hide details in dired
(require 'dired-details+)
(setq dired-details-hidden-string "")
(require 'jmax-mode)
(jmax-mode 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; add this directory to the path for loading lisp files
(add-to-list 'load-path starter-kit-dir)
(setq abbrev-file-name (expand-file-name "user/abbrev_defs" starter-kit-dir))
(setq save-abbrevs t)
(setq-default abbrev-mode t)
;; kill mail buffers when exiting
(setq message-kill-buffer-on-exit t)
;; set the frame title to show file names
(setq frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
(setq inhibit-startup-screen t) ;; stop showing startup screen
(tool-bar-mode 0) ; remove the icons
(menu-bar-mode 1) ; keep the menus
(global-visual-line-mode 1) ;; how long lines are handled. This
;; appears to wrap long lines visually,
;; but not add line-returns
(global-font-lock-mode t) ;; turn on font-lock mode everywhere
;; I do not like autofill mode.
(auto-fill-mode -1)
(show-paren-mode 1) ;; highlight parentheses
(setq show-paren-style 'mixed) ;; alternative is 'expression, 'parenthesis or 'mixed
(line-number-mode 1) ;; turn linumbers on in mode-line
(setq backup-inhibited t) ;; disable backup file creation
(fset 'yes-or-no-p 'y-or-n-p) ; answer with y/n instead of yes/no
;; Disable all version control. makes startup and opening files much faster
;; except git and svn which I actually use
(setq vc-handled-backends '(Git SVN))
;; http://emacsredux.com/blog/2013/04/05/recently-visited-files
(require 'recentf)
(setq recentf-max-saved-items 200
recentf-max-menu-items 15)
(recentf-mode +1)
(setq save-place-file (expand-file-name "user/saved-places" starter-kit-dir))
(global-set-key (kbd "<f7>") 'helm-recentf)
;; automatically show completions for execute-extended-command
(icomplete-mode 1)
;;* ido completion
(require 'ido)
(require 'ido-ubiquitous)
(require 'flx-ido)
(setq ido-enable-prefix nil
ido-enable-flex-matching t
ido-create-new-buffer 'always
ido-use-filename-at-point 'guess
ido-max-prospects 10
ido-save-directory-list-file (expand-file-name "user/ido.hist" starter-kit-dir)
ido-default-file-method 'selected-window
ido-auto-merge-work-directories-length -1)
(ido-mode +1)
(ido-ubiquitous-mode +1)
;;** smarter fuzzy matching for ido
(flx-ido-mode +1)
;; disable ido faces to see flx highlights
(setq ido-use-faces nil)
;; http://sachachua.com/blog/2014/03/emacs-basics-call-commands-name-m-x-tips-better-completion-using-ido-helm/
(require 'ido-hacks nil t)
(if (commandp 'ido-vertical-mode)
(progn
(ido-vertical-mode 1)
(setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right)))
;;* smex, remember recently and most frequently used commands
;; (require 'smex)
;; (setq smex-save-file (expand-file-name "user/.smex-items" starter-kit-dir))
;; (smex-initialize)
;; (global-set-key (kbd "M-x") 'smex)
;; (global-set-key (kbd "M-X") 'smex-major-mode-commands)
;;* Helm
;; http://tuhdo.github.io/helm-intro.html
(require 'helm)
(setq helm-command-prefix-key "C-c h")
(require 'helm-config)
(require 'helm-eshell)
(require 'helm-files)
(require 'helm-grep)
;; (define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
; rebind tab to do persistent action
;; (define-key helm-map (kbd "C-i") 'helm-execute-persistent-action)
; make TAB works in terminal
(define-key helm-map (kbd "C-z") 'helm-select-action) ; list actions using C-z
(define-key helm-grep-mode-map (kbd "<return>") 'helm-grep-mode-jump-other-window)
(define-key helm-grep-mode-map (kbd "n") 'helm-grep-mode-jump-other-window-forward)
(define-key helm-grep-mode-map (kbd "p") 'helm-grep-mode-jump-other-window-backward)
(define-key helm-map (kbd "C-x 2") 'helm-select-2nd-action)
(define-key helm-map (kbd "C-x 3") 'helm-select-3rd-action)
(define-key helm-map (kbd "C-x 4") 'helm-select-4rd-action)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x b") 'helm-mini)
(global-set-key (kbd "C-x r l") 'helm-bookmarks)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-c h s") 'helm-semantic-or-imenu)
(global-set-key (kbd "C-c h m") 'helm-man-woman)
(global-set-key (kbd "C-c h f") 'helm-find)
(global-set-key (kbd "C-c h l") 'helm-locate)
(global-set-key (kbd "C-c h o") 'helm-occur)
(global-set-key (kbd "C-c h r") 'helm-resume)
(global-set-key (kbd "C-c m") 'helm-all-mark-rings)
(define-key 'help-command (kbd "C-f") 'helm-apropos)
(define-key 'help-command (kbd "r") 'helm-info-emacs)
;; use helm to list eshell history
(add-hook 'eshell-mode-hook
#'(lambda ()
(define-key eshell-mode-map (kbd "M-l") 'helm-eshell-history)))
;;; Save current position to mark ring
(add-hook 'helm-goto-line-before-hook 'helm-save-current-pos-to-mark-ring)
;; * helm extensions
;; add some useful functions to helm-find-files
(defun helm-attach-to-email (candidate)
(mml-attach-file candidate))
(defun helm-find-files-insert-path (target)
"Insert relative path to TARGET."
(insert (file-relative-name target)))
(defun helm-find-files-insert-absolute-path (target)
"Insert absolute path to TARGET."
(insert (expand-file-name target)))
(add-hook 'helm-find-files-before-init-hook
(lambda ()
(helm-add-action-to-source
"Insert path"
'helm-find-files-insert-path
helm-source-find-files)
(helm-add-action-to-source
"Insert absolute path"
'helm-find-files-insert-absolute-path
helm-source-find-files)
(helm-add-action-to-source
"Attach file to email"
'helm-attach-to-email helm-source-find-files)
(helm-add-action-to-source
"Make directory"
(lambda (target)
(make-directory target))
helm-source-find-files)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;* other loads
(load-file (expand-file-name "email.el" starter-kit-dir))
;; add matlab
(add-to-list 'load-path (expand-file-name "matlab" starter-kit-dir))
(load-library "matlab-load")
;; Load up org mode
(load-file (expand-file-name "jmax-org.el" starter-kit-dir))
;; load course module
(add-to-list 'load-path (expand-file-name "techela" starter-kit-dir))
(require 'techela)
;; We load all .el files in the user directory. No order is guaranteed.
(add-to-list 'load-path user-dir)
(when (and (file-exists-p user-dir)
jmax-load-user-dir)
(dolist (file (directory-files user-dir 't "^[^#].*el$"))
(message "Loading %s" file)
(load file)))
(require 'jmax-utils)
(require 'python-setup)
(require 'jeldoc)
;;* Spell-checking
(when (setq-default ispell-program-name
(or (executable-find "hunspell")
(executable-find "ispell")
(executable-find "aspell")))
(setq ispell-personal-dictionary (concat starter-kit-dir "user/.ispell"))
(setq ispell-silently-savep t)
;; Spell-checking on the fly
(flyspell-mode +1)
(add-hook 'flyspell-incorrect-hook
(lambda (beg end sym)
(message "%s misspelled. Type %s to fix it."
(buffer-substring beg end)
(substitute-command-keys "\\[flyspell-check-previous-highlighted-word]"))
;; return nil so word is still highlighted.
nil))
(eval-after-load "flyspell"
'(progn
(define-key flyspell-mouse-map [s-mouse-1] #'flyspell-correct-word)))
;; enabling flyspell in special edit source blocks.
(defadvice org-edit-src-code (around set-buffer-file-name activate compile)
(let ((file-name (buffer-file-name))) ;; (1)
ad-do-it ;; (2)
(setq buffer-file-name file-name))) ;; (3)
;; flyspell mode for spell checking everywhere
(add-hook 'org-mode-hook 'turn-on-flyspell 'append)
;; configure ispell to ignore some things
(defun endless/org-ispell ()
"Configure `ispell-skip-region-alist' for `org-mode'."
(make-local-variable 'ispell-skip-region-alist)
(add-to-list 'ispell-skip-region-alist '(org-property-drawer-re))
(add-to-list 'ispell-skip-region-alist '("~" "~"))
(add-to-list 'ispell-skip-region-alist '("=" "="))
;; this next line approximately ignores org-ref-links
(add-to-list 'ispell-skip-region-alist '("cite:" . "[[:space:]]"))
(add-to-list 'ispell-skip-region-alist '("label:" . "[[:space:]]"))
(add-to-list 'ispell-skip-region-alist '("ref:" . "[[:space:]]"))
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC")))
(add-hook 'org-mode-hook #'endless/org-ispell)
(defun flyspell-check-next-highlighted-word ()
"Move to next error and check it."
(interactive)
(flyspell-goto-next-error)
(ispell-word))
(defhydra spell (:color red)
"spell"
("s" flyspell-check-previous-highlighted-word "previous")
("n" flyspell-check-next-highlighted-word "next")
("c" ispell-continue "cont")
("e" flyspell-goto-next-error "next error")
("w" ispell-word "word")
("b" ispell-buffer "buffer")
("q" nil "quit" :color blue))
(global-set-key (kbd "s-s") 'flyspell-check-previous-highlighted-word)
(global-set-key (kbd "M-s-s") 'spell/body))
(setq save-abbrevs t
only-global-abbrevs t)
(setq-default abbrev-mode t)
(defun jmax-define-abbrev (abbreviation expansion)
"Define an ABBREVIATION that globally expands to EXPANSION.
for example: cheme to Chemical Engineering. This is essentially
like `inverse-add-blobal-abbrev', but doesn't require the prefix
arg, and is easier to remember I think."
(interactive "sAbbreviation: \nsExpansion: ")
(when (string-match " " abbreviation)
(error "No spaces allowed in an abbreviation"))
(define-abbrev global-abbrev-table abbreviation expansion))
;; http://endlessparentheses.com/ispell-and-abbrev-the-perfect-auto-correct.html
(define-key ctl-x-map "\C-i" 'endless/ispell-word-then-abbrev)
(defun endless/ispell-word-then-abbrev (p)
"Call `ispell-word'. Then create an abbrev for the correction made.
With prefix P, create local abbrev. Otherwise it will be global."
(interactive "P")
(let ((bef (downcase (or (thing-at-point 'word) ""))) aft)
(call-interactively 'ispell-word)
(setq aft (downcase (or (thing-at-point 'word) "")))
(unless (string= aft bef)
(message "\"%s\" now expands to \"%s\" %sally"
bef aft (if p "loc" "glob"))
(define-abbrev
(if p global-abbrev-table local-abbrev-table)
bef aft))))
;;* Theme
;; load this last so that the user theme can be loaded
(add-to-list 'custom-theme-load-path (expand-file-name "themes" starter-kit-dir))
(load-theme jmax-user-theme t)
(provide 'jmax)
;;; jmax.el ends here