Source code for mmf.utils.pymacs
"""Some tools for using Pymacs in Emacs.
"""
from __future__ import division
__all__ = ['launch_pp_terminals']
from Pymacs import lisp
import mmf.async.pp
[docs]def launch_pp_terminals(n, h_max=4):
r"""Opens a new window and splits it, launching a terminal that logs into
each of the first `n` terminals specified in `mmf.async.pp._HOSTS`"""
rows = n // h_max
cols = h_max
commands = []
hosts = list(reversed(mmf.async.pp._HOSTS[:n]))
col = 1
row = 1
n = 0
for row in xrange(rows):
if row + 1 < rows:
# We will need more rows, so create a new one but don't change
# window yet.
commands.append("(setq next-row (split-window next-row height))")
for col in xrange(cols):
if hosts:
h = hosts.pop()[0]
else:
break
commands.append("(select-window window)")
commands.append('(term "bash")')
commands.append('(rename-buffer "%s")' % h)
commands.append('(insert "ssh %s") (term-send-input)' % h)
commands.append('(insert "export TERM=vt100") (term-send-input)')
commands.append('(insert "top") (term-send-input)')
if col + 1 < cols:
# We will need more cols, so create one and move window
commands.append("(setq window (split-window window width t))")
# Move to next row
commands.append("(setq window next-row)")
command = """
(let ((frame (new-frame))
frame-height
frame-width
next-row
window
width
height)
(set-face-attribute 'default frame :height 80)
(setq frame-height
(/ (* (/ (x-display-pixel-height) (frame-char-height frame)) 1) 2))
(setq frame-width
(- (/ (x-display-pixel-width) (frame-char-width frame)) 5))
(setq next-row (frame-first-window frame))
(setq window (frame-first-window frame))
(setq width (/ frame-width %i))
(setq height (/ frame-height %i))
(set-frame-position frame 0 0)
(set-frame-size frame frame-width frame-height)
%s)
""" % (cols, rows, "\n".join(commands))
print command
lisp(command)