(macro box_it
	(
		(extern swap_int
		        inq_marked_edges
		)
		(string text
		     old_tab
		)
		(int beg_lin
		     beg_col
		     end_lin
		     end_col
		     mid_left
		     mid_right
		     cur_lin
		     cur_col
		)

		(if (! (inq_marked))
			(error "No marked block/column.")
		;else
			(
				(inq_marked_edges beg_lin beg_col end_lin end_col mid_left mid_right)

				(if (> beg_lin end_lin)
					(swap_int beg_lin end_lin)
				)
				(if (> beg_col end_col)
					(swap_int beg_col end_col)
				)
				(save_position)

				(if (&& (> end_col beg_col) (> mid_right end_col))
					(
						(= end_col 0)
						(move_abs beg_lin 0)
						(end_of_line)
						(inq_position cur_lin cur_col)
						(while (<= cur_lin end_lin)
							(
								(-- cur_col)
								(if (> cur_col end_col)
									(= end_col cur_col)
								)
								(move_rel 1 0)
								(end_of_line)
								(inq_position cur_lin cur_col)
							)
						)
					)
				)

				(move_abs beg_lin (+ end_col 1))
				(inq_position cur_lin)

				(inq_position cur_lin)
				(while (<= cur_lin end_lin)
					(
						(= old_tab (use_tab_char "n"))
						(insert "º")
						(use_tab_char old_tab)
						(move_abs 0 beg_col)
						(insert "º")
						(move_abs 0 (+ end_col 1))
						(move_rel 1 0)
						(inq_position cur_lin)
					)
				)

				(= text (repeated (+ (- end_col beg_col) 1) "Í"))

				(move_abs (+ end_lin 1) beg_col)
				(save_position)
				(move_abs 0 1)
				(insert "\n")
				(restore_position)
				(insert (+ (+ "È" text) "¼"))

				(move_abs beg_lin beg_col)
				(save_position)
				(move_abs 0 1)
				(insert "\n")
				(restore_position)
				(insert (+ (+ "É" text) "»"))

				(restore_position)
				(raise_anchor)
			)
		)
	)
)
(macro repeated
	(
		(string repeated_text
		        text
		)
		(int repeat_count
		     loop_count
		)

		(get_parm 0 repeat_count)
		(get_parm 1 repeated_text)

		(= text "")
		(= loop_count 0)

		(while (< loop_count repeat_count)
			(
				(+= text repeated_text)
				(++ loop_count)
			)
		)

		(returns text)
	)
)
(macro swap_int
	(
		(int p0 p1)
		(get_parm 0 p0)
		(get_parm 1 p1)
		(put_parm 0 p1)
		(put_parm 1 p0)
	)
)
(macro inq_marked_edges
	(
		(int beg_lin
		     beg_col
		     end_lin
		     end_col
		     mid_left
		     mid_right
		     end_last
		)

		(if (inq_marked beg_lin beg_col end_lin end_col)
			(
 				(if (above beg_lin end_lin)
					(
						(swap_int beg_lin end_lin)
						(swap_int beg_col end_col)
					)
				)
				(if (== (inq_marked) 3)
					(
						(= beg_col 1)
						(= end_col (inq_line_length))
					)
				)
				(save_position)
				(move_abs end_lin)
				(end_of_line)
				(inq_position NULL end_last)
				(restore_position)

				(if (> end_col end_last)
					(= end_col end_last)
				)

				(if (== (inq_marked) 2)
					(
						(if (above beg_col end_col)
							(swap_int beg_col end_col)
						)
						(= mid_left beg_col)
						(= mid_right end_col)
					)
				;else
					(
						(if (&& (== beg_lin end_lin) (above beg_col end_col))
							(swap_int beg_col end_col)
						)
						(= mid_left 1)
						(= mid_right (inq_line_length))
					)
				)
				(put_parm 0 beg_lin)
				(put_parm 1 beg_col)
				(put_parm 2 end_lin)
				(put_parm 3 end_col)
				(put_parm 4 mid_left)
				(put_parm 5 mid_right)
			)
		)
	)
)
