[climacs-cvs] CVS climacs

thenriksen thenriksen at common-lisp.net
Sun Jul 23 11:57:11 UTC 2006


Update of /project/climacs/cvsroot/climacs
In directory clnet:/tmp/cvs-serv31285

Modified Files:
	base.lisp 
Log Message:

Added `as-offsets' macro for ease of writing functions that accept
both offsets and marks.


--- /project/climacs/cvsroot/climacs/base.lisp	2006/07/07 23:59:38	1.54
+++ /project/climacs/cvsroot/climacs/base.lisp	2006/07/23 11:57:10	1.55
@@ -32,6 +32,30 @@
 
 (in-package :climacs-base)
 
+(defmacro as-offsets ((&rest marks)
+                      &body body)
+  "Bind the symbols in `marks' to the numeric offsets of the mark
+  objects that the symbols are bound to. If a symbol in `mark' is
+  already bound to an offset, just keep that binding. An element
+  of `marks' may also be a list - in this case, the first element
+  is used to get an offset, and the second element (which should
+  be a symbol) will be bound to this offset. Evaluate `body' with
+  these bindings."
+  `(let ,(mapcar #'(lambda (mark-sym)
+                     (if (listp mark-sym)
+                         `(,(second mark-sym)
+                            (let ((value ,(first mark-sym)))
+                              (if (numberp value)
+                                  value
+                                  (offset value))))
+                         `(,mark-sym
+                           (let ((value ,mark-sym))
+                             (if (numberp value)
+                                 ,mark-sym
+                                 (offset value))))))
+                 marks)
+     , at body))
+
 (defmacro do-buffer-region ((object offset buffer offset1 offset2)
                             &body body)
   "Iterate over the elements of the region delimited by offset1 and offset2.




More information about the Climacs-cvs mailing list