-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mic-definputter.el
102 lines (88 loc) · 3.29 KB
/
mic-definputter.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
;;; mic-definputter.el --- Inputter for `mic' -*- lexical-binding: t; -*-
;; Copyright (C) 2023 by ROCKTAKEY
;; 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:
;; Inputter for `mic'
;;; Code:
(require 'mic-utils)
(defmacro mic-definputter-pseudo-plist (name listized-keywords &optional docstring)
"Define an inputter, named NAME and documented by DOCSTRING, for `mic-defmic'.
Here is description for an inputter defined by this.
---
Any keywords in LISTIZED-KEYWORDS are allowed to put muptiple value,
whereas the other keywords are not allowed.
For example, when LISTIZED-KEYWORDS is (:a :b), lists below are allowed:
(:a 1
:b 4 5 6
:c 7)
(:a 1 2
:c 7)
(:a 1
:b 2 4
:a 5
:c 9)
but lists below are not allowed:
(:a 1 2
:c 3 4) ; Because :c is not allowed to be multiple.
(:a 1
:c 2
:b 4
:c 4) ; Because :c is not allowed to be multiple.
This function returns plist whose value on keyword in LISTIZED-KEYWORDS is
put together into one list.
For example, when LISTIZED-KEYWORDS is (:a :b),
lists below are transformed like:
(:a 1
:b 4 5 6
:c 7)
;; =>
(:a (1)
:b (4 5 6)
:c 7)"
(declare (indent defun))
(let ((listized-keywords (eval listized-keywords)))
`(defun ,name (pseudo-plist)
,(or docstring
(format "Inputter for `mic'.
It takes one argument PSEUDO-PLIST and return normalized plist.
Keywords listed below are allowed to put muptiple value,
whereas the other keywords are not allowed:
%s
For more information, see `mic-definputter-pseudo-plist'."
(mapconcat
(lambda (arg)
(concat "- `" (pp-to-string arg) "'"))
listized-keywords
"\n")))
(let (redundant-plist)
(let (key)
(while pseudo-plist
(let ((now (pop pseudo-plist)))
(if (keywordp now)
(setq key now)
(mic-plist-put-append redundant-plist key (list now))))))
(let (normalized-plist)
(while redundant-plist
(let ((key (pop redundant-plist))
(value (pop redundant-plist)))
(mic-plist-put normalized-plist key
(if (seq-some
(apply-partially #'eq key)
',listized-keywords)
value
(when (cdr value)
(error "`%s': keyword `%s' is not allowed to be passed multiple times"
',name key))
(car value)))))
normalized-plist)))))
(provide 'mic-definputter)
;;; mic-definputter.el ends here