Skip to content

Commit 98d1780

Browse files
committed
docs: More on the term buffer.
1 parent 20564e0 commit 98d1780

File tree

2 files changed

+79
-21
lines changed

2 files changed

+79
-21
lines changed

docs/source/reference.rst

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ All function that grab the terminal frame must be called from within a
7474
secondary instance, that is, after below :code:`(turtles-ert-test)` in
7575
an ERT test.
7676

77+
When grabbing the terminal frame, the content of the current buffer is
78+
replaced with a copy of the terminal data, with the point set at the
79+
position of the cursor.
80+
81+
In that buffer, color and similar text attributes are available as a
82+
'face text property. Starting with Emacs 29.1, the terminal supports
83+
24bit colors, but older Emacs versions must do with 16 or even 8
84+
colors. This usually doesn't matter as it's more convenient to check
85+
for faces rather than colors, see the :faces key argument below.
86+
7787
(turtles-with-grab-buffer (&key ...) &rest body) : macro
7888
This macro creates an ERT test buffer, grab the specified
7989
portion of the frame, post-processes it, then evaluates BODY.
@@ -354,8 +364,17 @@ instances run the same version of Emacs with the same
354364
:code:`load-path`, in vanilla mode, without configuration.
355365

356366
The secondary Emacs instances are run within a hidden
357-
:code:`term-mode` buffer, which is grabbed upon request and sent to
358-
the instances.
367+
:code:`term-mode` buffer. Such buffers are called "
368+
*turtles-term-<instance-name>*" (note the space). You may switch to
369+
that buffer to interact directly with the Emacs instance. To see
370+
colors, rename it; Emacs doesn't bother processing 'font-lock-face in
371+
hidden buffers.
372+
373+
While secondary instances can be interacted with from that buffer, it
374+
is awkward, as the two Emacs instances use the same keybindings. You
375+
might be happier calling :ref:`turtles-new-frame-in-instance <visit>`,
376+
if you're running in a windowing environment, or otherwise call
377+
:ref:`turtles-instance-eval <instances>`.
359378

360379
The main Emacs process communicates with the secondary instances using
361380
socket communication described in the :ref:`next section <rpc>`. On
@@ -364,19 +383,17 @@ communicate with the server through RPCs.
364383

365384
There can be multiple secondary instances, identified by a symbol,
366385
their ID. Instances with different ids have different characteristics,
367-
defined by :code:`turtles-definstance`, described below.
368-
369-
Turtles defines one shared instance in a 80x25 terminal whose ID is
370-
'default. This is the instance used by ERT tests unless specified
371-
otherwise.
386+
defined by :code:`turtles-definstance`, described below. Turtles
387+
defines one shared instance in a 80x25 terminal whose ID is 'default.
388+
This is the instance used by ERT tests unless specified otherwise.
372389

373390
Secondary instances can be started and stopped independently using
374391
:code:`turtles-start-instance` and :code:`turtles-stop-instance`, and
375392
communicated with using :code:`turtles-instance-eval`.
376393

377-
When developing, the versions of elisp libraries might get out of sync
378-
between the main Emacs process and secondary instances. In such a
379-
case, the simplest thing to do is to restart the instances with
394+
During development, the versions of elisp libraries might get out of
395+
sync between the main Emacs process and secondary instances. In such a
396+
case, the simplest thing to do is to restart all live instances with
380397
:code:`turtles-restart`.
381398

382399
(turtles-start-server) : function
@@ -476,6 +493,14 @@ case, the simplest thing to do is to restart the instances with
476493
result of that evaluation. If that evaluation is likely to take
477494
time, set TIMEOUT to a value longer than the default 10s.
478495

496+
This function provides a convenient way to probe the internals of
497+
an Emacs instance from the comfort of the main Emacs process.
498+
499+
For example, if you want to see what buffers are opened in the
500+
secondary emacs instance, you can run :kbd:`M-x eval-expression`
501+
and evaluate :code:`(turtles-instance-eval 'default
502+
'(buffer-list))`.
503+
479504
(turtles-start-instance inst-or-id) : command
480505
Start the given instance, unless it is already started.
481506

turtles.texi

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,21 @@ nil.
588588

