summaryrefslogtreecommitdiff
path: root/modules/text-config.el
blob: 730e36a30c711dc3a759e1379c2530e3b843a811 (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
;;; text-config --- Text Settings and Functionality -*- lexical-binding: t; coding: utf-8; -*-
;; author Craig Jennings <c@cjennings.net>

;;; Commentary:
;;
;; Configuration for text editing features including:
;; - Basic text mode settings (visual line mode, indentation, spacing)
;; - Text manipulation (move-text, expand-region, change-inner)
;; - Selection behavior (delete-selection-mode)
;; - Editing tools (edit-indirect, olivetti, accent)
;; - Visual enhancements (prettify-symbols, visual-fill-column)

;;; Code:

;; ------------------------------- Text Settings -------------------------------

;; Global text settings
(setopt indent-tabs-mode nil)         ;; indentation should not insert tabs
(setopt require-final-newline nil)    ;; don't require newlines at the end of files
(setopt sentence-end-double-space nil) ;; in the 21st century, sentences end w/ a single space

(defun cj/text-mode-settings ()
  "Personal settings for `text-mode'."
  (turn-on-visual-line-mode))        ;; wrap text in text modes
(add-hook 'text-mode-hook #'cj/text-mode-settings)

;; --------------------------------- Move Text ---------------------------------
;; move the current line or selected region up or down in the buffer

(use-package move-text
  :bind
  (("C-<up>" . move-text-up)
   ("C-<down>" . move-text-down)))

;; ------------------------------- Expand Region -------------------------------
;; increase the region by semantic units

(use-package expand-region
  :bind
  (("M-=" . er/expand-region)
   ("C->" . er/expand-region)
   ("M--" . er/contract-region)
   ("C-<" . er/contract-region)))

;; ---------------------------- Change Inner / Outer ---------------------------
;; change inner and outer, just like in vim.

(use-package change-inner
  :bind (("C-c i" . change-inner)
         ("C-c o" . change-outer)))

;; ------------------------------ Delete Selection -----------------------------
;; delete the region on character insertion

(use-package delsel
  :ensure nil ;; built-in
  :config
  (delete-selection-mode t))

;; ------------------------------- Edit Indirect -------------------------------
;; edit selection in new buffer, C-c to finish; replaces with modifications

(use-package edit-indirect
  :bind ("M-I" . edit-indirect-region))

;; ------------------------------ Prettify Symbols -----------------------------
;; replacing the word l-a-m-b-d-a with a symbol, just because

(defun cj/case-insensitive-symbol-pair (pair)
  "Convert a symbol PAIR to both lowercase and uppercase variants.
PAIR is a cons cell of (string . symbol)."
  (let ((k (car pair))
        (v (cdr pair)))
    (list (cons (downcase k) v)
          (cons (upcase k) v))))

(setopt prettify-symbols-alist
        (apply #'append
               (mapcar #'cj/case-insensitive-symbol-pair
                       '(("#+begin_src" . "λ")
                         ("#+end_src" . "λ")
                         ("lambda" . "λ")))))

(add-hook 'prog-mode-hook #'turn-on-prettify-symbols-mode)
(add-hook 'org-mode-hook #'turn-on-prettify-symbols-mode)

;; ---------------------------------- Olivetti ---------------------------------
;; center text in the middle of the screen.

(use-package olivetti
  :commands olivetti-mode
  :config
  (setopt olivetti-body-width 100))  ;; 100 characters wide (comfortable reading width)

;; --------------------------- Accent (Diacriticals) ---------------------------
;; an easy way to enter diacritical marks

(use-package accent
  :commands accent-company
  :bind ("C-`" . accent-company))

(provide 'text-config)
;;; text-config.el ends here