annotate lisp/emacs-lisp/backquote.el @ 53021:92d82baef50b

* xterm.c (XAW_ARROW_SCROLLBARS): Define it for Xaw 1.5E.
author Jan Djärv <jan.h.d@swipnet.se>
date Sat, 08 Nov 2003 12:45:13 +0000
parents 695cf19ef79e
children 3c18d4160cc6 375f2633d815
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15261
bd56cdc4d07b Fixed up initial line
Erik Naggum <erik@naggum.no>
parents: 14169
diff changeset
1 ;;; backquote.el --- implement the ` Lisp construct
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
2
39085
97bb42866d17 (backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
3 ;;; Copyright (C) 1990, 1992, 1994, 2001 Free Software Foundation, Inc.
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
5 ;; Author: Rick Sladkey <jrs@world.std.com>
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
6 ;; Maintainer: FSF
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
7 ;; Keywords: extensions, internal
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
8
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 12606
diff changeset
9 ;; This file is part of GNU Emacs.
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 11687
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
24 ;; Boston, MA 02111-1307, USA.
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 12606
diff changeset
26 ;;; Commentary:
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
48172
ce9e21650e0c Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 39085
diff changeset
28 ;; When the Lisp reader sees `(...), it generates (\` (...)).
ce9e21650e0c Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 39085
diff changeset
29 ;; When it sees ,... inside such a backquote form, it generates (\, ...).
ce9e21650e0c Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 39085
diff changeset
30 ;; For ,@... it generates (\,@ ...).
ce9e21650e0c Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 39085
diff changeset
31
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
32 ;; 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
33 ;; 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
34 ;; 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
35 ;; and needs no run-time support. It should really be a subr.
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
37 ;;; Code:
181
a587d037d637 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 340
diff changeset
39 (provide 'backquote)
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 340
diff changeset
40
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
41 ;; function and macro versions of backquote-list*
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
42
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
43 (defun backquote-list*-function (first &rest list)
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
44 "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
45
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
46 For example (backquote-list* 'a 'b 'c) => (a b . c)"
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
47 (if list
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
48 (let* ((rest list) (newlist (cons first nil)) (last newlist))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
49 (while (cdr rest)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
50 (setcdr last (cons (car rest) nil))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
51 (setq last (cdr last)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
52 rest (cdr rest)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
53 (setcdr last (car rest))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
54 newlist)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
55 first))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
56
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
57 (defmacro backquote-list*-macro (first &rest list)
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
58 "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
59
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
60 For example (backquote-list* 'a 'b 'c) => (a b . c)"
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
61 (setq list (reverse (cons first list))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
62 first (car list)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
63 list (cdr list))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
64 (if list
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
65 (let* ((second (car list))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
66 (rest (cdr list))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
67 (newlist (list 'cons second first)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
68 (while rest
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
69 (setq newlist (list 'cons (car rest) newlist)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
70 rest (cdr rest)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
71 newlist)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
72 first))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
73
7369
cc6d237a7c7e (backquote-backquote-symbol): Don't autoload defvar.
Richard M. Stallman <rms@gnu.org>
parents: 7299
diff changeset
74 (defalias 'backquote-list* (symbol-function 'backquote-list*-macro))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
75
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
76 ;; 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
77 ;; 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
78 (defconst backquote-backquote-symbol '\`
39085
97bb42866d17 (backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
79 "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
80
27243
069b39c07c8d Remove inappropriate customization (allowing custom.el to use
Dave Love <fx@gnu.org>
parents: 21365
diff changeset
81 (defconst backquote-unquote-symbol ',
39085
97bb42866d17 (backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
82 "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
83
27243
069b39c07c8d Remove inappropriate customization (allowing custom.el to use
Dave Love <fx@gnu.org>
parents: 21365
diff changeset
84 (defconst backquote-splice-symbol ',@
39085
97bb42866d17 (backquote-backquote-symbol)
Gerd Moellmann <gerd@gnu.org>
parents: 38412
diff changeset
85 "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
86
7299
44c38d99d3c4 (backquote): Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
87 ;;;###autoload
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
88 (defmacro backquote (arg)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
89 "Argument STRUCTURE describes a template to build.
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
90
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
91 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
92 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
93
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
94 For example:
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
95
11687
14c5ed91e3d0 ('\`): Use backslash for reading the backquote.
Richard M. Stallman <rms@gnu.org>
parents: 8209
diff changeset
96 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
97 `(a b c) => (a b c) ; backquote acts like quote
12606
410385a28fb8 (backquote): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
98 `(a ,b c) => (a (ba bb bc) c) ; insert the value of b
410385a28fb8 (backquote): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
99 `(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
100
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
101 Vectors work just like lists. Nested backquotes are permitted."
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
102 (cdr (backquote-process arg)))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
103
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
104 ;; GNU Emacs has no reader macros
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
105
7299
44c38d99d3c4 (backquote): Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 7298
diff changeset
106 ;;;###autoload
11687
14c5ed91e3d0 ('\`): Use backslash for reading the backquote.
Richard M. Stallman <rms@gnu.org>
parents: 8209
diff changeset
107 (defalias '\` (symbol-function 'backquote))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
108
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
109 ;; 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
110 ;; the backquote-processed structure. 0 => the structure is
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
111 ;; 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
112 ;; The top-level backquote macro just discards the tag.
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
113
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
114 (defun backquote-process (s)
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
115 (cond
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
116 ((vectorp s)
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
117 (let ((n (backquote-process (append s ()))))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
118 (if (= (car n) 0)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
119 (cons 0 s)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
120 (cons 1 (cond
38028
a5aad5623acc (backquote-process): Handle `[,@SYMBOL].
Richard M. Stallman <rms@gnu.org>
parents: 27243
diff changeset
121 ((not (listp (cdr n)))
a5aad5623acc (backquote-process): Handle `[,@SYMBOL].
Richard M. Stallman <rms@gnu.org>
parents: 27243
diff changeset
122 (list 'vconcat (cdr n)))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
123 ((eq (nth 1 n) 'list)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
124 (cons 'vector (nthcdr 2 n)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
125 ((eq (nth 1 n) 'append)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
126 (cons 'vconcat (nthcdr 2 n)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
127 (t
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
128 (list 'apply '(function vector) (cdr n))))))))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
129 ((atom s)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
130 (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
131 s
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
132 (list 'quote s))))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
133 ((eq (car s) backquote-unquote-symbol)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
134 (cons 1 (nth 1 s)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
135 ((eq (car s) backquote-splice-symbol)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
136 (cons 2 (nth 1 s)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
137 ((eq (car s) backquote-backquote-symbol)
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
138 (backquote-process (cdr (backquote-process (nth 1 s)))))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
139 (t
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
140 (let ((rest s)
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
141 item firstlist list lists expression)
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
142 ;; 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
143 ;; 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
144 ;; that should go in this level.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48172
diff changeset
145 ;; 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
146 ;; 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
147 ;; 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
148 ;; 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
149 ;; If there are any at the end, they go in LIST, likewise.
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
150 (while (consp rest)
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
151 ;; Turn . (, foo) into (,@ foo).
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
152 (if (eq (car rest) backquote-unquote-symbol)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
153 (setq rest (list (list backquote-splice-symbol (nth 1 rest)))))
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
154 (setq item (backquote-process (car rest)))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
155 (cond
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
156 ((= (car item) 2)
8007
5b6bbe9478b5 (backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents: 7369
diff changeset
157 ;; 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
158 ;; into FIRSTLIST.
5b6bbe9478b5 (backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents: 7369
diff changeset
159 (if (null lists)
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
160 (setq firstlist list
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
161 list nil))
8007
5b6bbe9478b5 (backquote-process): Fix criterion for using FIRSTLIST.
Richard M. Stallman <rms@gnu.org>
parents: 7369
diff changeset
162 ;; Otherwise, put any preceding nonspliced items into LISTS.
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
163 (if list
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
164 (setq lists (cons (backquote-listify list '(0 . nil)) lists)))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
165 (setq lists (cons (cdr item) lists))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
166 (setq list nil))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
167 (t
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
168 (setq list (cons item list))))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
169 (setq rest (cdr rest)))
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
170 ;; 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
171 ;; (which remains in REST).
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
172 (if (or rest list)
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
173 (setq lists (cons (backquote-listify list (backquote-process rest))
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
174 lists)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48172
diff changeset
175 ;; 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
176 (setq expression
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
177 (if (or (cdr lists)
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
178 (eq (car-safe (car lists)) backquote-splice-symbol))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
179 (cons 'append (nreverse lists))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
180 (car lists)))
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
181 ;; Tack on any initial elements.
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
182 (if firstlist
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
183 (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
184 (if (eq (car-safe expression) 'quote)
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
185 (cons 0 (list 'quote s))
6835
922626d0570d (backquote-process): Don't crash if ultimate
Richard M. Stallman <rms@gnu.org>
parents: 6224
diff changeset
186 (cons 1 expression))))))
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
187
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
188 ;; 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
189 ;; 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
190 ;; on which tags are in the list.
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
191
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
192 (defun backquote-listify (list old-tail)
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
193 (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
194 (if (= (car old-tail) 0)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
195 (setq tail (eval tail)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
196 old-tail nil))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
197 (while (consp list-tail)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
198 (setq item (car list-tail))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
199 (setq list-tail (cdr list-tail))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
200 (if (or heads old-tail (/= (car item) 0))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
201 (setq heads (cons (cdr item) heads))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
202 (setq tail (cons (eval (cdr item)) tail))))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
203 (cond
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
204 (tail
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
205 (if (null old-tail)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
206 (setq tail (list 'quote tail)))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
207 (if heads
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
208 (let ((use-list* (or (cdr heads)
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
209 (and (consp (car heads))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
210 (eq (car (car heads))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
211 backquote-splice-symbol)))))
6224
a27c028e757a (backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents: 6223
diff changeset
212 (cons (if use-list* 'backquote-list* 'cons)
6223
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
213 (append heads (list tail))))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
214 tail))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
215 (t (cons 'list heads)))))
de6afd5ec418 Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
216
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
217 ;;; 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
218 ;;; backquote.el ends here