Mercurial > emacs
annotate lisp/emacs-lisp/backquote.el @ 6357:fb5923ece02c
(VERTICAL_SCROLL_BAR_RIGHT_BORDER): Change from 3 to 2.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Tue, 15 Mar 1994 01:25:56 +0000 |
parents | a27c028e757a |
children | 922626d0570d |
rev | line source |
---|---|
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1 ;;; New backquote for GNU Emacs. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
2 ;;; Copyright (C) 1990, 1992 Free Software Foundation, Inc. |
845 | 3 |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
4 ;; Author: Rick Sladkey <jrs@world.std.com> |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
5 ;; Maintainer: FSF |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
6 ;; Keywords: extensions, internal |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
8 ;; This file is not part of GNU Emacs but is distributed under |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
9 ;; the same conditions as GNU Emacs. |
181 | 10 |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
13 ;; the Free Software Foundation; either version 1, or (at your option) |
181 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
25 ;; This is a new backquote for GNU Emacs written by |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
26 ;; Rick Sladkey <jrs@world.std.com>. It has the following |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
27 ;; features compared to the version 18 backquote: |
181 | 28 |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
29 ;; Correctly handles nested backquotes. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
30 ;; Correctly handles constants after a splice. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
31 ;; Correctly handles top-level atoms and unquotes. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
32 ;; Correctly handles unquote after dot. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
33 ;; Understands vectors. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
34 ;; Minimizes gratuitous consing. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
35 ;; Faster operation with simpler semantics. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
36 ;; Generates faster run-time expressions. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
37 ;; One third fewer calories than our regular beer. |
181 | 38 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
39 ;; 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
|
40 ;; 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
|
41 ;; 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
|
42 ;; and needs no run-time support. It should really be a subr. |
181 | 43 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
44 ;;; Code: |
181 | 45 |
584 | 46 (provide 'backquote) |
47 | |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
48 ;; function and macro versions of backquote-list* |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
49 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
50 (defun backquote-list*-function (first &rest list) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
51 "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
|
52 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
53 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
|
54 (if list |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
55 (let* ((rest list) (newlist (cons first nil)) (last newlist)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
56 (while (cdr rest) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
57 (setcdr last (cons (car rest) nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
58 (setq last (cdr last) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
59 rest (cdr rest))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
60 (setcdr last (car rest)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
61 newlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
62 first)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
63 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
64 (defmacro backquote-list*-macro (first &rest list) |
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
65 "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
|
66 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
67 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
|
68 (setq list (reverse (cons first list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
69 first (car list) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
70 list (cdr list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
71 (if list |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
72 (let* ((second (car list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
73 (rest (cdr list)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
74 (newlist (list 'cons second first))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
75 (while rest |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
76 (setq newlist (list 'cons (car rest) newlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
77 rest (cdr rest))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
78 newlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
79 first)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
80 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
81 (fset 'backquote-list* (symbol-function 'backquote-list*-macro)) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
82 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
83 ;; 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
|
84 ;; to represent the backquote, unquote, and splice operations. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
85 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
86 (defvar backquote-backquote-symbol '` |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
87 "*Symbol used to represent a backquote or nested backquote (e.g. `).") |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
88 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
89 (defvar backquote-unquote-symbol ', |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
90 "*Symbol used to represent an unquote (e.g. `,') inside a backquote.") |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
91 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
92 (defvar backquote-splice-symbol ',@ |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
93 "*Symbol used to represent a splice (e.g. `,'@) inside a backquote.") |
6223
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 (defmacro backquote (arg) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
96 "Argument STRUCTURE describes a template to build. |
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 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
|
99 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
|
100 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
101 For example: |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
102 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
103 b => (ba bb bc) ; assume b has this value |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
104 \(` (a b c)) => (a b c) ; backquote acts like quote |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
105 \(` (a (, b) c)) => (a (ba bb bc) c) ; insert the value of b |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
106 \(` (a (,@ b) c)) => (a ba bb bc c) ; splice in the value of b |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
107 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
108 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
|
109 (cdr (backquote-process arg))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
110 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
111 ;; GNU Emacs has no reader macros |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
112 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
113 (fset backquote-backquote-symbol (symbol-function 'backquote)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
114 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
115 ;; 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
|
116 ;; the backquote-processed structure. 0 => the structure is |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
117 ;; 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
|
118 ;; The top-level backquote macro just discards the tag. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
119 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
120 (defun backquote-process (s) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
121 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
122 ((vectorp s) |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
123 (let ((n (backquote-process (append s ())))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
124 (if (= (car n) 0) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
125 (cons 0 s) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
126 (cons 1 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
127 ((eq (nth 1 n) 'list) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
128 (cons 'vector (nthcdr 2 n))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
129 ((eq (nth 1 n) 'append) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
130 (cons 'vconcat (nthcdr 2 n))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
131 (t |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
132 (list 'apply '(function vector) (cdr n)))))))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
133 ((atom s) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
134 (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
|
135 s |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
136 (list 'quote s)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
137 ((eq (car s) backquote-unquote-symbol) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
138 (cons 1 (nth 1 s))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
139 ((eq (car s) backquote-splice-symbol) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
140 (cons 2 (nth 1 s))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
141 ((eq (car s) backquote-backquote-symbol) |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
142 (backquote-process (cdr (backquote-process (nth 1 s))))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
143 (t |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
144 (let ((rest s) (item nil) (firstlist nil) (list nil) (lists nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
145 (while (consp rest) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
146 (if (eq (car rest) backquote-unquote-symbol) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
147 (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
|
148 (setq item (backquote-process (car rest))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
149 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
150 ((= (car item) 2) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
151 (if (null firstlist) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
152 (setq firstlist list |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
153 list nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
154 (if list |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
155 (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
|
156 (setq lists (cons (cdr item) lists)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
157 (setq list nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
158 (t |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
159 (setq list (cons item list)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
160 (setq rest (cdr rest))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
161 (if (or rest list) |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
162 (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
|
163 lists))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
164 (setq lists |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
165 (if (or (cdr lists) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
166 (and (consp (car lists)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
167 (eq (car (car lists)) backquote-splice-symbol))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
168 (cons 'append (nreverse lists)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
169 (car lists))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
170 (if firstlist |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
171 (setq lists (backquote-listify firstlist (cons 1 lists)))) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
172 (if (eq (car lists) 'quote) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
173 (cons 0 (list 'quote s)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
174 (cons 1 lists)))))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
175 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
176 ;; 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
|
177 ;; 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
|
178 ;; on which tags are in the list. |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
179 |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
180 (defun backquote-listify (list old-tail) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
181 (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
|
182 (if (= (car old-tail) 0) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
183 (setq tail (eval tail) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
184 old-tail nil)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
185 (while (consp list-tail) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
186 (setq item (car list-tail)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
187 (setq list-tail (cdr list-tail)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
188 (if (or heads old-tail (/= (car item) 0)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
189 (setq heads (cons (cdr item) heads)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
190 (setq tail (cons (eval (cdr item)) tail)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
191 (cond |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
192 (tail |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
193 (if (null old-tail) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
194 (setq tail (list 'quote tail))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
195 (if heads |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
196 (let ((use-list* (or (cdr heads) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
197 (and (consp (car heads)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
198 (eq (car (car heads)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
199 backquote-splice-symbol))))) |
6224
a27c028e757a
(backquote-listify): Renamed from bq-listify.
Richard M. Stallman <rms@gnu.org>
parents:
6223
diff
changeset
|
200 (cons (if use-list* 'backquote-list* 'cons) |
6223
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
201 (append heads (list tail)))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
202 tail)) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
203 (t (cons 'list heads))))) |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
204 |
de6afd5ec418
Complete rewrite by Sladkey.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
205 ;; backquote.el ends here |