-declare -i x="ecols * e_colwd + e_hextra"
-noip $emacs -geometry $((ecols * e_colchars + e_cextra))x$(((XHEIGHT - e_vextra)/e_lineht))+0+0&
-
-# --- Now place some xterms ---
-#
-# A few smaller xterms are in general better than one great big one. 35
-# lines is a good height for most terminals. 25 lines is a minimum. The
-# strategy for doling out xterms into a column is to make as many 35-liners
-# as we can, until the remaining space would be too small for a 25-liner. If
-# we can get two 25s out of that then we do (largest first); otherwise just
-# make one big one. We stop at the end of a page, once we've made three
-# xterms.
-
-declare -i n=0 pgx=0 l h y ht
-declare -i hstd="35 * t_lineht + t_vextra" hmin="25 * t_lineht + t_vextra"
-while true; do
- if ((x + t_wd > xbound)); then
- if ((n >= 3)); then break; fi
- x="pgx + XWIDTH" pgx="pgx + XWIDTH" xbound="xbound + XWIDTH"
- fi
- y=0 ht=XHEIGHT
- while ((ht - hstd >= hmin)); do
- $term $geom 80x35+$x+$y&
- y="y + hstd" ht="ht - hstd" n="n + 1"
+declare -i \
+ emacsx="ecols * e_colchars + e_cextra" \
+ emacsy="(XHEIGHT - e_vextra)/e_lineht"
+
+start-emacs () {
+ run bgclients noip $emacs -geometry ${emacsx}x${emacsy}+0+0
+}
+
+## Now place some xterms.
+##
+## A few smaller xterms are in general better than one great big one. 35
+## lines is a good height for most terminals. 25 lines is a minimum. The
+## strategy for doling out xterms into a column is to make as many 35-liners
+## as we can, until the remaining space would be too small for a 25-liner.
+## If we can get two 25s out of that then we do (largest first); otherwise
+## just make one big one. We stop at the end of a page, once we've made
+## three xterms.
+
+start-xterms () {
+
+ ## Initialize some parameters.
+ declare -i x="ecols * e_colwd + e_hextra"
+ declare -i n=0 pgx=0 l h y ht
+ declare -i hstd="35 * t_lineht + t_vextra" hmin="25 * t_lineht + t_vextra"
+
+ ## Do the placement.
+ while :; do
+
+ ## Start a new iteration.
+ if ((x + t_wd > xbound)); then
+ if ((n >= 3)); then break; fi
+ x="pgx + XWIDTH" pgx="pgx + XWIDTH" xbound="xbound + XWIDTH"
+ fi
+
+ ## Make large xterms.
+ y=0 ht=XHEIGHT
+ while ((ht - hstd >= hmin)); do
+ run bgclients $term $geom 80x35+$x+$y
+ y="y + hstd" ht="ht - hstd" n="n + 1"
+ done
+
+ ## Fill the remaining space.
+ if ((ht >= 2 * hmin)); then h="ht - hmin"; else h=ht; fi
+ l="(h - t_vextra)/t_lineht" h="l * t_lineht + t_vextra"
+ run bgclients $term $geom 80x$l+$x+$y
+ y="y + h" ht="ht - h" n="n + 1"
+ if ((ht >= hmin)); then
+ run bgclients $term $geom 80x25+$x+$y
+ n="n + 1"
+ fi
+ x="x + t_wd"