+(defun picture-current-line ()
+ "Return the vertical position of point. Top line is 1."
+ (+ (count-lines (point-min) (point))
+ (if (= (current-column) 0) 1 0)))
+
+(defun picture-draw-rectangle (start end)
+ "Draw a rectangle around region."
+ (interactive "*r") ; start will be less than end
+ (let* ((sl (picture-current-line))
+ (sc (current-column))
+ (pvs picture-vertical-step)
+ (phs picture-horizontal-step)
+ (c1 (progn (goto-char start) (current-column)))
+ (r1 (picture-current-line))
+ (c2 (progn (goto-char end) (current-column)))
+ (r2 (picture-current-line))
+ (right (max c1 c2))
+ (left (min c1 c2))
+ (top (min r1 r2))
+ (bottom (max r1 r2)))
+ (goto-line top)
+ (move-to-column left t)
+ (picture-update-desired-column t)
+
+ (picture-movement-right)
+ (picture-insert picture-rectangle-ctl 1)
+ (picture-insert picture-rectangle-h (- right picture-desired-column))
+
+ (picture-movement-down)
+ (picture-insert picture-rectangle-ctr 1)
+ (picture-insert picture-rectangle-v (- bottom (picture-current-line)))
+
+ (picture-movement-left)
+ (picture-insert picture-rectangle-cbr 1)
+ (picture-insert picture-rectangle-h (- picture-desired-column left))
+
+ (picture-movement-up)
+ (picture-insert picture-rectangle-cbl 1)
+ (picture-insert picture-rectangle-v (- (picture-current-line) top))
+
+ (picture-set-motion pvs phs)
+ (goto-line sl)
+ (move-to-column sc t)))
+