-
Notifications
You must be signed in to change notification settings - Fork 54
/
combobulate-toml.el
122 lines (108 loc) · 4.44 KB
/
combobulate-toml.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;;; combobulate-toml.el --- TOML mode support for Combobulate -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Mickey Petersen
;; Author: Mickey Petersen <[email protected]>
;; Keywords:
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'combobulate-settings)
(require 'combobulate-navigation)
(require 'combobulate-manipulation)
(require 'combobulate-interface)
(require 'combobulate-rules)
(defun combobulate-toml-pretty-print-node-name (node default-name)
"Pretty print the name of NODE."
(combobulate-string-truncate
(pcase (combobulate-node-type node)
("table" (concat "[" (combobulate-node-text (combobulate-node-child node 0)) "]"))
("table_array_element" (concat "[[" (combobulate-node-text (combobulate-node-child node 0)) "]]"))
("pair" (concat
(combobulate-node-text (combobulate-node-child node 0))))
("string" (concat (combobulate-node-text node)))
;; ("bare_key" (concat (combobulate-node-text (combobulate-node-next-sibling node))))
(_ default-name))
40))
(eval-and-compile
(defvar combobulate-toml-definitions
'((context-nodes '("string" "float" "integer"))
(envelope-list nil)
(pretty-print-node-name-function #'combobulate-toml-pretty-print-node-name)
(highlight-queries-default nil)
(procedures-edit
`((:activation-nodes
((:nodes
("bare_key" "dotted_key")
:has-ancestor ((irule "pair"))))
:selector (:choose
parent
:match-query
(:query (_ (pair (_) @match)+) :engine combobulate)))
;; edit the value field of a pair
(:activation-nodes
((:nodes
((exclude (rule "pair") "bare_key" "dotted_key"))
:has-ancestor ((irule "pair"))))
:selector (:choose
parent
:match-query
(:query (_ (pair (_) (_) @match)+) :engine combobulate)))))
(procedures-sexp
'((:activation-nodes ((:nodes ("table"))))))
(procedures-defun '((:activation-nodes ((:nodes ("table" "table_array_element"))))))
(procedures-sibling
'(;; array navigation
(:activation-nodes
((:nodes
((rule "array"))
:position at
:has-parent ((rule "array"))))
:selector (:match-children t))
;; table navigation
(:activation-nodes
((:nodes
((rule "document"))
:position at
:has-parent ("document")))
:selector (:match-children t))
;; pair-wise navigation (key side)
(:activation-nodes
((:nodes ("pair") :position at :has-parent ("table" "table_array_element")))
:selector (:match-children (:match-rules ("pair"))))
(:activation-nodes
((:nodes
((rule "pair"))
:has-fields "value"
:has-ancestor ((irule "pair"))))
:selector (:choose
parent
:match-query
(:query (object (pair (_) (_) @match)+) :engine combobulate)))))
(procedures-hierarchy
'(;; in and out of tables
(:activation-nodes
((:nodes ("table" "table_array_element") :position at))
:selector (:choose node :match-children (:match-rules (exclude (all) "bare_key"))))
;; general navigation
(:activation-nodes
((:nodes (exclude (all) "string") :position at))
:selector (:choose node :match-children t))))
(procedures-logical '((:activation-nodes ((:nodes (all)))))))))
(define-combobulate-language
:name toml
:language toml
:major-modes (toml-ts-mode toml-mode)
:custom combobulate-toml-definitions
:setup-fn combobulate-toml-setup)
(defun combobulate-toml-setup (_))
(provide 'combobulate-toml)
;;; combobulate-toml.el ends here