forked from SystemCrafters/crafted-emacs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
crafted-editing.el
98 lines (79 loc) · 3.03 KB
/
crafted-editing.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
;;; crafted-editing.el -*- lexical-binding: t; -*-
;; Copyright (C) 2022
;; SPDX-License-Identifier: MIT
;; Author: System Crafters Community
;; Commentary
;; Editing text configuration.
;;; Code:
;;; Helpers for defcustom variables
(defun crafted-editing--prefer-tabs (enable)
"Adjust whitespace configuration to support tabs based on ENABLE."
(if enable
(customize-set-variable 'whitespace-style
'(face empty trailing indentation::tab
space-after-tab::tab
space-before-tab::tab))
(customize-set-variable 'whitespace-style
'(face empty trailing tab-mark
indentation::space))))
(defun crafted-editing--enable-whitespace-modes (modes)
"Enable whitespace-mode for each mode specified by MODES."
(dolist (mode modes)
(add-hook (intern (format "%s-hook" mode))
#'whitespace-mode)))
(defun crafted-editing--disable-whitespace-modes (modes)
"Do not enable whitespace-mode for each mode specified by MODES."
(dolist (mode modes)
(remove-hook (intern (format "%s-hook" mode))
#'whitespace-mode)))
;;; Customization group for the Crafted Editing module.
(defgroup crafted-editing '()
"Editing related configuration for Crafted Emacs."
:tag "Crafted Editing"
:group 'crafted)
(define-obsolete-variable-alias
'rational-editing-prefer-tabs
'crafted-editing-prefer-tabs
"1")
;; provide an option for users who prefer tabs over spaces
(defcustom crafted-editing-prefer-tabs nil
"Prefer using tabs instead of spaces."
:tag "Prefer tabs over spaces"
:group 'crafted-editing
:set (lambda (sym val)
(set-default sym val)
(crafted-editing--prefer-tabs val)))
(define-obsolete-variable-alias
'rational-editing-whitespace-cleanup-enabled-modes
'crafted-editing-whitespace-cleanup-enabled-modes
"1")
;; whitespace cleanup configuration
(defcustom crafted-editing-whitespace-cleanup-enabled-modes
'(conf-mode prog-mode)
"Modes which should have whitespace cleanup enabled."
:type 'list
:tag "Whitespace cleanup enabled modes"
:group 'crafted-editing
:set (lambda (sym val)
(set-default sym val)
(crafted-editing--enable-whitespace-modes val)))
(define-obsolete-variable-alias
'rational-editing-whitespace-cleanup-disabled-modes
'crafted-editing-whitespace-cleanup-disabled-modes
"1")
(defcustom crafted-editing-whitespace-cleanup-disabled-modes
'(makefile-mode)
"Modes which should not have whitespace cleanup enabled."
:type 'list
:tag "Whitespace cleanup disabled modes"
:group 'crafted-editing
:set (lambda (sym val)
(set-default sym val)
(crafted-editing--disable-whitespace-modes val)))
;;; cleanup whitespace
(customize-set-variable 'whitespace-action '(cleanup auto-cleanup))
;;; parentheses
(electric-pair-mode 1) ; auto-insert matching bracket
(show-paren-mode 1) ; turn on paren match highlighting
(provide 'crafted-editing)
;;; crafted-editing.el ends here