SHOW:
|
|
- or go back to the newest paste.
| 1 | ; Define a macro called "$" with one argument "selector-or-nodes" and an arbitrary number of extra | |
| 2 | ; arguments that are listed in "modifiers". | |
| 3 | - | `*LQUERY-MASTER-DOCUMENT* |
| 3 | + | |
| 4 | - | `(let ((working-nodes *LQUERY-MASTER-DOCUMENT*)) |
| 4 | + | |
| 5 | - | ,(if (stringp selector-or-nodes) |
| 5 | + | `*LQUERY-MASTER-DOCUMENT* ;In case selector-or-nodes is NIL, simply return the entire document. |
| 6 | - | `(setf working-nodes (css:query ,selector-or-nodes working-nodes)) |
| 6 | + | `(let ((working-nodes *LQUERY-MASTER-DOCUMENT*)) ;Create a variable "working-nodes" and set it to the document. |
| 7 | - | `(setf working-nodes ,selector-or-nodes)) |
| 7 | + | ,(if (stringp selector-or-nodes) ;In case "selector-or-nodes" is a string, we assume the user wants to use it as a CSS selector. |
| 8 | `(setf working-nodes (css:query ,selector-or-nodes working-nodes)) ;Use the css:query function to get the desired elements and set "working-nodes" to that. | |
| 9 | - | (if (not (listp working-nodes)) |
| 9 | + | `(setf working-nodes ,selector-or-nodes)) ;Otherwise simply set working-nodes to the value specified. |
| 10 | ||
| 11 | (if (not (listp working-nodes)) ;Safety check to make sure we can only process lists. | |
| 12 | - | ,(if modifiers |
| 12 | + | |
| 13 | - | `(progn |
| 13 | + | |
| 14 | - | ,@(loop for mod in modifiers collect |
| 14 | + | ,(if modifiers ;If any modifiers were supplied, |
| 15 | - | `(setf working-nodes (,(find-symbol (mkstr 'nodefun- (car mod)) :lquery) |
| 15 | + | `(progn ;Do the following |
| 16 | - | working-nodes |
| 16 | + | ,@(loop for mod in modifiers collect ;This loop "generates" function calls that will be executed later on when the program is actually run. |
| 17 | - | ,@(cdr mod)))))) |
| 17 | + | `(setf working-nodes ;Set "working-nodes" to the following new value |
| 18 | (,(find-symbol (mkstr 'nodefun- (car mod)) :lquery) ;Generated by the function we passed into the macro as a "modifier" argument. | |
| 19 | - | working-nodes))) |
| 19 | + | working-nodes ;Pass the current "working-nodes" into this function |
| 20 | ,@(cdr mod)))))) ;As well as all the other arguments supplied to the function call. | |
| 21 | ||
| 22 | working-nodes))) ;Finally return "working-nodes". |