-
Notifications
You must be signed in to change notification settings - Fork 2
/
dot-emacs
678 lines (512 loc) · 34 KB
/
dot-emacs
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Title: .emacs configuration for people who don't normally use Emacs, but still want to use org-mode.
;; Author: Jacob Levernier (except when otherwise noted)
;; Date: 2017-06-30
;; License: GPLv3
;; License rationale:
;; If you remove the code block that beings with "Code block from http://stackoverflow.com/a/36707038" and ends with "End of code block from http://stackoverflow.com/a/36707038", you may consider this released under The 3-Clause BSD License, copyright Jacob Levernier, 2017.
;; The above-mentioned code block is from Stack Exchange, which requires CC-BY-SA licensing. In order to be in compliance with this license, I'm also considering the code in this file overall GPLv3 licensed, because CC-BY-SA to GPLv3 license compatibility is approved by Creative Commons (https://creativecommons.org/share-your-work/licensing-considerations/compatible-licenses/).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set up the package manager, so that org-mode is available and packages can be easily downloaded and installed from the melpa repository
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(prefer-coding-system 'utf-8)
(require 'package)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(setq package-enable-at-startup nil)
(package-initialize) ;; Load packages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End package manager setup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Refresh the list of packages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(unless package-archive-contents
(package-refresh-contents))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End refresh the list of packages
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Easily list packages in this one central place. You'll be asked automatically whether you'd like to install any packages in this list that aren't currently installed the next time you start Emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq package-selected-packages
(quote
(
flycheck ;; For Syntax checking
powerline
solarized-theme ;; This can then be activated with M-x load-theme
markdown-mode
markdown-mode+
;;darkroom ;; Seems to be missing from Melpa as of 2017-07-12, and so is commented out for now.
ivy ;; For a dashboard
;;scroll-restore ;; For allowing scrolling without moving the cursor once it goes off-screen.
org-repo-todo ;; For todo functionality within a repo.
org-journal ;; An org-mode-based journal
undo-tree
tabbar
neotree
)))
(if (version< emacs-version "25.1")
(progn
(message "Emacs version is below 25.1")
;; Install any missing packages:
(dolist (package-name package-selected-packages)
(when (not (package-installed-p package-name))
(package-install package-name)))
)
(progn
(message "Emacs version is 25.1 or above.")
;; Install any missing packages that are listed in the package-selected-packages variable below. (This is a feature introduced in Emacs 25.1). See, e.g., http://stackoverflow.com/a/39891192
(package-install-selected-packages)
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of package list to automatically install
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enable other settings for making Emacs' interface easier to use
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;
;; NeoTree (a file browser)
;;;;;;;;;;;;;;;
(global-set-key [f8] 'neotree-toggle)
;;;;;;;;;;;;;;;
;; Ivy-mode
;;;;;;;;;;;;;;;
(ivy-mode 1) ;; Enable ivy-mode, which makes menus in Emacs nicer-looking and searchable.
;;;;;;;;;;;;;;;
;; TabBar-mode
;;;;;;;;;;;;;;;
;; NOTE: To customize the way that the tabbar looks, I recommend making edits through the emacs GUI by using 'M-x customize-group', then selecting 'tabbar', then pressing <enter>.
(tabbar-mode 1) ;; Enable tabbar-mode, which makes a browser-style tab bar if available buffers appear at the top of the window.
;; Put all tabs into one group, following https://www.emacswiki.org/emacs/TabBarMode
(setq tabbar-buffer-groups-function
(lambda ()
(list "All")))
(global-set-key (kbd "C-t") 'ivy-switch-buffer) ;; Set the keybinding Ctrl+t (like "new tab" in some editors and web browers) to bring up the buffer list.
;;;;;;;;;;;;;;;
;; Scroll-restore-mode (for saving your place when you scroll with your mouse)
;;;;;;;;;;;;;;;
;; These are commented out because scroll-restore causes an error with org-emphasize: "Error in post-command-hook (scroll-restore-post-command)..."
;;(scroll-restore-mode 1) ;; Change to nil to disable, and 1 to enable, scroll-restore mode by default
;;(global-set-key (kbd "C-x j") 'scroll-restore-jump-back) ;; Set a keybinding for jumping back when scrolling.
;;;;;;;;;;;;;;;
;; Load the Darkroom package (useful for writing prose -- it brings in the margins of the interface to offer less distraction when writing)
;;;;;;;;;;;;;;;
;;(require 'darkroom) ;; Seems to be missing from Melpa as of 2017-07-12, and so is commented out for now.
;;;;;;;;;;;;;;;
;; Powerline (for making the status bar at the bottom of the page more useful)
;;;;;;;;;;;;;;;
(require 'powerline)
(powerline-default-theme) ;; Turn on powerline
;;;;;;;;;;;;;;;
;; Font, text display, and color theme settings
;;;;;;;;;;;;;;;
;; Load solarized theme on startup
(load-theme 'solarized-light t)
;;(load-theme 'solarized-dark t) ;; Uncomment this for the solarized dark theme instead of the solarized light theme.
;; Set font to 16 pt. (1/10 font x 160):
(set-face-attribute 'default nil :height 160)
;; Word-wrap by word instead of character by default:
(setq-default word-wrap t)
;;;;;;;;;;;;;;;
;; Misc. interface settings
;;;;;;;;;;;;;;;
;; Set zoom in and out to Ctrl + and Ctrl - (By default, they're C-x C-+ and C-x C--, respectively)
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
;; Do the same as above for font sizing with C-mousewheel-up/down
(global-set-key (kbd "<C-mouse-4>") 'text-scale-increase)
(global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease)
;; Don't display the 'Welcome to GNU Emacs' buffer on startup
(setq inhibit-startup-message t)
;; From https://www.emacswiki.org/emacs/SmoothScrolling: Enable smooth scrolling with the mouse:
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
(setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
;; Cause window titles to display the current buffer's name (rather than just "emacs@computer-name")
(setq-default frame-title-format '("%b"))
;; Make Emacs function like a 'normal' text editor (with enhancements for plaintext tables), by:
;; Entering 'CUA' mode, which enables the C-z, C-s, C-c, C-v, etc. keybindings that are used in many other editors, as well as Shift-based text selection.
;; Enabling orgtbl-mode (via orgstruct-mode). This allows you to type
;; | 1 | 2 | 3 |
;; and press tab for a nicely-formatted ASCII table.
;;(orgstruct-mode) ;; Following https://www.gnu.org/software/emacs/manual/html_node/org/Tables-in-arbitrary-syntax.html#Tables-in-arbitrary-syntax, enable the use of orgtbl-mode (for tables) without actually turning on all of org-mode.
;;(orgtbl-mode) ;; Enable orgtbl-mode, where you can put pipe symbols around something and press Tab and it will format into a nice table for you.
(setq cursor-type '(bar . 2))
(global-set-key (kbd "C-s") 'save-buffer) ;; Map C-s to Save
(global-set-key (kbd "C-o") 'find-file) ;; Map C-o to Open
(require 'undo-tree)
(global-undo-tree-mode)
(global-set-key (kbd "C-S-z") 'undo-tree-redo) ;; Map C-S-z to Redo
(global-set-key (kbd "C-y") 'undo-tree-redo) ;; Map C-y to Redo
;; Make Ctrl-F4 close the current buffer and ctrl-tab scroll through buffers
(global-set-key (kbd "<C-f4>") 'kill-buffer)
(global-set-key (kbd "<C-tab>") 'switch-to-next-buffer)
(global-set-key (kbd "<C-iso-lefttab>") 'switch-to-prev-buffer)
;; Get isearch-forward to automatically wrap:
(defadvice isearch-search (after isearch-no-fail activate)
;; Code block from http://stackoverflow.com/a/36707038, authored by Chris Martin (http://stackoverflow.com/posts/36707038/revisions):
(unless isearch-success
(ad-disable-advice 'isearch-search 'after 'isearch-no-fail)
(ad-activate 'isearch-search)
(isearch-repeat (if isearch-forward 'forward))
(ad-enable-advice 'isearch-search 'after 'isearch-no-fail)
(ad-activate 'isearch-search)))
;; End of code block from http://stackoverflow.com/a/36707038
;; Make C-f activate search-forward
(global-set-key (kbd "C-f") 'isearch-forward)
(define-key isearch-mode-map "\C-f" 'isearch-repeat-forward)
;; From https://www.emacswiki.org/emacs/CuaMode: Activate CUA mode, which makes Emacs function with keybindings like in a "normal" editor : )
(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode nil) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour
;; Tell emacs to still use CUA keybindings in org-mode, which would otherwise replace some of them:
(setq org-support-shift-select t)
(setq org-replace-disputed-keys t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of extra interface configurations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DO NOT EDIT THIS SECTION MANUALLY
;; Variables configured from within Emacs
;; (Press C-h v for help understanding a variable -- type the variable's name, then press "edit"/"change", and choose a new setting for that variable. If you then click "Apply and Save", the change will be recorded here.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(bmkp-last-as-first-bookmark-file "~/.emacs.d/bookmarks")
'(custom-safe-themes
(quote
("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" default)))
'(darkroom-margins 0.2)
'(delete-selection-mode nil)
'(org-hide-leading-stars t)
'(org-journal-date-format "%A, %Y-%m-%d")
'(org-journal-file-format "%Y-%m-%d.org")
'(org-startup-truncated nil)
'(package-selected-packages
(quote
(tabbar flycheck powerline solarized-theme markdown-mode markdown-mode+ ivy org-repo-todo org-journal undo-tree)))
'(tabbar-background-color "dark gray")
'(tabbar-separator (quote (0.8))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(org-level-1 ((t (:inherit outline-1 :height 1.0))))
'(org-level-2 ((t (:inherit outline-2 :height 1.0))))
'(org-level-3 ((t (:inherit outline-3 :height 1.0))))
'(org-level-4 ((t (:inherit outline-4 :height 1.0))))
'(org-level-5 ((t (:inherit outline-5 :height 1.0))))
'(tabbar-button ((t (:inherit tabbar-default))))
'(tabbar-default ((t (:inherit variable-pitch :background "gainsboro" :foreground "dim gray" :box nil :underline nil :height 0.9))))
'(tabbar-highlight ((t (:background "cornsilk"))))
'(tabbar-selected ((t (:inherit nil :background "cornsilk" :foreground "black" :underline nil))))
'(tabbar-separator ((t (:inherit nil :background "dark gray" :underline nil))))
'(tabbar-unselected ((t (:inherit tabbar-default :box (:line-width 1 :color "white" :style released-button))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of variable settings made from within Emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Tab vs. Spaces settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make <tab> actually insert a tabstop, following (but editing from) http://www.creativeadea.com/uncategorized/force-emacs-to-use-tabs:
(setq-default indent-tabs-mode t)
;; Bind the TAB key
(global-set-key (kbd "TAB") 'self-insert-command)
;; Set the tab width
(setq-default default-tab-width 3)
(setq-default tab-width 3)
(setq-default c-basic-indent 3)
(setq-default c-basic-offset 3)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of tab vs. spaces settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;
;; Navigating between windows:
;;;;;;;;;;;;;;;;;;;;;;;;
;; Set custom keybindings for moving among windows (since org-mode takes over shift and alt/meta, and I like using the control key for moving quickly over words). The lowercase 's-' is for the Windows key (Not the Shift key (which is S-, with an uppercase S):
(global-set-key (kbd "C-S-M-<right>") 'windmove-right)
(global-set-key (kbd "C-S-M-<left>") 'windmove-left)
(global-set-key (kbd "C-S-M-<up>") 'windmove-up)
(global-set-key (kbd "C-S-M-<down>") 'windmove-down)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of settings for navigating between windows
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom functions for different writing-modes (e.g., for writing prose distraction-free, and making Emacs behave like a more "normal" text editor)
;; The 'laity/' in the function names is just to make them easier to search for. You can use your own name or delete that part of the function name)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun laity/prose-writing-mode ()
"Enter writing mode, turning some distractions off.
This function makes the following changes:
* Starts markdown mode. This enables markdown syntax highlighting.
* Enables orgtbl-mode (via orgstruct-mode). This allows you to type
| 1 | 2 | 3 |
and press tab for a nicely-formatted ASCII table.
* Enables flyspell-mode. This enables red lines under misspelled words. You can middle-click a word to change it.
* Enables markdown-display-inline-images. This will show images within markdown text, if the images 1) have an absolute path, and 2) do not have any other text in the parentheses portion of the image syntax (e.g., this is correct: '![Description goes here](/full/path/to/image.jpg)'. This is not correct: '![Description goes here](/full/path/to/image.jpg 'Description goes here')').
* Changes the theme to solarized-dark.
" ;; End of docstring (documentation string)
(interactive) ;; Tell emacs that this function is a command (and should thus be listed in the M-x list of commands).
(markdown-mode) ;; Turn on markdown syntax highlighting
;;(darkroom-mode) ;; Bring in the margins ;; Seems to be missing from Melpa as of 2017-07-12, and so is commented out for now.
(orgstruct-mode) ;; Following https://www.gnu.org/software/emacs/manual/html_node/org/Tables-in-arbitrary-syntax.html#Tables-in-arbitrary-syntax, enable the use of orgtbl-mode (for tables) without actually turning on all of org-mode.
(orgtbl-mode) ;; Enable orgtbl-mode, where you can put pipe symbols around something and press Tab and it will format into a nice table for you.
(flyspell-mode) ;; Enable spell-checking red underlines.
(markdown-display-inline-images) ;; Show markdown images (if they have absolute paths and no text other than the path within the parentheses portion) in the buffer. This can be toggled with M-x markdown-toggle-inline-images
(load-theme 'solarized-dark)) ;; Make the theme dark
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of custom functions for different styles of writing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Org-mode settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;
;; Set agenda files list:
;; This is the list of all folders and files into which org-mode will look for .org files.
;;;;;;;;;;;;;;;
(if (boundp 'org-user-agenda-files)
(setq org-agenda-files org-user-agenda-files)
(setq org-agenda-files (quote (
;; ('~' = your home directory)
"~/Daily_Logs"
"~/Primary_Syncing_Folder/Documents/todo"
))))
;;;;;;;;;;;;;;;
;; Set the org-journal directory
;; This is the directory (which, when typed here, needs to have a trailing slash ('/') into which org-journal-mode will look for .org files
;;;;;;;;;;;;;;;
(setq org-journal-dir "~/Primary_Syncing_Folder/Documents/Research_and_Project_Log_Notes/")
;;;;;;;;;;;;;;;
;; Set default TODO-list states (e.g., TODO, DONE, etc.) and colors for org-mode
;; '@/!' means that a prompt will appear asking for information when these states are used (?)
;;;;;;;;;;;;;;;
;; Adapted from org-mode complex example file (which is GPLv3-licensed):
;; Set default TODO states (and a color scheme for them) for all org files.
;; Following 'C-h v org-todo-keywords', EXAMPLE(e@/!) means that EXAMPLE can be chosen with the 'e' key when using C-c C-t, and that on entering it, a timestamp and note (@) should be recorded, and than on leaving it, just a timestamp (!) should be recorded. (For a timestamp upon just leaving the state, EXAMPLE(e/!) would be valid).
;; Anything after the pipe symbol ('|') is considered a DONE-type state.
(setq org-todo-keywords
(quote ((sequence "TODO(t)" "NEXT(n)" "RIGHT_NOW(r)" "SCHEDULED(s)" "|" "DONE(d!)")
(sequence "SCHEDULED(s@/)" "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)")
(sequence "|" "TIME_TRACKED(x)")))) ;; TIME_TRACKED is a non-todo but still time-tracked item.
(setq org-todo-keyword-faces
(quote (("TODO" :foreground "red" :weight bold)
("NEXT" :foreground "blue" :weight bold)
("RIGHT_NOW" :foreground "green" :weight bold)
("DONE" :foreground "forest green" :weight bold)
("WAITING" :foreground "orange" :weight bold)
("HOLD" :foreground "magenta" :weight bold)
("CANCELLED" :foreground "forest green" :weight bold)
("SCHEDULED" :foreground "forest green" :weight bold))))
(setq org-todo-state-tags-triggers
(quote (("CANCELLED" ("CANCELLED" . t))
("WAITING" ("WAITING" . t))
("HOLD" ("WAITING") ("HOLD" . t))
(done ("WAITING") ("HOLD"))
("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
;;;;;;;;;;;;;;;
;; Misc. org-mode settings
;;;;;;;;;;;;;;;
(setq org-agenda-search-view-always-boolean t) ;; When searching in org-mode's agenda, don't require explicit '+' symbols (so 'test1 test2' will be seen as '+test1 +test2' when this is set to t)
;; Get header font sizes to change alongside non-header text when the font is increased or decreased. For a discussion about this, see, e.g., http://stackoverflow.com/a/21525620.
(setq solarized-scale-org-headlines nil)
;;;;;;;;;;;;;;;
;; Org-mode syntax
;;;;;;;;;;;;;;;
;; (setq org-hide-emphasis-markers t) ;; Hide markup (e.g., *bold*, /italics/, etc.). I've decided to comment this out for now, because org-emphasize below does not always act in intuitive ways.
;; Set keyboard shortcuts for C-b (bold), C-u (underline), and C-i (italicize). For a discussion of this, see, e.g., https://emacs.stackexchange.com/questions/27645:
(defun laity/org-emphasize-with-message-and-highlighting(org-emphasize-character org-emphasize-character-plaintext keybinding-character-for-message)
(interactive)
(org-emphasize org-emphasize-character)
(exchange-point-and-mark) ;; Re-select the originally-highlighted text
(setq deactivate-mark nil) ;; Tell emacs to actually show the highlighting.
(message "You can un-bold text by deleting the '%s's or pressing C-S-%s." org-emphasize-character-plaintext keybinding-character-for-message))
(defun laity/org-un-emphasize()
(interactive)
(org-emphasize ?\ )
(exchange-point-and-mark) ;; Re-select the originally-highlighted text
(setq deactivate-mark nil) ;; Tell emacs to actually show the highlighting.
)
(define-key org-mode-map (kbd "C-b") (
lambda()
(interactive)
(laity/org-emphasize-with-message-and-highlighting ?\* '* 'b)
))
(define-key org-mode-map (kbd "C-i") (
lambda()
(interactive)
(laity/org-emphasize-with-message-and-highlighting ?\/ '/ 'i)
))
(define-key org-mode-map (kbd "C-u") (
lambda()
(interactive)
(laity/org-emphasize-with-message-and-highlighting ?\_ '_ 'u)
))
(define-key org-mode-map (kbd "S-C-b") (
lambda ()
(interactive)
(laity/org-un-emphasize)
))
(define-key org-mode-map (kbd "S-C-i") (
lambda ()
(interactive)
(laity/org-un-emphasize)
))
(define-key org-mode-map (kbd "S-C-u") (
lambda ()
(interactive)
(laity/org-un-emphasize)
))
;;;;;;;;;;;;;;;
;; Misc. other settings
;;;;;;;;;;;;;;;
;; Make shift+click highlight text rather than open a menu (see, e.g., https://superuser.com/a/522183):
(define-key global-map (kbd "<S-down-mouse-1>") 'mouse-save-then-kill)
;; When in org-mode, turn org-indent-mode on by default:
(add-hook 'org-mode-hook ;; When entering into org-mode...
(lambda ()
(org-indent-mode 1)))
;; org-indent-mode occasionally needs re-initializing (see here: https://github.com/syl20bnr/spacemacs/issues/2732), so we'll define a function and keybinding to do so:
(defun laity/reindent()
"Fix org-mode indentations." ;; Inspired by https://github.com/syl20bnr/spacemacs/issues/2732#issuecomment-173704844, but altered from it (it was really just these two steps; my use and invocation are different).
(interactive)
(org-indent-mode 1)
(recenter-top-bottom))
;; Following http://orgmode.org/manual/TODO-dependencies.html#TODO-dependencies, make org-mode honor Todo dependencies by not allowing something to be marked DONE unless its children have all been addressed.
(setq org-enforce-todo-dependencies 't)
(setq org-enforce-todo-checkbox-dependencies 't)
;; Make the cursor blink, and be a narrow line:
(blink-cursor-mode 1)
(setq-default cursor-type 'bar)
(setq make-backup-files nil) ; From http://superuser.com/a/84168/192382: stop creating (backup) (~) files
;; When in org-mode, load a function I wrote for facilitating pasting links, and set keyboard commands for it and a related function.
(add-hook 'org-mode-hook ;; When entering into org-mode...
(lambda ()
;; Define the function:
(defun laity/org-id-paste-link ()
"Paste an org-mode link to another line (or other file listed in org-agenda-files), with the prefix \"id:\".
This function assumes that the last thing that you did before running this function was going to the target location of the link and running M-x org-id-copy, which will generate (if necessary) and then copy an ID for that line of org-mode document."
(interactive)
(insert "[[id:")
(yank)
(insert "][]]")
(backward-char 2))
(local-set-key (kbd "C-x l") 'org-id-copy)
(local-set-key (kbd "C-x L") 'laity/org-id-paste-link))) ;; local-set-key will set the key for the major mode (any buffer in org-mode).
;; Set new text for emacs' startup "Scratch buffer:"
(setq initial-scratch-message "Welcome to Emacs, configured for use like a normal text editor, with org-mode built-in!
* Enabling org-mode
To turn org-mode on, type M-x (as noted below, that means hold down the 'Meta' key (usually the Alt key or Command key, depending on your keyboard) and x at the same time), then type 'org-mode', and press enter.
This document is written in org-mode syntax. Turn on org-mode now, and you'll see the headlines 'fold' down. You can then press <Tab> repeatedly on a headline to cycle through it being folded, partially open, and fully open. You can also use Shift-<Tab> to cycle through *all* headlines in the document at once.
*Go ahead and enable org-mode now, using the instructions above.*
* org-mode syntax
org-mode has some special conventions for marking-up text. Many of these are similar to [[https://daringfireball.net/projects/markdown/syntax][Markdown]], which you may have heard of.
For example:
- Want to make a bullet list? Just add a dash to the front of each line, like with this line!
- Want to make text *bold* or /italicized/?
- Want to mark something as ~computer code~?
- Want to insert a block quote?
#+BEGIN_QUOTE
I use Emacs, which might be thought of as a thermonuclear word processor.
- Neal Stephenson
#+END_QUOTE
(If you're in org-mode right now, you can click on either the line 'Want to insert a block quote' and/or the line '#+BEGIN_QUOTE' and press <Tab> on your keyboard to 'Fold' the rest of the text underneath.)
** More org-mode syntax examples
You can format text in *more* /more/ _more_ =more= ~more~ +more+ ways.
*** This line is a 'Headline' because it starts with one or more asterisks (more asterisks = more indented in the list). It has three tags (like hashtags) :tag1:tag2:tag3:
*** TODO This line is another 'Headline.' It is also a 'Todo' item, because it starts with the word TODO. With org-mode activated, put your cursor on this line, and run *M-x org-todo* (or use the keyboard shortcut, *C-c C-t*, and try changing it's TODO state to 'DONE'.
*** What's below this is an example bullet list (press <Tab> on this line if you can't see what's below it)
- This is a bullet list
- [ ] This line has a checkbox.
- [X] This line also has a checkbox, which has been checked.
- [ ] This line has a checkbox. To check it, you can either manually write 'X' in it, or you can use the keyboard shortcut *C-c C-c*. Go ahead and try that now!
** Documentation for org-mode syntax
The *'Compact Guide' to org-mode's syntax* is [[http://orgmode.org/orgguide.pdf][here in PDF form]] and [[http://orgmode.org/guide/][here in HTML form]]. The PDF is 45 pages, but that's because it has a lot of explanatory text; you *don't need to read the whole document, and certainly not all at once!* Rather, just look through the Table of Contents when you have a question, and learn as you go.
* Keyboard shortcuts to remember
:PROPERTIES:
:ID: 0fc580dc-4707-49bb-b42c-4d4f92886ab8
This 'Properties drawer' gives this headline ('Keyboard shortcuts to remember') a unique ID number that we can make a clickable link to. There's a link above that links to this ID.
This Properties drawer and ID number were automatically created using the command 'org-id-copy', or the keyboard command *C-x l* (as mentioned below, under the 'org-mode shortcuts' headline).
You can link to this from elsewhere in any document you've listed in the ~org-agenda-files~ part of your ~.emacs~ file using syntax like this: ~[ [id:0fc580dc-4707-49bb-b42c-4d4f92886ab8][Text for the link goes here] ]~
*Note:* Linking to this will only work for files that you've added to the ~org-agenda-files~ part of your ~.emacs~ file.
:END:
** Explanation of how keyboard shortcuts are written out here (as in other org-mode documentation you might read)
- 'C-h k' means 'Hold down Control and h and the same time, then press k.'
- Similarly, 'M-x' means 'Hold down 'Meta' (usually the Alt key, depending on your keyboard) and x at the same time.'
- 'C-S-<up>' means 'Hold down Control, Shift, and the up arrow button at the same time.'
- Similarly, 'C-c C-t' means 'Hold down Control and c and the same time, then hold down Control and t at the same time.'
** Summarizing what's below: *The four basic keyboard commands for you to learn*
org-mode and Emacs both have so many features, it takes /years/ to learn them all. Thus, my recommendation is not to try to learn everything all at once. Rather, learn the very basics, and then add to your knowledge as you have new needs that come up.
With this in mind, there are just four keyboard commands to remember when starting to use org-mode with this configuration file:
- *M-x*: Bring up a list of every function in Emacs. Put differently, bring up a list of every thing that Emacs can do, from moving the cursor like your arrow keys do to doing complicated org-mode tasks.
- The menu that M-x will bring up is searchable. Thus, *you don't need to remember every function name,* if you can articulate a vague idea of what its name might be. You can always learn keyboard shortcuts later.
- For example, do you want to clock-in to a task in your Todo list? By searching for the phrase 'clock in', you'll find the function's name, 'org-clock-in'!
- Another example: Want to select from a list of all of the Todo states (TODO, DONE, SCHEDULED, HOLD, etc.) that org-mode understands? Search for the phrase 'todo', and you'll find 'org-todo'!
- *C-g* (think 'Control: Go away'): The equivalent of 'Cancel' whenever you're in a menu like from *M-x*.
- *C-x b* (think 'Control/execute buffers'): Bring up a list of all of the open buffers (buffers are like tabs, but you can bring them up anywhere, including in multiple windows). Like the *M-x* menu, this menu is searchable.
- *C-x 1*: Close all split-screen panes except for the current one.
** Normal keyboard shortcuts
Although Emacs doesn't typically use them, this configuration of Emacs has enabled 'normal' keyboard shortcuts like C-c for *copy*, C-v for *paste*, C-o for *open*, etc.
If you notice that a keyboard shortcut you try to use doesn't work, let me know, and we can see about adding it.
*C-f* does work for *searching* a file. To jump between matches, you need to keep pressing C-f (instead of <Enter>, like in some text editors).
You can highlight text and then press *C-b* to *bold* it. Similarly, you can use *C-i* for /italicizing/ and *C-u* for _underlining_ text. *C-S-b*, *C-S-i*, and *C-S-u* will un-emphasize (un-bold, un-italicize, and un-underline) highlighted text.
** Menus
If you remember even *just the two keyboard shortcuts below*, you can use Emacs with org-mode :)
- *M-x*: Get a searchable pop-up menu (called 'Ivy') of every function in Emacs
- *C-g*: Cancel a pop-up menu
You can change the font that Emacs uses using the *Options -> Set Default Font...* menu at the top of the window.
*F8* will bring up a clickable file browser sidebar that you can use in addition to the ~File -> Open~ menu.
** Getting help
- *C-h k*: Get the help documentation for any keyboard shortcut (you type the keyboard shortcut, and it tells you what that shortcut does)
- *C-h f*: Get the help documentation for any function (you type the function name, and it shows you the help documentation for it
- *C-h v*: Get the value of any configuration variable in Emacs (you type the variable name, and it tells you what it does and what it's currently set to)
** Switching between windows and open files ('buffers')
(A '*buffer*' in Emacs is like a tab in Firefox or Chrome -- it's a file or scratchpad that's currently open)
- *C-x b*: Switch between buffers
- *C-x 1*: If you have multiple windows/panes open, switch to just the current one.
- *windows-key-<up>*, *windows-key-<down>*: If you have multiple windows/panes open, move between them.
** Scrolling
One element of Emacs that sometimes frustrates users is that *the cursor will move when you scroll through a long document.* If you would like to 'bookmark' a part of your document to be able to easily jump back to, you can use *M-x point-to-register*. It will ask you to type a letter (for example, 'a'), to save your place. When you want to jump back to that place in your document, you can use ~M-x jump-to-register~, and then press 'a'.
This means that you can have many bookmarks in your document (from a-z and 0-9, for example)!
Because the ~M-x~ menu is searchable, you can also search for just ~register~ to see what other commands Emacs can use for jumping around a document (and across documents/buffers). For example, ~M-x list-registers~ will list all of the bookmarks you've set across all open documents, along with the letters/numbers you've used to identify them.
** org-mode shortcuts
- *C-x l* / *C-x L*: When you're in org-mode, you can go to any headline (any line that starts with '*'), and type C-x l (think 'l' for 'link'). This will create an ID number for that headline and copy a link to it to your keyboard.
Then you can go anywhere else in your document and press C-x L to paste the link in org-mode format. Type some text to describe the link, and you now have a clickable link to that first place in your document!
*Note:* This will only work for files that you've added to the ~org-agenda-files~ part of your ~.emacs~ file.
- *C-c C-c*: Toggle/refresh stuff (toggle check boxes, change tags, refresh clock-table, depending on the context)
- *C-c C-t*: Quick access to list of todo states (runs M-x org-todo)
- *M-<Enter>*: Add a new list item
- :M-S-<Enter>*: Add a new checkbox item
- *M-[left/right]*: change the spacing of list items
- *<Tab>*: Fold / Unfold the headline where your cursor is.
- *S-<Tab>*: Fold / Unfold every headline in the document.
- *M-<up>* / *M-<down>*: Move a headline up or down
- *M-<left>* / *M-<right>*: De-indent / Indent a headline
- *M-<Enter>*: Insert a new headline
- *M-S-<Enter>*: Insert a new TODO headline
* org-mode functions to remember
(You can run any of these from the M-x menu):
- *org-todo*: Quick list of todo states (nicer than cycling through with S-[left/right])
- *org-show-todo-tree*: See the todo list for the current buffer (with non-todo lines folded)
- *org-add-note*: Add a note with a datestamp
- *org-sort*: Sort a list by something (you get a menu re: alphabetical, numeric, etc.)
- *org-sparse-tree*: See just the unfinished Todo items in the current file.
- *org-clock-in* / *org-clock-out*: Add a timeclock to the current headline.
- *org-clock-report*: See how much time you've spent (from *org-clock-in* / *org-clock-out*) on the current headline and the headlines below it. You can configure the report [[http://orgmode.org/manual/The-clock-table.html]][in a lot of ways]].
- *org-agenda*: Search through all of your ~org-agenda-files~ files, see all of the Todo entries across them, and more.
(Within org-agenda, if you press a (for full Agenda view), then v (for View) and d (for Day), you'll get the current day's entries.
") ;; End of scratch message definition.
;; Since the scratch-buffer's message is long, tell emacs to scroll to the beginning of the buffer on startup:
(add-hook 'emacs-startup-hook 'startup-scroll-function)
(defun startup-scroll-function ()
"Scroll to the top of the buffer"
(beginning-of-buffer))