forked from pprevos/emacs-writing-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
747 lines (606 loc) · 18 KB
/
init.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
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
;;; init.el --- Emacs Writing Studio init -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Peter Prevos
;; Author: Peter Prevos <[email protected]>
;; Maintainer: Peter Prevos <[email protected]>
;; This file is NOT part of GNU Emacs.
;;
;; 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 <https://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; Emacs Writing Studio init file
;; https://lucidmanager.org/tags/emacs
;;
;; This init file is tangled from the Org mode source:
;; documents/ews-book/99-appendix.org
;;
;;; Code:
;; Emacs 29? EWS leverages functionality from the latest Emacs version.
(when (< emacs-major-version 29)
(error "Emacs Writing Studio requires Emacs version 29 or later"))
;; Custom settings in a separate file and load the custom settings
(setq-default custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
(keymap-global-set "C-c w v" 'customise-variable)
;; Set package archives
(use-package package
:config
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize))
;; Package Management
(use-package use-package
:custom
(use-package-always-ensure t)
(package-native-compile t)
(warning-minimum-level :emergency))
;; Load EWS functions
(load-file (concat (file-name-as-directory user-emacs-directory) "ews.el"))
;; Check for missing external software
;;
;; - soffice (LibreOffice): View and create office documents
;; - zip: Unpack ePub documents
;; - pdftotext (poppler-utils): Convert PDF to text
;; - ddjvu (DjVuLibre): View DjVu files
;; - curl: Reading RSS feeds
;; - convert (ImageMagick) or gm (GraphicsMagick): Convert image files
;; - latex (TexLive, MacTex or MikTeX): Preview LaTex and export Org to PDF
;; - hunspell: Spellcheck. Also requires a hunspell dictionary
;; - grep: Search inside files
;; - gs (GhostScript) or mutool (MuPDF): View PDF files
;; - mpg321, ogg123 (vorbis-tools), mplayer, mpv, vlc: Media players
;; - git: Version control
(ews-missing-executables
'("soffice"
"zip"
"pdftotext"
"ddjvu"
"curl"
("convert" "gm")
"latex"
"hunspell"
"grep"
("gs" "mutool")
("mpg321" "ogg123" "mplayer" "mpv" "vlc")
"git"))
;;; LOOK AND FEEL
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
;; Short answers only please
(setq use-short-answers t)
;; Spacious padding
(use-package spacious-padding
:custom
(line-spacing 3)
:init
(spacious-padding-mode 1))
;; Modus Themes
(use-package modus-themes
:custom
(modus-themes-italic-constructs t)
(modus-themes-bold-constructs t)
(modus-themes-mixed-fonts t)
(modus-themes-to-toggle
'(modus-operandi-tinted modus-vivendi-tinted))
:init
(load-theme 'modus-operandi-tinted :no-confirm)
:bind
(("C-c w t t" . modus-themes-toggle)
("C-c w t m" . modus-themes-select)
("C-c w t s" . consult-theme)))
;; Mixed-pich mode
(use-package mixed-pitch
:hook
(text-mode . mixed-pitch-mode))
;; Window management
;; Split windows sensibly
(setq split-width-threshold 120
split-height-threshold nil)
;; Keep window sizes balanced
(use-package balanced-windows
:config
(balanced-windows-mode))
;; MINIBUFFER COMPLETION
;; Enable vertico
(use-package vertico
:init
(vertico-mode)
:custom
(vertico-sort-function 'vertico-sort-history-alpha))
;; Persist history over Emacs restarts.
(use-package savehist
:init
(savehist-mode))
;; Search for partial matches in any order
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides
'((file (styles partial-completion)))))
;; Enable richer annotations using the Marginalia package
(use-package marginalia
:init
(marginalia-mode))
;; Improve keyboard shortcut discoverability
(use-package which-key
:config
(which-key-mode)
:custom
(which-key-max-description-length 40)
(which-key-lighter nil)
(which-key-sort-order 'which-key-description-order))
;; Improved help buffers
(use-package helpful
:bind
(("C-h f" . helpful-function)
("C-h x" . helpful-command)
("C-h k" . helpful-key)
("C-h v" . helpful-variable)))
;;; Text mode settings
(use-package text-mode
:ensure
nil
:hook
(text-mode . visual-line-mode)
:init
(delete-selection-mode t)
:custom
(sentence-end-double-space nil)
(scroll-error-top-bottom t)
(save-interprogram-paste-before-kill t))
;; Check spelling with flyspell and hunspell
(use-package flyspell
:custom
(ispell-program-name "hunspell")
(ispell-dictionary ews-hunspell-dictionaries)
(flyspell-mark-duplications-flag nil) ;; Writegood mode does this
(org-fold-core-style 'overlays) ;; Fix Org mode bug
:config
(ispell-set-spellchecker-params)
(ispell-hunspell-add-multi-dic ews-hunspell-dictionaries)
:hook
(text-mode . flyspell-mode)
:bind
(("C-c w s s" . ispell)
("C-;" . flyspell-auto-correct-previous-word)))
;;; Ricing Org mode
(use-package org
:custom
(org-startup-indented t)
(org-hide-emphasis-markers t)
(org-startup-with-inline-images t)
(org-image-actual-width '(450))
(org-fold-catch-invisible-edits 'error)
(org-pretty-entities t)
(org-use-sub-superscripts "{}")
(org-id-link-to-org-use-id t)
(org-fold-catch-invisible-edits 'show))
;; Show hidden emphasis markers
(use-package org-appear
:hook
(org-mode . org-appear-mode))
;; LaTeX previews
(use-package org-fragtog
:after org
:hook
(org-mode . org-fragtog-mode)
:custom
(org-startup-with-latex-preview nil)
(org-format-latex-options
(plist-put org-format-latex-options :scale 2)
(plist-put org-format-latex-options :foreground 'auto)
(plist-put org-format-latex-options :background 'auto)))
;; Org modern: Most features are disabled for beginning users
(use-package org-modern
:hook
(org-mode . org-modern-mode)
:custom
(org-modern-table nil)
(org-modern-keyword nil)
(org-modern-timestamp nil)
(org-modern-priority nil)
(org-modern-checkbox nil)
(org-modern-tag nil)
(org-modern-block-name nil)
(org-modern-keyword nil)
(org-modern-footnote nil)
(org-modern-internal-target nil)
(org-modern-radio-target nil)
(org-modern-statistics nil)
(org-modern-progress nil))
;; Consult convenience functions
(use-package consult
:bind
(("C-c w h" . consult-org-heading)
("C-c w g" . consult-grep)))
;; INSPIRATION
;; Doc-View
(use-package doc-view
:custom
(doc-view-resolution 300)
(large-file-warning-threshold (* 50 (expt 2 20))))
;; Read ePub files
(use-package nov
:init
(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))
;; Reading LibreOffice files
;; Fixing a bug in Org Mode pre-9.7
;; Org mode clobbers associations with office documents
(use-package ox-odt
:ensure nil
:config
(add-to-list 'auto-mode-alist
'("\\.\\(?:OD[CFIGPST]\\|od[cfigpst]\\)\\'"
. doc-view-mode-maybe)))
;; Managing Bibliographies
(use-package bibtex
:custom
(bibtex-user-optional-fields
'(("keywords" "Keywords to describe the entry" "")
("file" "Relative or absolute path to attachments" "" )))
(bibtex-align-at-equal-sign t)
:config
(ews-bibtex-register)
:bind
(("C-c w b r" . ews-bibtex-register)))
;; Biblio package for adding BibTeX records
(use-package biblio
:bind
(("C-c w b b" . ews-bibtex-biblio-lookup)))
;; Citar to access bibliographies
(use-package citar
:defer t
:custom
(citar-bibliography ews-bibtex-files)
:bind
(("C-c w b o" . citar-open)))
;; Read RSS feeds with Elfeed
(use-package elfeed
:custom
(elfeed-db-directory
(expand-file-name "elfeed" user-emacs-directory))
(elfeed-show-entry-switch 'display-buffer)
:bind
("C-c w e" . elfeed))
;; Configure Elfeed with org mode
(use-package elfeed-org
:config
(elfeed-org)
:custom
(rmh-elfeed-org-files
(list (concat (file-name-as-directory (getenv "HOME")) "elfeed.org"))))
;; Easy insertion of weblinks
(use-package org-web-tools
:bind
(("C-c w w" . org-web-tools-insert-link-for-url)))
;; Emacs Multimedia System
(use-package emms
:config
(require 'emms-setup)
(require 'emms-mpris)
(emms-all)
(emms-default-players)
(emms-mpris-enable)
:custom
(emms-browser-covers #'emms-browser-cache-thumbnail-async)
:bind
(("C-c w m b" . emms-browser)
("C-c w m e" . emms)
("C-c w m p" . emms-play-playlist )
("<XF86AudioPrev>" . emms-previous)
("<XF86AudioNext>" . emms-next)
("<XF86AudioPlay>" . emms-pause)))
(use-package openwith
:config
(openwith-mode t)
:custom
(openwith-associations nil))
;; Fleeting notes
(use-package org
:bind
(("C-c c" . org-capture)
("C-c l" . org-store-link))
:custom
(org-goto-interface 'outline-path-completion)
(org-capture-templates
'(("f" "Fleeting note"
item
(file+headline org-default-notes-file "Notes")
"- %?")
("p" "Permanent note" plain
(file denote-last-path)
#'denote-org-capture
:no-save t
:immediate-finish nil
:kill-buffer t
:jump-to-captured t)
("t" "New task" entry
(file+headline org-default-notes-file "Tasks")
"* TODO %i%?"))))
;; Denote
(use-package denote
:defer t
:custom
(denote-sort-keywords t)
:hook
(dired-mode . denote-dired-mode)
:custom-face
(denote-faces-link ((t (:slant italic))))
:init
(require 'denote-org-extras)
:bind
(("C-c w d b" . denote-find-backlink)
("C-c w d d" . denote-date)
("C-c w d f" . denote-find-link)
("C-c w d h" . denote-org-extras-link-to-heading)
("C-c w d i" . denote-link-or-create)
("C-c w d k" . denote-rename-file-keywords)
("C-c w d l" . denote-insert-link)
("C-c w d n" . denote)
("C-c w d r" . denote-rename-file)
("C-c w d R" . denote-rename-file-using-front-matter)))
;; Consult-Notes for easy access to notes
(use-package consult-notes
:bind
(("C-c w f" . consult-notes)
("C-c w d g" . consult-notes-search-in-all-notes))
:init
(consult-notes-denote-mode))
;; Citar-Denote to manage literature notes
(use-package citar-denote
:custom
(citar-open-always-create-notes t)
:init
(citar-denote-mode)
:bind
(("C-c w b c" . citar-create-note)
("C-c w b n" . citar-denote-open-note)
("C-c w b x" . citar-denote-nocite)
:map org-mode-map
("C-c w b k" . citar-denote-add-citekey)
("C-c w b K" . citar-denote-remove-citekey)
("C-c w b d" . citar-denote-dwim)
("C-c w b e" . citar-denote-open-reference-entry)))
;; Explore and manage your Denote collection
(use-package denote-explore
:bind
(;; Statistics
("C-c w x c" . denote-explore-count-notes)
("C-c w x C" . denote-explore-count-keywords)
("C-c w x b" . denote-explore-barchart-keywords)
("C-c w x e" . denote-explore-barchart-filetypes)
;; Random walks
("C-c w x r" . denote-explore-random-note)
("C-c w x l" . denote-explore-random-link)
("C-c w x k" . denote-explore-random-keyword)
("C-c w x x" . denote-explore-random-regex)
;; Denote Janitor
("C-c w x d" . denote-explore-identify-duplicate-notes)
("C-c w x z" . denote-explore-zero-keywords)
("C-c w x s" . denote-explore-single-keywords)
("C-c w x o" . denote-explore-sort-keywords)
("C-c w x w" . denote-explore-rename-keyword)
;; Visualise denote
("C-c w x n" . denote-explore-network)
("C-c w x v" . denote-explore-network-regenerate)
("C-c w x D" . denote-explore-degree-barchart)))
;; Set some Org mode shortcuts
(use-package org
:bind
(:map org-mode-map
("C-c w n" . ews-org-insert-notes-drawer)
("C-c w p" . ews-org-insert-screenshot)
("C-c w c" . ews-org-count-words)))
;; Distraction-free writing
(use-package olivetti
:demand t
:bind
(("C-c w o" . ews-olivetti)))
;; Undo Tree
(use-package undo-tree
:config
(global-undo-tree-mode)
:custom
(undo-tree-auto-save-history nil)
:bind
(("C-c w u" . undo-tree-visualise)))
;; Export citations with Org Mode
(require 'oc-natbib)
(require 'oc-csl)
(setq org-cite-global-bibliography ews-bibtex-files
org-cite-insert-processor 'citar
org-cite-follow-processor 'citar
org-cite-activate-processor 'citar)
;; Lookup words in the online dictionary
(use-package dictionary
:custom
(dictionary-server "dict.org")
:bind
(("C-c w s d" . dictionary-lookup-definition)))
(use-package powerthesaurus
:bind
(("C-c w s p" . powerthesaurus-transient)))
;; Writegood-Mode for weasel words, passive writing and repeated word detection
(use-package writegood-mode
:bind
(("C-c w s r" . writegood-reading-ease)
("C-c w s l" . writegood-grade-level))
:hook
(text-mode . writegood-mode))
;; Titlecasing
(use-package titlecase
:custom
(titlecase-style 'apa)
:bind
(("C-c w s t" . titlecase-dwim)
("C-c w s c" . ews-org-headings-titlecase)))
;; Abbreviations
(add-hook 'text-mode-hook 'abbrev-mode)
;; Lorem Ipsum generator
(use-package lorem-ipsum
:custom
(lorem-ipsum-list-bullet "- ") ;; Org mode bullets
:init
(setq lorem-ipsum-sentence-separator
(if sentence-end-double-space " " " "))
:bind
(("C-c w s i" . lorem-ipsum-insert-paragraphs)))
;; ediff
(use-package ediff
:ensure nil
:custom
(ediff-keep-variants nil)
(ediff-split-window-function 'split-window-horizontally)
(ediff-window-setup-function 'ediff-setup-windows-plain))
(use-package fountain-mode)
(use-package markdown-mode)
;; Generic Org Export Settings
(use-package org
:custom
(org-export-with-drawers nil)
(org-export-with-todo-keywords nil)
(org-export-with-broken-links t)
(org-export-with-toc nil)
(org-export-with-smart-quotes t)
(org-export-date-timestamp-format "%e %B %Y"))
;; epub export
(use-package ox-epub
:demand t
:init
(require 'ox-org))
;; LaTeX PDF Export settings
(use-package ox-latex
:ensure nil
:demand t
:custom
;; Multiple LaTeX passes for bibliographies
(org-latex-pdf-process
'("pdflatex -interaction nonstopmode -output-directory %o %f"
"bibtex %b"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
;; Clean temporary files after export
(org-latex-logfiles-extensions
(quote ("lof" "lot" "tex~" "aux" "idx" "log" "out"
"toc" "nav" "snm" "vrb" "dvi" "fdb_latexmk"
"blg" "brf" "fls" "entoc" "ps" "spl" "bbl"
"tex" "bcf"))))
;; EWS paperback configuration
(with-eval-after-load 'ox-latex
(add-to-list
'org-latex-classes
'("ews"
"\\documentclass[11pt, twoside]{memoir}
\\setstocksize{9.25in}{7.5in}
\\settrimmedsize{\\stockheight}{\\stockwidth}{*}
\\setlrmarginsandblock{2cm}{1cm}{*}
\\setulmarginsandblock{1.5cm}{2.25cm}{*}
\\checkandfixthelayout
\\setcounter{tocdepth}{0}
\\OnehalfSpacing
\\usepackage{ebgaramond}
\\usepackage[htt]{hyphenat}
\\chapterstyle{bianchi}
\\setsecheadstyle{\\normalfont \\raggedright \\textbf}
\\setsubsecheadstyle{\\normalfont \\raggedright \\textbf}
\\setsubsubsecheadstyle{\\normalfont\\centering}
\\usepackage[font={small, it}]{caption}
\\pagestyle{myheadings}
\\usepackage{ccicons}
\\usepackage[authoryear]{natbib}
\\bibliographystyle{apalike}
\\usepackage{svg}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
;;; ADMINISTRATION
;; Bind org agenda command and custom agenda
(use-package org
:custom
(org-agenda-custom-commands
'(("e" "Agenda, next actions and waiting"
((agenda "" ((org-agenda-overriding-header "Next three days:")
(org-agenda-span 3)
(org-agenda-start-on-weekday nil)))
(todo "NEXT" ((org-agenda-overriding-header "Next Actions:")))
(todo "WAIT" ((org-agenda-overriding-header "Waiting:")))))))
:bind
(("C-c a" . org-agenda)))
;; FILE MANAGEMENT
(use-package dired
:ensure
nil
:commands
(dired dired-jump)
:custom
(dired-listing-switches
"-goah --group-directories-first --time-style=long-iso")
(dired-dwim-target t)
(delete-by-moving-to-trash t)
:init
(put 'dired-find-alternate-file 'disabled nil))
;; Hide hidden files
(use-package dired
:ensure nil
:hook (dired-mode . dired-omit-mode)
:bind (:map dired-mode-map
( "." . dired-omit-mode))
:custom (dired-omit-files "^\\.[a-zA-Z0-9]+"))
;; Backup files
(setq-default backup-directory-alist
`(("." . ,(expand-file-name "backups/" user-emacs-directory)))
version-control t
delete-old-versions t
create-lockfiles nil)
;; Recent files
(use-package recentf
:config
(recentf-mode t)
:custom
(recentf-max-saved-items 50)
:bind
(("C-c w r" . recentf-open)))
;; Bookmarks
(use-package bookmark
:custom
(bookmark-save-flag 1)
:bind
("C-x r d" . bookmark-delete))
;; Image viewer
(use-package emacs
:custom
(image-dired-external-viewer "gimp")
:bind
((:map image-mode-map
("k" . image-kill-buffer)
("<right>" . image-next-file)
("<left>" . image-previous-file))
(:map dired-mode-map
("C-<return>" . image-dired-dired-display-external))))
(use-package image-dired
:bind
(("C-c w I" . image-dired))
(:map image-dired-thumbnail-mode-map
("C-<right>" . image-dired-display-next)
("C-<left>" . image-dired-display-previous)))
;; ADVANCED UNDOCUMENTED EXPORT SETTINGS FOR EWS
;; Use GraphViz for flow diagrams
;; requires GraphViz software
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t))) ; this line activates GraophViz dot