Mercurial > emacs
annotate lisp/emacs-lisp/backquote.el @ 99975:dddfb4772d33
(hash_get_category_set): New function.
(Fmodify_category_entry): Adjusted for the change of
char_table_ref_and_range. Call hash_get_category_set to get a
category set to store in the table.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 27 Nov 2008 07:59:21 +0000 |
parents | 90a2847062be |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
15261 | 1 ;;; backquote.el --- implement the ` Lisp construct |
14169 | 2 |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1990, 1992, 1994, 2001, 2002, 2003, 2004, |
79704 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
845 | 5 |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
6 ;; Author: Rick Sladkey <jrs@world.std.com> |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
7 ;; Maintainer: FSF |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
8 ;; Keywords: extensions, internal |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
9 |
13337 | 10 ;; This file is part of GNU Emacs. |
181 | 11 |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92948
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
181 | 13 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92948
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92948
diff
changeset
|
15 ;; (at your option) any later version. |
181 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
92948
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
181 | 24 |
13337 | 25 ;;; Commentary: |
181 | 26 |
48172 | 27 ;; When the Lisp reader sees `(...), it generates (\` (...)). |
28 ;; When it sees ,... inside such a backquote form, it generates (\, ...). | |
29 ;; For ,@... it generates (\,@ ...). | |
30 | |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
31 ;; This backquote will generate calls to the backquote-list* form. |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
32 ;; Both a function version and a macro version are included. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
33 ;; The macro version is used by default because it is faster |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
34 ;; and needs no run-time support. It should really be a subr. |
181 | 35 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
36 ;;; Code: |
181 | 37 |
584 | 38 (provide 'backquote) |
39 | |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
40 ;; function and macro versions of backquote-list* |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
41 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
42 (defun backquote-list*-function (first &rest list) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
43 "Like `list' but the last argument is the tail of the new list. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
44 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
45 For example (backquote-list* 'a 'b 'c) => (a b . c)" |
54494
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
46 ;; The recursive solution is much nicer: |
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
47 ;; (if list (cons first (apply 'backquote-list*-function list)) first)) |
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
48 ;; but Emacs is not very good at efficiently processing recursion. |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
49 (if list |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
50 (let* ((rest list) (newlist (cons first nil)) (last newlist)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
51 (while (cdr rest) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
52 (setcdr last (cons (car rest) nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
53 (setq last (cdr last) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
54 rest (cdr rest))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
55 (setcdr last (car rest)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
56 newlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
57 first)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
58 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
59 (defmacro backquote-list*-macro (first &rest list) |
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
60 "Like `list' but the last argument is the tail of the new list. |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
61 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
62 For example (backquote-list* 'a 'b 'c) => (a b . c)" |
54494
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
63 ;; The recursive solution is much nicer: |
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
64 ;; (if list (list 'cons first (cons 'backquote-list*-macro list)) first)) |
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
65 ;; but Emacs is not very good at efficiently processing such things. |
3c18d4160cc6
(backquote-list*-macro): Use nreverse.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
66 (setq list (nreverse (cons first list)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
67 first (car list) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
68 list (cdr list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
69 (if list |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
70 (let* ((second (car list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
71 (rest (cdr list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
72 (newlist (list 'cons second first))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
73 (while rest |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
74 (setq newlist (list 'cons (car rest) newlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
75 rest (cdr rest))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
76 newlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
77 first)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
78 |
7369
cc6d237a7c7e
(backquote-backquote-symbol): Don't autoload defvar.
Richard M. Stallman <rms@gnu.org>
parents:
7299
diff
changeset
|
79 (defalias 'backquote-list* (symbol-function 'backquote-list*-macro)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
80 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
81 ;; A few advertised variables that control which symbols are used |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
82 ;; to represent the backquote, unquote, and splice operations. |
27243
069b39c07c8d
Remove inappropriate customization (allowing custom.el to use
Dave Love <fx@gnu.org>
parents:
21365
diff
changeset
|
83 (defconst backquote-backquote-symbol '\` |
39085
97bb42866d17
(backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
84 "Symbol used to represent a backquote or nested backquote.") |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
85 |
78638
a5611e4218bf
(backquote-unquote-symbol, backquote-splice-symbol):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78603
diff
changeset
|
86 (defconst backquote-unquote-symbol '\, |
39085
97bb42866d17
(backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
87 "Symbol used to represent an unquote inside a backquote.") |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
88 |
78638
a5611e4218bf
(backquote-unquote-symbol, backquote-splice-symbol):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78603
diff
changeset
|
89 (defconst backquote-splice-symbol '\,@ |
39085
97bb42866d17
(backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents:
38412
diff
changeset
|
90 "Symbol used to represent a splice inside a backquote.") |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
91 |
86169
fb6683560bac
(backquote): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
78638
diff
changeset
|
92 (defmacro backquote (structure) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
93 "Argument STRUCTURE describes a template to build. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
94 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
95 The whole structure acts as if it were quoted except for certain |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
96 places where expressions are evaluated and inserted or spliced in. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
97 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
98 For example: |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
99 |
11687
14c5ed91e3d0
('\`): Use backslash for reading the backquote.
Richard M. Stallman <rms@gnu.org>
parents:
8209
diff
changeset
|
100 b => (ba bb bc) ; assume b has this value |
14c5ed91e3d0
('\`): Use backslash for reading the backquote.
Richard M. Stallman <rms@gnu.org>
parents:
8209
diff
changeset
|
101 `(a b c) => (a b c) ; backquote acts like quote |
12606 | 102 `(a ,b c) => (a (ba bb bc) c) ; insert the value of b |
103 `(a ,@b c) => (a ba bb bc c) ; splice in the value of b | |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
104 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
105 Vectors work just like lists. Nested backquotes are permitted." |
86169
fb6683560bac
(backquote): Improve argument/docstring consistency.
Juanma Barranquero <lekktu@gmail.com>
parents:
78638
diff
changeset
|
106 (cdr (backquote-process structure))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
107 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
108 ;; GNU Emacs has no reader macros |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
109 |
11687
14c5ed91e3d0
('\`): Use backslash for reading the backquote.
Richard M. Stallman <rms@gnu.org>
parents:
8209
diff
changeset
|
110 (defalias '\` (symbol-function 'backquote)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
111 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
112 ;; backquote-process returns a dotted-pair of a tag (0, 1, or 2) and |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
113 ;; the backquote-processed structure. 0 => the structure is |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
114 ;; constant, 1 => to be unquoted, 2 => to be spliced in. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
115 ;; The top-level backquote macro just discards the tag. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
116 |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
117 (defun backquote-delay-process (s level) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
118 "Process a (un|back|splice)quote inside a backquote. |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
119 This simply recurses through the body." |
78603
eb7052b9d8b1
(backquote-delay-process): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78522
diff
changeset
|
120 (let ((exp (backquote-listify (list (cons 0 (list 'quote (car s)))) |
eb7052b9d8b1
(backquote-delay-process): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78522
diff
changeset
|
121 (backquote-process (cdr s) level)))) |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
122 (if (eq (car-safe exp) 'quote) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
123 (cons 0 (list 'quote s)) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
124 (cons 1 exp)))) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
125 |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
126 (defun backquote-process (s &optional level) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
127 "Process the body of a backquote. |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
128 S is the body. Returns a cons cell whose cdr is piece of code which |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
129 is the macro-expansion of S, and whose car is a small integer whose value |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
130 can either indicate that the code is constant (0), or not (1), or returns |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
131 a list which should be spliced into its environment (2). |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
132 LEVEL is only used internally and indicates the nesting level: |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
133 0 (the default) is for the toplevel nested inside a single backquote." |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
134 (unless level (setq level 0)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
135 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
136 ((vectorp s) |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
137 (let ((n (backquote-process (append s ()) level))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
138 (if (= (car n) 0) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
139 (cons 0 s) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
140 (cons 1 (cond |
38028
a5aad5623acc
(backquote-process): Handle `[,@SYMBOL].
Richard M. Stallman <rms@gnu.org>
parents:
27243
diff
changeset
|
141 ((not (listp (cdr n))) |
a5aad5623acc
(backquote-process): Handle `[,@SYMBOL].
Richard M. Stallman <rms@gnu.org>
parents:
27243
diff
changeset
|
142 (list 'vconcat (cdr n))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
143 ((eq (nth 1 n) 'list) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
144 (cons 'vector (nthcdr 2 n))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
145 ((eq (nth 1 n) 'append) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
146 (cons 'vconcat (nthcdr 2 n))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
147 (t |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
148 (list 'apply '(function vector) (cdr n)))))))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
149 ((atom s) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
150 (cons 0 (if (or (null s) (eq s t) (not (symbolp s))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
151 s |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
152 (list 'quote s)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
153 ((eq (car s) backquote-unquote-symbol) |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
154 (if (<= level 0) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
155 (cons 1 (nth 1 s)) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
156 (backquote-delay-process s (1- level)))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
157 ((eq (car s) backquote-splice-symbol) |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
158 (if (<= level 0) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
159 (cons 2 (nth 1 s)) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
160 (backquote-delay-process s (1- level)))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
161 ((eq (car s) backquote-backquote-symbol) |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
162 (backquote-delay-process s (1+ level))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
163 (t |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
164 (let ((rest s) |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
165 item firstlist list lists expression) |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
166 ;; Scan this list-level, setting LISTS to a list of forms, |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
167 ;; each of which produces a list of elements |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
168 ;; that should go in this level. |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48172
diff
changeset
|
169 ;; The order of LISTS is backwards. |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
170 ;; If there are non-splicing elements (constant or variable) |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
171 ;; at the beginning, put them in FIRSTLIST, |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
172 ;; as a list of tagged values (TAG . FORM). |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
173 ;; If there are any at the end, they go in LIST, likewise. |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
174 (while (and (consp rest) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
175 ;; Stop if the cdr is an expression inside a backquote or |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
176 ;; unquote since this needs to go recursively through |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
177 ;; backquote-process. |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
178 (not (or (eq (car rest) backquote-unquote-symbol) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
179 (eq (car rest) backquote-backquote-symbol)))) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
180 (setq item (backquote-process (car rest) level)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
181 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
182 ((= (car item) 2) |
8007
5b6bbe9478b5
(backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents:
7369
diff
changeset
|
183 ;; Put the nonspliced items before the first spliced item |
5b6bbe9478b5
(backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents:
7369
diff
changeset
|
184 ;; into FIRSTLIST. |
5b6bbe9478b5
(backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents:
7369
diff
changeset
|
185 (if (null lists) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
186 (setq firstlist list |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
187 list nil)) |
8007
5b6bbe9478b5
(backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents:
7369
diff
changeset
|
188 ;; Otherwise, put any preceding nonspliced items into LISTS. |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
189 (if list |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
190 (push (backquote-listify list '(0 . nil)) lists)) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
191 (push (cdr item) lists) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
192 (setq list nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
193 (t |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
194 (setq list (cons item list)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
195 (setq rest (cdr rest))) |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
196 ;; Handle nonsplicing final elements, and the tail of the list |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
197 ;; (which remains in REST). |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
198 (if (or rest list) |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
199 (push (backquote-listify list (backquote-process rest level)) |
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
200 lists)) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48172
diff
changeset
|
201 ;; Turn LISTS into a form that produces the combined list. |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
202 (setq expression |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
203 (if (or (cdr lists) |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
204 (eq (car-safe (car lists)) backquote-splice-symbol)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
205 (cons 'append (nreverse lists)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
206 (car lists))) |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
207 ;; Tack on any initial elements. |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
208 (if firstlist |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
209 (setq expression (backquote-listify firstlist (cons 1 expression)))) |
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
210 (if (eq (car-safe expression) 'quote) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
211 (cons 0 (list 'quote s)) |
6835
922626d0570d
(backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents:
6224
diff
changeset
|
212 (cons 1 expression)))))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
213 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
214 ;; backquote-listify takes (tag . structure) pairs from backquote-process |
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
215 ;; and decides between append, list, backquote-list*, and cons depending |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
216 ;; on which tags are in the list. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
217 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
218 (defun backquote-listify (list old-tail) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
219 (let ((heads nil) (tail (cdr old-tail)) (list-tail list) (item nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
220 (if (= (car old-tail) 0) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
221 (setq tail (eval tail) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
222 old-tail nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
223 (while (consp list-tail) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
224 (setq item (car list-tail)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
225 (setq list-tail (cdr list-tail)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
226 (if (or heads old-tail (/= (car item) 0)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
227 (setq heads (cons (cdr item) heads)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
228 (setq tail (cons (eval (cdr item)) tail)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
229 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
230 (tail |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
231 (if (null old-tail) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
232 (setq tail (list 'quote tail))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
233 (if heads |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
234 (let ((use-list* (or (cdr heads) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
235 (and (consp (car heads)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
236 (eq (car (car heads)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
237 backquote-splice-symbol))))) |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
238 (cons (if use-list* 'backquote-list* 'cons) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
239 (append heads (list tail)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
240 tail)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
241 (t (cons 'list heads))))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
242 |
78522
d471cb9c486c
(backquote-delay-process): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
243 ;; arch-tag: 1a26206a-6b5e-4c56-8e24-2eef0f7e0e7a |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
38028
diff
changeset
|
244 ;;; backquote.el ends here |