-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinit-compat.el
92 lines (90 loc) · 3.72 KB
/
init-compat.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
(when (version< emacs-version "26.0")
(defvar definition-prefixes (make-hash-table :test 'equal))
(defun register-definition-prefixes (file prefixes)
"Register that FILE uses PREFIXES."
(dolist (prefix prefixes)
(puthash prefix (cons file (gethash prefix definition-prefixes))
definition-prefixes))))
(when (version< emacs-version "27.0")
(defmacro if-let* (varlist then &rest else)
(declare (indent 2)
(debug ((&rest [&or symbolp (symbolp form) (form)])
body)))
(if varlist
`(let* ,(setq varlist (internal--build-bindings varlist))
(if ,(caar (last varlist))
,then
,@else))
`(let* () ,then)))
(defun internal--build-binding (binding prev-var)
"Check and build a single BINDING with PREV-VAR."
(setq binding
(cond
((symbolp binding)
(list binding binding))
((null (cdr binding))
(list (make-symbol "s") (car binding)))
(t binding)))
(when (> (length binding) 2)
(signal 'error
(cons "`let' bindings can have only one value-form" binding)))
(let ((var (car binding)))
`(,var (and ,prev-var ,(cadr binding)))))
(defun internal--build-bindings (bindings)
"Check and build conditional value forms for BINDINGS."
(let ((prev-var t))
(mapcar (lambda (binding)
(let ((binding (internal--build-binding binding prev-var)))
(setq prev-var (car binding))
binding))
bindings)))
(defmacro if-let* (varlist then &rest else)
(declare (indent 2)
(debug ((&rest [&or symbolp (symbolp form) (form)])
body)))
(if varlist
`(let* ,(setq varlist (internal--build-bindings varlist))
(if ,(caar (last varlist))
,then
,@else))
`(let* () ,then)))
(defmacro if-let (spec then &rest else)
(declare (indent 2)
(debug ([&or (symbolp form) ; must be first, Bug#48489
(&rest [&or symbolp (symbolp form) (form)])]
body)))
(when (and (<= (length spec) 2)
(not (listp (car spec))))
;; Adjust the single binding case
(setq spec (list spec)))
(list 'if-let* spec then (macroexp-progn else)))
(defmacro when-let (spec &rest body)
(declare (indent 1) (debug if-let))
(list 'if-let spec (macroexp-progn body))))
(when (version< emacs-version "29.0")
;; define-obsolete-variable-alias の上書き補正
(defmacro define-obsolete-variable-alias (obsolete-name
current-name
&optional when docstring)
""
(declare (doc-string 4)
(advertised-calling-convention
(obsolete-name current-name when &optional docstring) "23.1"))
`(progn
(defvaralias ,obsolete-name ,current-name ,docstring)
(dolist (prop '(saved-value saved-variable-comment))
(and (get ,obsolete-name prop)
(null (get ,current-name prop))
(put ,current-name prop (get ,obsolete-name prop))))
(make-obsolete-variable ,obsolete-name ,current-name ,when)))
;; define-obsolete-function-alias の上書き補正
(defmacro define-obsolete-function-alias (obsolete-name
current-name
&optional when docstring)
""
(declare (doc-string 4)
(advertised-calling-convention
(obsolete-name current-name when &optional docstring) "23.1"))
`(progn
(defalias ,obsolete-name ,current-name ,docstring)
(make-obsolete ,obsolete-name ,current-name ,when))))