aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/init/oni-align.el
blob: 8e63d27ef91659288dd3640affbf3e408888dedb (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
;;; oni-align.el --- Alignment configuration         -*- lexical-binding: t; -*-

;; Copyright (C) 2018  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local

;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Configuration for several alignment options.

;;; Code:

(require 'align)

;; Align CSS files like so:

;;   body        { color: #ffffff;            }
;;   .some-class { background-color: #ffffff; }
;;   #some-id    { width: 200px;              }

;;   .some-more-class {
;;       color:            #ffffff;
;;       background-color: #ffffff;
;;       width:            200px;
;;   }

;; Keep these in order. They are each added to the _front_ of the
;; list and are applied in order. Changing their order will change
;; the results.
(add-to-list 'align-rules-list
             `(css-closing-brace
               (regexp . ,(rx (group (0+ whitespace)) "}" eol))
               (group . (1))
               (modes . '(scss-mode css-mode))))

(add-to-list 'align-rules-list
             `(css-colons
               (regexp . ,(rx bol
                              (0+ whitespace)
                              (1+ (any (?a . ?z) ?- ?$))
                              ":"
                              (group (0+ whitespace))
                              (0+ nonl)
                              ";"
                              eol))
               (group . (1))
               (modes . '(scss-mode css-mode))
               (repeat . t)))

(add-to-list 'align-rules-list
             `(css-opening-brace
               (regexp . ,(rx bol
                              (0+ whitespace)
                              (0+ (any ?# ?. ?, ?\s ?& ?: ?-
                                       (?a . ?z) (?A . ?Z) (?0 . ?9)))
                              (any (?a . ?z) (?A . ?Z) (?0 . ?9))
                              (group (0+ whitespace))
                              "{"
                              (0+ nonl)))
               (group . (1))
               (modes . '(scss-mode css-mode))))

(provide 'oni-align)
;;; oni-align.el ends here