summaryrefslogtreecommitdiff
path: root/blendoit/init-blendoit.org
blob: 67c33d6f0f90630c047dbcea34975f117318001a (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
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
#+TITLE: Blendoit's literate GNU Emacs config
#+AUTHOR: Marius Peter
#+DATE: <2020-07-21 Tue>
#+STARTUP: customtime showall
#+SETUPFILE: ~/org/templates/documents/personal.org
#+INCLUDE: ~/org/templates/documents/personal-title.org

#+BEGIN_abstract
GNU Emacs is most often used as a text editor. The utmost level of
customisation is afforded by enabling the user to rewrite /any/ part of
the source code and observe the editor's modified behaviour in real
time. Since its inception in 1984, GNU Emacs has grown to be much more
than a full-featured, high-productivity text editor---new /modes/ have
been written to interact with hundreds of file formats, including
=.txt=, =.pdf=, =.jpg=, =.csv=, and =.zip= just to name a few. This
configuration file itself was written in /Org mode/, a collection of
functions enabling the harmonious mixing of code and comments in view
of publication: this is the endgame of /literate programming/.
#+END_abstract

* Preliminary setup

** Garbage collection

First, we increase the RAM threshold beyond which the garbage collector is
activated.

#+NAME: garbage-collection
#+BEGIN_SRC emacs-lisp
(setq gc-cons-threshold 100000000)
#+END_SRC

** Server start

Makes opening emacs faster for following instances.

#+NAME: server-start
#+BEGIN_SRC emacs-lisp
(server-start)
#+END_SRC

** Custom file

Load settings created automatically by GNU Emacs Custom. (For example, any
clickable option/toggle is saved here.) Useful for fooling around with M-x
customize-group <package>.

#+NAME: custom-file
#+BEGIN_SRC emacs-lisp
(setq custom-file "~/.emacs.d/blendoit/custom/custom-file.el")
(load custom-file)
#+END_SRC

** Customization shortcuts

We begin by defining a user shortcut to this very file:

#+NAME: shortcut-config
#+BEGIN_SRC emacs-lisp
  (defun find-init-blendoit ()
    "Jump to this very file."
     (interactive)
     (find-file "~/.emacs.d/blendoit/init-blendoit.org"))

  (global-set-key (kbd "C-c c") 'find-init-blendoit)
#+END_SRC

Now, different shortcuts for other customization actions:

#+NAME: shortcuts-customization
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-c v") 'customize-variable)
#+END_SRC

** Backups

Backups are so important that they should be described right after the shortcut
to this file.

#+BEGIN_SRC emacs-lisp
  (setq backup-directory-alist `((".*" . ,temporary-file-directory))
  auto-save-file-name-transforms `((".*" ,temporary-file-directory t))
      backup-by-copying t    ; Don't delink hardlinks
      version-control t      ; Use version numbers on backups
      delete-old-versions t  ; Automatically delete excess backups
      kept-new-versions 20   ; how many of the newest versions to keep
      kept-old-versions 5    ; and how many of the old
      )
#+END_SRC

** Secrets

#+INCLUDE: ./secrets.org

#+BEGIN_SRC emacs-lisp
  (setq user-full-name "Marius Peter"
        user-mail-address "blendoit@gmail.com")
#+END_SRC

* Global key bindings

The following bindings strive to further enhance CUA[fn::Common User Access.]
mode.

** Navigation

#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "C-s") 'save-buffer)
  (global-set-key (kbd "C-b") 'ibuffer-sidebar-toggle-sidebar)
  (global-set-key (kbd "C-o") 'menu-find-file-existing)
  (global-set-key (kbd "C-r") 'counsel-recentf)
#+END_SRC

The following bindings lead to more natural exit behaviors.

#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-w") 'kill-buffer-and-window)
(global-set-key (kbd "C-q") 'save-buffers-kill-terminal)
#+END_SRC

** Mouse zoom

 Zoom in/out of selected buffer using Alt + mouse wheel.

#+BEGIN_SRC emacs-lisp
  (global-set-key [M-mouse-4] 'text-scale-increase)
  (global-set-key [M-mouse-5] 'text-scale-decrease)
#+END_SRC

* Packages

List of package archives.

#+NAME: packages
#+BEGIN_SRC emacs-lisp
  (require 'package)
  (add-to-list 'package-archives '("melpa" . "https://melpa.milkbox.net/packages/") t)
  (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
  (package-initialize)
#+END_SRC

#+RESULTS: packages

Ensure =use-package= is installed.

#+BEGIN_SRC emacs-lisp
  (unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package)
  (eval-when-compile (require 'use-package)))
  (setq use-package-always-ensure t)
#+END_SRC

** Org

Phew, I can finally introduce Org mode! I am so *excited*.

Org mode replaces a word processor, a presentation creator, and a spreadsheet
editor. IMHO, the spreadsheet ability captures more than 80% use cases wherein
one wishes to include a table in a text document destined for physical
publication. (It is clear that Excel spreadsheets are /not/ destined for physical
publication---simply attempt to print an Excel spreadsheet with the default
settings.)  In my opinion, Org mode matches all /useful/ features of the
Microsoft Office suite 1-to-1.

What follows are customizations designed to make Org mode behave more like
Microsoft Word. The end goal is, once again, to draw as many new users to Emacs
as possible!

*** Basic customization

First, we hide markup symbols for *bold*, /italic/, _underlined_ and +strikethrough+
text, and ensure our document appears indented upon loading:[fn::It /appears/
indented, but the underlying plaintext file does not contain tab characters!]

#+NAME: org-basic
#+BEGIN_SRC emacs-lisp
  (setq org-hide-emphasis-markers t)
  (setq org-startup-indented t)
#+END_SRC

Then, we customize Org headings to emulate WYSIWYG[fn::What You See Is What You
Get (input and output are identical), as opposed to What You See Is What You
Mean (the input contains instructions that can modify the output).] behavior
normally found in Word:

#+NAME: org-list-bullets
#+BEGIN_SRC emacs-lisp
  (setq org-directory "~/org")
  (font-lock-add-keywords
   'org-mode
   '(("^ *\\([-]\\) "
    (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))
#+END_SRC

- Look at
- This beautifully indented
  - List...
  - Of lists!
- (Rendered with pretty bullets in Emacs)

The following prettifies Org mode heading bullets:

#+NAME: org-headings-bullets
#+BEGIN_SRC emacs-lisp
  (use-package org-bullets
    :hook
    (org-mode . org-bullets-mode)
  )
#+END_SRC



#+NAME: org-cosmetics
#+BEGIN_SRC emacs-lisp

(let* ((variable-tuple
        (cond ((x-list-fonts "Liberation Sans") '(:font "Liberation Sans"))
              ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
              (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro."))))
       (base-font-color     (face-foreground 'default nil 'default))
       (headline           `(:inherit default :weight bold)))

  (custom-theme-set-faces
   'user
   `(org-level-8 ((t (,@headline ,@variable-tuple))))
   `(org-level-7 ((t (,@headline ,@variable-tuple))))
   `(org-level-6 ((t (,@headline ,@variable-tuple))))
   `(org-level-5 ((t (,@headline ,@variable-tuple))))
   `(org-level-4 ((t (,@headline ,@variable-tuple :height 1.1))))
   `(org-level-3 ((t (,@headline ,@variable-tuple :height 1.25))))
   `(org-level-2 ((t (,@headline ,@variable-tuple :height 1.5))))
   `(org-level-1 ((t (,@headline ,@variable-tuple :height 1.75))))
   `(org-document-title ((t (,@headline ,@variable-tuple :height 2.0 :underline nil))))))

;(custom-theme-set-faces
; 'user
; '(variable-pitch ((t (:family "Liberation Sans"))))
; '(fixed-pitch ((t ( :family "Hack")))))

#+END_SRC

*** Agenda

The agenda displays a chronological list of headings across all agenda files
for which the heading or body contain a matching =org-time-stamp=.[fn::An
=org-time-stamp= can be inserted with =C-c .= (period)]

#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-c a") 'org-agenda)
#+END_SRC

*** Publish

In the following /alist/ (association list), we describe the projects publishable
via =org-publish=. We separate the publishing of =.org= files and attachments,
because an online tutorial recommended we do so.

#+BEGIN_SRC emacs-lisp
(require 'ox-publish)
(setq org-publish-project-alist
        '(
          ("Safran-VIP-html"
           :base-directory "~/org/WORK/Safran/programs/B787/VIP/doc/org/"
           :base-extension "org"
           :publishing-directory "~/org/WORK/Safran/programs/B787/VIP/doc/wiki/"
           :recursive t
           :publishing-function org-html-publish-to-html
           :auto-preamble t
           :auto-sitemap t
           :sitemap-title "" )

          ("Safran-VIP-static"
           :base-directory "~/org/WORK/Safran/programs/B787/VIP/doc/org/"
           :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|mp4\\|ogg\\|swf"
           :publishing-directory "~/org/WORK/Safran/programs/B787/VIP/doc/wiki/"
           :recursive t
           :publishing-function org-publish-attachment )

          ("Safran-VIP-all"
           :components ("Safran-VIP-html" "Safran-VIP-static"))

          ("Safran-MA700-html"
           :base-directory "~/org/WORK/Safran/programs/MA700/doc/org/"
           :base-extension "org"
           :publishing-directory "~/org/WORK/Safran/programs/MA700/doc/wiki/"
           :recursive t
           :publishing-function org-html-publish-to-html
           :auto-preamble t
           :auto-sitemap t
           :sitemap-title "" )

          ("Safran-MA700-static"
           :base-directory "~/org/WORK/Safran/programs/MA700/doc/org/"
           :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|mp4\\|ogg\\|swf"
           :publishing-directory "~/org/WORK/Safran/programs/MA700/doc/wiki/"
           :recursive t
           :publishing-function org-publish-attachment )

          ("Safran-MA700-all"
           :components ("Safran-MA700-html" "Safran-MA700-static"))))

  (add-to-list 'org-latex-packages-alist '("table" "xcolor"
                                           t ("pdflatex")))
  (add-to-list 'org-latex-packages-alist '("AUTO" "babel"
                                           t ("pdflatex")))
  (add-to-list 'org-latex-packages-alist '("AUTO" "polyglossia"
                                           t ("xelatex" "lualatex")))
#+END_SRC

*** Export

This creates a shorter binding for the most common Org export: Org \rightarrow
LaTeX \rightarrow PDF.

#+BEGIN_SRC emacs-lisp
(defun blendoit-org-quick-export ()
  "Org export to PDF and open.
  This basically reimplements `C-c C-e l o'."
  (interactive)
    (org-latex-export-to-pdf)
    (org-open-file
      (concat (substring buffer-file-truename 0 -3) "pdf")))

(global-set-key (kbd "C-c e") 'blendoit-org-quick-export)
#+END_SRC

** =gnuplot=

#+BEGIN_SRC emacs-lisp
(use-package gnuplot)
#+END_SRC

** =company=

# #+BEGIN_SRC emacs-lisp
# (use-package company)
# #+END_SRC

** Ledger

#+BEGIN_SRC emacs-lisp
  (use-package ledger-mode
    :bind
     ("C-c r" . ledger-report)
     ("C-c C" . ledger-mode-clean-buffer))
#+END_SRC

** TODO ibuffer-sidebar
SCHEDULED: <2020-07-21 Tue>

#+BEGIN_SRC emacs-lisp
;    (use-package ibuffer-sidebar
;     :bind ("mouse-1" . ibuffer-mouse-visit-buffer)
;     :bind ("mouse-3" . ibuffer-mouse-toggle-mark))

;     (add-hook 'ibuffer-sidebar-mode-hook
;       (lambda ()
;        (local-unset-key (quote mouse-1))
;        (local-unset-key (quote mouse-2))
;        (local-set-key (quote mouse-1) (quote ibuffer-mouse-visit-buffer))
;        (local-set-key (quote mouse-2) (quote ibuffer-mouse-toggle-mark))))
#+END_SRC

** Which-key

#+BEGIN_SRC emacs-lisp
(use-package which-key
:init
 (which-key-mode)
;; :config
;;  (setq which-key-idle-delay 1000)
;;  (setq which-key-idle-secondary-delay 0.05)
;;  (setq which-key-show-early-on-C-h t)
)
#+END_SRC

** Ivy

Auto completion.

#+BEGIN_SRC emacs-lisp
(use-package ivy
 :config
  (ivy-mode t)
  (setq ivy-use-virtual-buffers t
   ivy-count-format "%d/%d "
   enable-recursive-minibuffers t))

  (use-package ivy-hydra)
#+END_SRC

*** Counsel

  Wonderful counsellor!

#+BEGIN_SRC emacs-lisp
(use-package counsel
 :bind ("M-x" . counsel-M-x)
 :config (counsel-mode))

(global-set-key (kbd "C-f") 'counsel-grep-or-swiper)
#+END_SRC

*** Swiper

#+BEGIN_SRC emacs-lisp
(use-package swiper
 :bind (("C-f" . counsel-grep-or-swiper)))
#+END_SRC

** Ido

# #+BEGIN_SRC emacs-lisp
#   (setq ido-enable-flex-matching t)
#   (setq ido-everywhere t)
#   (ido-mode 1)
# #+END_SRC

** Company

#+NAME: company
#+BEGIN_SRC emacs-lisp
;; (use-package company
;;  :config (add-hook 'after-init-hook 'global-company-mode))
#+END_SRC

** Flycheck

#+NAME: flycheck
#+BEGIN_SRC emacs-lisp
(use-package flycheck
 :init (global-flycheck-mode))
#+END_SRC

** Magit

#+BEGIN_SRC emacs-lisp
  (use-package magit
   :bind ("C-c g" . magit-status))
#+END_SRC

** PDF-tools

#+BEGIN_SRC emacs-lisp
(use-package pdf-tools
 :config (pdf-loader-install))
#+END_SRC

* Cosmetics

** Faces & cursors

In order to imitate other modern text editors, we'll resort to a blinking bar
cursor.

*** Default cursor

#+BEGIN_SRC emacs-lisp
(setq-default cursor-type (quote bar))
#+END_SRC

*** Mixed pitch in Org mode

Fixed-pitch and variable-pitch fonts will be used intelligently in all hooked
modes.

#+BEGIN_SRC emacs-lisp
  (use-package mixed-pitch
    :hook ((org-mode
            info-mode) . mixed-pitch-mode))
#+END_SRC

** All the icons

#+BEGIN_SRC emacs-lisp
(use-package all-the-icons)
#+END_SRC

** Theme

#+BEGIN_SRC emacs-lisp
;;  (use-package zenburn-theme
;;   :config
;;    (load-theme 'zenburn))

(load-theme 'wombat)
#+END_SRC

** Transparency

#+BEGIN_SRC emacs-lisp
(add-to-list 'default-frame-alist '(alpha . (90 . 50)))
#+END_SRC

** Scrollbars

#+BEGIN_SRC emacs-lisp
(set-window-scroll-bars (minibuffer-window) nil nil)
#+END_SRC

* Editing preferences

These customizations enhance editor usability.

#+BEGIN_SRC emacs-lisp
(setq-default fill-column 79)
(defalias 'yes-or-no-p 'y-or-n-p)
#+END_SRC

** Initial & subsequent frame size

# #+BEGIN_SRC emacs-lisp
# (add-to-list 'initial-frame-alist '((width . 79) (height . 60)))
# (add-to-list 'default-frame-alist '((width . 60) (height . 20)))
# #+END_SRC

** Better parentheses

#+BEGIN_SRC emacs-lisp
  (use-package smartparens
    :config
    (add-hook 'prog-mode-hook 'smartparens-mode))

  (use-package rainbow-delimiters
    :config
    (add-hook 'prog-mode-hook 'rainbow-delimiters-mode))
#+END_SRC
Copyright 2019--2024 Marius PETER