summaryrefslogtreecommitdiff
path: root/emacs/inits/23-text-related.el
blob: 75eb8693684db13e83470337b67e3fbbc8a0ab39 (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
;; Time-stamp: <2020-04-13 14:36:53 (tslil@bison)>

;; -----------------------------------------------------------------------------
;; Spelling

(use-package spell-fu
  :ensure t
  :config
  (setq ispell-dictionary "british"
        ispell-personal-dictionary "~/.aspell.en.pws")

  ;; The default was this "\\b\\([[:alpha:]][[:alpha:]']*\\)\\b", but that
  ;; didn't play well with ``LaTeX's quoting system''.
  (setq-default spell-fu-word-regexp "\\([[:alpha:]]+\\('[[:alpha:]]\\)*\\)"))

(setq sentence-end-double-space nil)

(add-hook 'mail-mode-hook (lambda ()
                            (electric-pair-local-mode 1)
                            (turn-on-auto-fill)
                            (spell-fu-mode 1)
                            (company-mode 1)))

(add-hook 'text-mode-hook (lambda ()
                            ;; (set-input-method "Adga")
                            (subword-mode 1)
                            (electric-pair-local-mode 1)
                            (turn-on-auto-fill)
                            (siege-mode 1)
                            (spell-fu-mode 1)
                            ))

(use-package dictionary :ensure t :defer t)

;; -----------------------------------------------------------------------------
;; Org

(use-package org
  :defer t
  :bind (:map org-mode-map
              ("M-h" . nil))
  ;; :hook (org-mode . (lambda ()
  ;;                     (activate-input-method default-input-method)))
  :config
  (setq org-use-sub-superscripts (quote {})
        org-modules nil))


;; -----------------------------------------------------------------------------
;; Deft

(use-package deft
  :ensure t
  :defer t
  :commands (deft)
  :bind (("C-z" . deft-take-note)
         ("C-c C-z" . deft))
  :config
  (setq deft-default-extension "org"
        deft-directory "~/store/notes"
        deft-use-filename-as-title nil
        deft-use-filter-string-for-filename t
        deft-file-naming-rules '((noslash . "_")
                                 (nospace . "_")
                                 (case-fn . downcase))
        deft-org-mode-title-prefix t)

  (defvar deft-take-note-pre-grab
    '((region-thing . (let ((r (if (region-active-p)
                                   (buffer-substring (region-beginning) (region-end))
                                 (thing-at-point 'line))))
                        (if r (concat r "\n") "")))
      (bfn . (let ((f (buffer-file-name))
                   (b (buffer-name))) (if f f (concat b " (no file associated)")))))
    "List of pairs of symbol names and (functions evaluating to)
  strings evaluated before the buffer is created, and made
  available for deft-take-note-default-contents.")

  (defvar deft-take-note-post-grab '()
    "List of pairs of symbol names and (functions evaluating to)
  strings evaluated after the buffer is created, and made
  available for deft-take-note-default-contents.")

  (defvar deft-take-note-default-contents '(region-thing bfn "\n")
    "List with string literals and symbols defined in the pre and
  post grab lists to be inserted into the buffer.")

  (defun deft-take-note ()
    (interactive)
    (let ((pre-alist (mapcar #'(lambda (elt) `(,(car elt) . ,(eval (cdr elt))))
                             deft-take-note-pre-grab)))
      (let ((bn (concat (format-time-string "%Y%m%d-%H:%M:%S.%N-%Z") "."
                        deft-default-extension)))
        (switch-to-buffer bn)
        (set-visited-file-name (expand-file-name
                                (concat deft-directory "/" bn)))
        (let ((complete-alist
               (append pre-alist
                       (mapcar #'(lambda (elt) `(,(car elt) . ,(eval (cdr elt))))
                               deft-take-note-post-grab))))
          (mapc #'(lambda (elt) (if (eq (type-of elt) 'string)
                                    (insert elt)
                                  (insert (cdr (assoc elt complete-alist)))))
                deft-take-note-default-contents))))))

;; -----------------------------------------------------------------------------
;; Useful keybinds

(defun vi-open-line-above ()
  "Insert a newline above the current line and put point at beginning."
  (interactive)
  (unless (bolp)
    (beginning-of-line))
  (newline)
  (forward-line -1)
  (indent-according-to-mode))

(defun vi-open-line-below ()
  "Insert a newline below the current line and put point at beginning."
  (interactive)
  (unless (eolp)
    (end-of-line))
  (newline-and-indent))

(global-set-key (kbd "M-o") 'vi-open-line-below)
(global-set-key (kbd "C-o") 'vi-open-line-above)

(global-set-key (kbd "M-C-+") 'text-scale-increase)
(global-set-key (kbd "M-C--") 'text-scale-decrease)