Mercurial > hg > xemacs-beta
comparison lisp/cl-macs.el @ 800:a5954632b187
[xemacs-hg @ 2002-03-31 08:27:14 by ben]
more fixes, first crack at finishing behavior implementation
TODO.ben-mule-21-5: Update.
configure.in: Fix for new error-checking types.
make-mswin-unicode.pl: Don't be fucked up by CRLF. Output code
to force errors when nonintercepted Windows calls issued.
behavior.el, dumped-lisp.el, menubar-items.el: Add support for saving using custom. Load into a dumped XEmacs.
Correct :title to :short-doc in accordance with behavior-defs.el.
Add a submenu under Options for turning on/off behaviors.
cl-macs.el: Properly document `loop'. Fix a minor bug in keymap iteration and
add support for bit-vector iteration.
lisp-mode.el: Rearrange and add items for macro expanding.
menubar-items.el: Document connection between these two functions.
window.el: Port stuff from GNU 21.1.
config.inc.samp, xemacs.mak: Separate out and add new variable for controlling error-checking.
s/windowsnt.h: Use new ERROR_CHECK_ALL; not related to DEBUG_XEMACS.
alloc.c, backtrace.h, buffer.c, buffer.h, bytecode.c, callproc.c, casetab.c, charset.h, chartab.c, cmdloop.c, config.h.in, console-msw.c, console-stream.c, console-tty.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dired-msw.c, dired.c, dumper.c, editfns.c, eldap.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, file-coding.h, fileio.c, frame-msw.c, frame.c, frame.h, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, insdel.c, intl-auto-encap-win32.c, intl-auto-encap-win32.h, intl-encap-win32.c, intl-win32.c, keymap.c, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-x.c, menubar.c, mule-coding.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, opaque.c, print.c, process-nt.c, process-unix.c, process.c, rangetab.c, redisplay-msw.c, redisplay-output.c, redisplay.c, regex.c, scrollbar-msw.c, select-msw.c, signal.c, specifier.c, specifier.h, symbols.c, sysdep.c, syswindows.h, text.c, text.h, toolbar-msw.c, tooltalk.c, ui-gtk.c, unicode.c, window.c: Redo error-checking macros: ERROR_CHECK_TYPECHECK ->
ERROR_CHECK_TYPES, ERROR_CHECK_CHARBPOS -> ERROR_CHECK_TEXT, add
ERROR_CHECK_DISPLAY, ERROR_CHECK_STRUCTURES. Document these in
config.h.in. Fix code to follow docs. Fix *_checking_assert()
in accordance with new names.
Attempt to fix periodic redisplay crash freeing display line
structures. Add first implementation of sledgehammer redisplay
check.
Redo print_*() to use write_fmt_string(), write_fmt_string_lisp().
Fix bug in md5 handling.
Rename character-to-unicode to char-to-unicode; same for
unicode-to-char{acter}.
Move chartab documentation to `make-char-table'.
Some header cleanup.
Clean up remaining places where nonintercepted Windows calls are
being used.
automated/mule-tests.el: Fix for new Unicode support.
author | ben |
---|---|
date | Sun, 31 Mar 2002 08:30:17 +0000 |
parents | 023b83f4e54b |
children | 79c6ff3eef26 |
comparison
equal
deleted
inserted
replaced
799:03d9f9084848 | 800:a5954632b187 |
---|---|
1 ;;; cl-macs.el --- Common Lisp extensions for XEmacs Lisp (part four) | 1 ;;; cl-macs.el --- Common Lisp extensions for XEmacs Lisp (part four) |
2 | 2 |
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1993 Free Software Foundation, Inc. |
4 ;; Copyright (C) 2002 Ben Wing. | |
4 | 5 |
5 ;; Author: Dave Gillespie <daveg@synaptics.com> | 6 ;; Author: Dave Gillespie <daveg@synaptics.com> |
6 ;; Version: 2.02 | 7 ;; Version: 2.02 |
7 ;; Keywords: extensions | 8 ;; Keywords: extensions |
8 | 9 |
595 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs) | 596 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs) |
596 | 597 |
597 ;;;###autoload | 598 ;;;###autoload |
598 (defmacro loop (&rest args) | 599 (defmacro loop (&rest args) |
599 "(loop CLAUSE...): The Common Lisp `loop' macro. | 600 "(loop CLAUSE...): The Common Lisp `loop' macro. |
601 | |
602 The loop macro consists of a series of clauses, which do things like | |
603 iterate variables, set conditions for exiting the loop, accumulating values | |
604 to be returned as the return value of the loop, and executing arbitrary | |
605 blocks of code. Each clause is proceed in turn, and the loop executes its | |
606 body repeatedly until an exit condition is hit. | |
607 | |
608 It's important to understand that loop clauses such as `for' and `while', | |
609 which look like loop-establishing constructs, don't actually *establish* a | |
610 loop\; the looping is established by the `loop' clause itself, which will | |
611 repeatedly process its body until told to stop. `while' merely establishes | |
612 a condition which, when true, causes the loop to finish, and `for' sets a | |
613 variable to different values on each iteration (e.g. successive elements of | |
614 a list) and sets an exit condition when there are no more values. This | |
615 means, for example, that if two `for' clauses appear, you don't get two | |
616 nested loops, but instead two variables that are stepped in parallel, and | |
617 two exit conditions, either of which, if triggered, will cause the loop to | |
618 end. Similarly for a loop with a `for' and a `while' clause. For example: | |
619 | |
620 \(loop | |
621 for x in list | |
622 while x | |
623 do ...) | |
624 | |
625 In each successive iteration, X is set to the next element of the list. If | |
626 there are no more elements, or if any element is nil (the `while' clause), | |
627 the loop exits. Otherwise, the block of code following `do' is executed.) | |
628 | |
629 This example also shows that some clauses establish variable bindings -- | |
630 essentially like a `let' binding -- and that following clauses can | |
631 reference these variables. Furthermore, the entire loop is surrounded by a | |
632 block named nil (unless the `named' clause is given), so you can return | |
633 from the loop using the macro `return'. (The other way to exit the loop is | |
634 through the macro `loop-finish'. The difference is that some loop clauses | |
635 establish or accumulate a value to be returned, and `loop-finish' returns | |
636 this. `return', however, can only return an explicitly-specified value. | |
637 NOTE CAREFULLY: There is a loop clause called `return' as well as a | |
638 standard Lisp macro called `return'. Normally they work similarly\; but if | |
639 you give the loop a name with `named', you will need to use the macro | |
640 `return-from'.) | |
641 | |
642 Another extremely useful feature of loops is called \"destructuring\". If, | |
643 in place of VAR, a list (possibly dotted, possibly a tree of arbitary | |
644 complexity) is given, the value to be assigned is assumed to have a similar | |
645 structure to the list given, and variables in the list will be matched up | |
646 with corresponding elements in the structure. For example: | |
647 | |
648 \(loop | |
649 for (x y) in '((foo 1) (bar 2) (baz 3)) | |
650 do (puthash x y some-hash-table)) | |
651 | |
652 will add three elements to a hash table, mapping foo -> 1, bar -> 2, and | |
653 baz -> 3. As other examples, you can conveniently process alists using | |
654 | |
655 \(loop for (x . y) in alist do ...) | |
656 | |
657 and plists using | |
658 | |
659 \(loop for (x y) on plist by #'cddr do ...) | |
660 | |
661 Destructuring is forgiving in that mismatches in the number of elements on | |
662 either size will be handled gracefully, either by ignoring or initializing | |
663 to nil. | |
664 | |
665 If you don't understand how a particular loop clause works, create an | |
666 example and use `macroexpand-sexp' to expand the macro. | |
667 | |
600 Valid clauses are: | 668 Valid clauses are: |
601 for VAR from/upfrom/downfrom NUM to/upto/downto/above/below NUM by NUM, | 669 |
602 for VAR in LIST by FUNC, for VAR on LIST by FUNC, for VAR = INIT then EXPR, | 670 \(NOTE: Keywords in lowercase\; slashes separate different possibilities |
603 for VAR across ARRAY, repeat NUM, with VAR = INIT, while COND, until COND, | 671 for keywords, some of which are synonymous\; brackets indicate optional |
604 always COND, never COND, thereis COND, collect EXPR into VAR, | 672 parts of the clause. In all of the clauses with `being', the word `being', |
605 append EXPR into VAR, nconc EXPR into VAR, sum EXPR into VAR, | 673 the words `each' or `the', and the difference between singular and plural |
606 count EXPR into VAR, maximize EXPR into VAR, minimize EXPR into VAR, | 674 keywords are all just syntactic sugar. Stylistically, you should write |
607 if COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...], | 675 either `being each foo' or `being the foos'.) |
608 unless COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...], | 676 |
609 do EXPRS..., initially EXPRS..., finally EXPRS..., return EXPR, | 677 for VAR from/upfrom/downfrom NUM1 to/upto/downto/above/below NUM2 [by NUMSTEP] |
610 finally return EXPR, named NAME." | 678 Step VAR across numbers. `upfrom', `upto', and `below' explicitly |
679 indicate upward stepping\; `downfrom', `downto', and `above' explicitly | |
680 indicate downward stepping. (If none of these is given, the default is | |
681 upward.) `to', `upto', and `downto' cause stepping to include NUM2 as | |
682 the last iteration, while `above' and `below' stop just before reaching | |
683 NUM2. `by' can be given to indicate a stepping increment other than 1. | |
684 | |
685 for VAR in LIST [by FUNC] | |
686 Step VAR over elements of a LIST. FUNC specifies how to get successive | |
687 sublists and defaults to `cdr'. | |
688 | |
689 for VAR on LIST [by FUNC] | |
690 Step VAR over tails of a LIST. FUNC specifies how to get successive | |
691 sublists and defaults to `cdr'. | |
692 | |
693 for VAR in-ref LIST [by FUNC] | |
694 Step VAR over elements of a LIST, like `for ... in', except the VAR is | |
695 bound using `symbol-macrolet' instead of `let'. In essence, VAR is set | |
696 to a \"reference\" to the list element instead of the element itself\; | |
697 this us, you can destructively modify the list using `setf' on VAR, and | |
698 any changes to the list will \"magically\" reflect themselves in | |
699 subsequent uses of VAR. | |
700 | |
701 for VAR = INIT [then EXPR] | |
702 Set VAR on each iteration of the loop. If only INIT is given, use it | |
703 on each iteration. Otherwise, use INIT on the first iteration and EXPR | |
704 on subsequent ones. | |
705 | |
706 for VAR across/across-ref ARRAY | |
707 Step VAR across a sequence other than a list (string, vector, bit | |
708 vector). If `across-ref' is given, VAR is bound using | |
709 `symbol-macrolet' instead of `let' -- see above. | |
710 | |
711 for VAR being each/the element/elements in/of/in-ref/of-ref SEQUENCE [using (index INDEX-VAR)] | |
712 Step VAR across any sequence. A variable can be specified with a | |
713 `using' phrase to receive the index, starting at 0. If `in-ref' or | |
714 `of-ref' is given, VAR is bound using `symbol-macrolet' instead of | |
715 `let' -- see above. | |
716 | |
717 for VAR being each/the hash-key/hash-keys/hash-value/hash-values in/of HASH-TABLE [using (hash-value/hash-key OTHER-VAR)] | |
718 | |
719 for VAR being each/the hash-key/hash-keys/hash-value/hash-values in/of HASH-TABLE [using (hash-value/hash-key OTHER-VAR)] | |
720 Map VAR over a hash table. The various keywords are synonymous except | |
721 those that distinguish between keys and values. The `using' phrase is | |
722 optional and allows both key and value to be bound. | |
723 | |
724 for VAR being each/the symbol/present-symbol/external-symbol/symbols/present-symbols/external-symbols in/of OBARRAY | |
725 Map VAR over the symbols in an obarray. All symbol keywords are | |
726 currently synonymous. | |
727 | |
728 for VAR being each/the extent/extents [in/of BUFFER-OR-STRING] [from POS] [to POS] | |
729 Map VAR over the extents in a buffer or string, defaulting to the | |
730 current buffer, the beginning and the end, respectively. | |
731 | |
732 for VAR being each/the interval/intervals [in/of BUFFER-OR-STRING] [property PROPERTY] [from POS] [to POS] | |
733 Map VAR over the intervals without property change in a buffer or | |
734 string, defaulting to the current buffer, the beginning and the end, | |
735 respectively. If PROPERTY is given, iteration occurs using | |
736 `next-single-property-change'\; otherwise, using | |
737 `next-property-change'. | |
738 | |
739 for VAR being each/the window/windows [in/of FRAME] | |
740 Step VAR over the windows in FRAME, defaulting to the selected frame. | |
741 | |
742 for VAR being each/the frame/frames | |
743 Step VAR over all frames. | |
744 | |
745 for VAR being each/the buffer/buffers [by FUNC] | |
746 Step VAR over all buffers. This is actually equivalent to | |
747 `for VAR in (buffer-list) [by FUNC]'. | |
748 | |
749 for VAR being each/the key-code/key-codes/key-seq/key-seqs/key-binding/key-bindings in KEYMAP [using (key-code/key-codes/key-seq/key-seqs/key-binding/key-bindings OTHER-VAR)] | |
750 Map VAR over the entries in a keymap. Keyword `key-seq' causes | |
751 recursive mapping over prefix keymaps occurring in the keymap, with VAR | |
752 getting the built-up sequence (a vector). Otherwise, mapping does not | |
753 occur recursively. `key-code' and `key-seq' refer to what is bound | |
754 (second argument of `define-key'), and `key-binding' what it's bound to | |
755 (third argument of `define-key'). | |
756 | |
757 as VAR ... | |
758 `as' is a synonym for `for'. | |
759 | |
760 and VAR ... | |
761 `and' clauses have the same syntax as `for' clauses except that the | |
762 variables in the clause are bound in parallel with a preceding | |
763 `and'/`for' clause instead of in series. | |
764 | |
765 with VAR = INIT | |
766 Set VAR to INIT once, before doing any iterations. | |
767 | |
768 repeat NUM | |
769 Exit the loop if more than NUM iterations have occurred. | |
770 | |
771 while COND | |
772 Exit the loop if COND isn't true. | |
773 | |
774 until COND | |
775 Exit the loop if COND is true. | |
776 | |
777 collect EXPR [into VAR] | |
778 Push EXPR onto the end of a list of values -- stored either in VAR or a | |
779 temporary variable that will be returned as the return value of the | |
780 loop if it terminates through an exit condition or a call to | |
781 `loop-finish'. | |
782 | |
783 append EXPR [into VAR] | |
784 Append EXPR (a list) onto the end of a list of values, like `collect'. | |
785 | |
786 nconc EXPR [into VAR] | |
787 Nconc EXPR (a list) onto the end of a list of values, like `collect'. | |
788 | |
789 concat EXPR [into VAR] | |
790 Concatenate EXPR (a string) onto the end of a string of values, like | |
791 `collect'. | |
792 | |
793 vconcat EXPR [into VAR] | |
794 Concatenate EXPR (a vector) onto the end of a vector of values, like | |
795 `collect'. | |
796 | |
797 bvconcat EXPR [into VAR] | |
798 Concatenate EXPR (a bit vector) onto the end of a bit vector of values, | |
799 like `collect'. | |
800 | |
801 sum EXPR [into VAR] | |
802 Add EXPR to a value, like `collect'. | |
803 | |
804 count EXPR [into VAR] | |
805 If EXPR is true, increment a value by 1, like `collect'. | |
806 | |
807 maximize EXPR [into VAR] | |
808 IF EXPR is greater than a value, replace the value with EXPR, like | |
809 `collect'. | |
810 | |
811 minimize EXPR [into VAR] | |
812 IF EXPR is less than a value, replace the value with EXPR, like | |
813 `collect'. | |
814 | |
815 always COND | |
816 If COND is true, continue the loop and set the loop return value (the | |
817 same value that's manipulated by `collect' and friends and is returned | |
818 by a normal loop exit or an exit using `loop-finish') to t\; otherwise, | |
819 exit the loop and return nil. The effect is to determine and return | |
820 whether a condition is true \"always\" (all iterations of the loop). | |
821 | |
822 never COND | |
823 If COND is false, continue the loop and set the loop return value (like | |
824 `always') to t\; otherwise, exit the loop and return nil. The effect | |
825 is to determine and return whether a condition is \"never\" true (all | |
826 iterations of the loop). | |
827 | |
828 thereis COND | |
829 If COND is true, exit the loop and return COND. | |
830 | |
831 if/when COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...] | |
832 If COND is true, execute the directly following clause(s)\; otherwise, | |
833 execute the clauses following `else'. | |
834 | |
835 unless COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...] | |
836 If COND is false, execute the directly following clause(s)\; otherwise, execute the clauses following `else'. | |
837 | |
838 do EXPRS... | |
839 Execute the expressions (any Lisp forms). | |
840 | |
841 initially EXPRS... | |
842 Execute EXPR once, before doing any iterations, and after values have | |
843 been set using `with'. | |
844 | |
845 finally EXPRS... | |
846 Execute EXPR once, directly before the loop terminates. This will not | |
847 be executed if the loop terminates prematurely as a result of `always', | |
848 `never', `thereis', or `return'. | |
849 | |
850 return EXPR | |
851 Exit from the loop and return EXPR. | |
852 | |
853 finally return EXPR | |
854 Specify the value to be returned when the loop exits. (Unlike `return', | |
855 this doesn't cause the loop to immediately exit\; it will exit whenever | |
856 it normally would have.) This takes precedence over a return value | |
857 specified with `collect' and friends or `always' and friends. | |
858 | |
859 named NAME | |
860 Specify the name for block surrounding the loop, in place of nil. | |
861 (See `block'.) | |
862 " | |
611 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list args)))))) | 863 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list args)))))) |
612 (list 'block nil (list* 'while t args)) | 864 (list 'block nil (list* 'while t args)) |
613 (let ((loop-name nil) (loop-bindings nil) | 865 (let ((loop-name nil) (loop-bindings nil) |
614 (loop-body nil) (loop-steps nil) | 866 (loop-body nil) (loop-steps nil) |
615 (loop-result nil) (loop-result-explicit nil) | 867 (loop-result nil) (loop-result-explicit nil) |
880 '(progn . --cl-map))) | 1132 '(progn . --cl-map))) |
881 buf prop from to)))) | 1133 buf prop from to)))) |
882 | 1134 |
883 ((memq word key-types) | 1135 ((memq word key-types) |
884 (or (memq (car args) '(in of)) (error "Expected `of'")) | 1136 (or (memq (car args) '(in of)) (error "Expected `of'")) |
885 (let ((map (cl-pop2 args)) | 1137 (let* ((map (cl-pop2 args)) |
886 (other (if (eq (car args) 'using) | 1138 other-word |
887 (if (and (= (length (cadr args)) 2) | 1139 (other (if (eq (car args) 'using) |
888 (memq (caadr args) key-types) | 1140 (if (and (= (length (cadr args)) 2) |
889 (not (eq (caadr args) word))) | 1141 (memq (setq other-word (caadr args)) |
890 (cadr (cl-pop2 args)) | 1142 key-types) |
891 (error "Bad `using' clause")) | 1143 (not (eq (caadr args) word))) |
1144 (cadr (cl-pop2 args)) | |
1145 (error "Bad `using' clause")) | |
892 (gensym)))) | 1146 (gensym)))) |
893 (if (memq word '(key-binding key-bindings)) | 1147 (when (memq word '(key-binding key-bindings)) |
894 (setq var (prog1 other (setq other var)))) | 1148 (setq var (prog1 other (setq other var))) |
1149 (and other-word (setq word other-word))) | |
895 (setq loop-map-form | 1150 (setq loop-map-form |
896 (list (if (memq word '(key-seq key-seqs)) | 1151 (list (if (memq word '(key-seq key-seqs)) |
897 'cl-map-keymap-recursively 'cl-map-keymap) | 1152 'cl-map-keymap-recursively 'cl-map-keymap) |
898 (list 'function (list* 'lambda (list var other) | 1153 (list 'function (list* 'lambda (list var other) |
899 '--cl-map)) map)))) | 1154 '--cl-map)) map)))) |
980 | 1235 |
981 ((memq word '(vconcat vconcating)) | 1236 ((memq word '(vconcat vconcating)) |
982 (let ((what (cl-pop args)) | 1237 (let ((what (cl-pop args)) |
983 (var (cl-loop-handle-accum []))) | 1238 (var (cl-loop-handle-accum []))) |
984 (cl-push (list 'progn (list 'callf 'vconcat var what) t) loop-body))) | 1239 (cl-push (list 'progn (list 'callf 'vconcat var what) t) loop-body))) |
1240 | |
1241 ((memq word '(bvconcat bvconcating)) | |
1242 (let ((what (cl-pop args)) | |
1243 (var (cl-loop-handle-accum #*))) | |
1244 (cl-push (list 'progn (list 'callf 'bvconcat var what) t) loop-body))) | |
985 | 1245 |
986 ((memq word '(sum summing)) | 1246 ((memq word '(sum summing)) |
987 (let ((what (cl-pop args)) | 1247 (let ((what (cl-pop args)) |
988 (var (cl-loop-handle-accum 0))) | 1248 (var (cl-loop-handle-accum 0))) |
989 (cl-push (list 'progn (list 'incf var what) t) loop-body))) | 1249 (cl-push (list 'progn (list 'incf var what) t) loop-body))) |