589589
Two macros are provided that fully control how the terminal frame is
590590
grabbed and fully-processed: @code{turtles-with-grab-buffer} and
591-
@code{turtles-to-string}:
591+
@code{turtles-to-string}, described below.
592+
593+
All function that grab the terminal frame must be called from within a
594+
secondary instance, that is, after below @code{(turtles-ert-test)} in
595+
an ERT test.
596+
597+
When grabbing the terminal frame, the content of the current buffer is
598+
replaced with a copy of the terminal data, with the point set at the
599+
position of the cursor.
600+
601+
In that buffer, color and similar text attributes are available as a
602+
‘face text property. Starting with Emacs 29.1, the terminal supports
603+
24bit colors, but older Emacs versions must do with 16 or even 8
604+
colors. This usually doesn’t matter as it’s more convenient to check
605+
for faces rather than colors, see the :faces key argument below.
592606

593607

594608
@table @asis
@@ -818,6 +832,10 @@ trailing newlines at the end of the current buffer.
818832

819833
This macro tests minibuffer or recursive-edit interactions.
820834

835+
This macro is meant to be called from within a secondary instance,
836+
that is, after below @code{(turtles-ert-test)} in an ERT
837+
test.
838+
821839
The READ section is a single sexp that calls a function that runs
822840
on the minibuffer or within a recursive-edit. When this function
823841
returns, the macro ends and returns the result of evaluating READ.
@@ -924,8 +942,17 @@ instances run the same version of Emacs with the same
924942
@code{load-path}, in vanilla mode, without configuration.
925943

926944
The secondary Emacs instances are run within a hidden
927-
@code{term-mode} buffer, which is grabbed upon request and sent to
928-
the instances.
945+
@code{term-mode} buffer. Such buffers are called ”
946+
`turtles-term-<instance-name>'” (note the space). You may switch to
947+
that buffer to interact directly with the Emacs instance. To see
948+
colors, rename it; Emacs doesn’t bother processing ‘font-lock-face in
949+
hidden buffers.
950+
951+
While secondary instances can be interacted with from that buffer, it
952+
is awkward, as the two Emacs instances use the same keybindings. You
953+
might be happier calling @ref{1b,,turtles-new-frame-in-instance},
954+
if you’re running in a windowing environment, or otherwise call
955+
@ref{d,,turtles-instance-eval}.
929956

930957
The main Emacs process communicates with the secondary instances using
931958
socket communication described in the @ref{17,,next section}. On
@@ -934,19 +961,17 @@ communicate with the server through RPCs.
934961

935962
There can be multiple secondary instances, identified by a symbol,
936963
their ID. Instances with different ids have different characteristics,
937-
defined by @code{turtles-definstance}, described below.
938-
939-
Turtles defines one shared instance in a 80x25 terminal whose ID is
940-
‘default. This is the instance used by ERT tests unless specified
941-
otherwise.
964+
defined by @code{turtles-definstance}, described below. Turtles
965+
defines one shared instance in a 80x25 terminal whose ID is ‘default.
966+
This is the instance used by ERT tests unless specified otherwise.
942967

943968
Secondary instances can be started and stopped independently using
944969
@code{turtles-start-instance} and @code{turtles-stop-instance}, and
945970
communicated with using @code{turtles-instance-eval}.
946971

947-
When developing, the versions of elisp libraries might get out of sync
948-
between the main Emacs process and secondary instances. In such a
949-
case, the simplest thing to do is to restart the instances with
972+
During development, the versions of elisp libraries might get out of
973+
sync between the main Emacs process and secondary instances. In such a
974+
case, the simplest thing to do is to restart all live instances with
950975
@code{turtles-restart}.
951976

952977

@@ -1058,6 +1083,14 @@ This function waits for the evaluation to finish and returns the
10581083
result of that evaluation. If that evaluation is likely to take
10591084
time, set TIMEOUT to a value longer than the default 10s.
10601085

1086+
This function provides a convenient way to probe the internals of
1087+
an Emacs instance from the comfort of the main Emacs process.
1088+
1089+
For example, if you want to see what buffers are opened in the
1090+
secondary emacs instance, you can run @code{M-x eval-expression}
1091+
and evaluate @code{(turtles-instance-eval 'default
1092+
'(buffer-list))}.
1093+
10611094
@item (turtles-start-instance inst-or-id) : command
10621095

10631096
Start the given instance, unless it is already started.

0 commit comments

Comments
 (0)