Skip to content

Commit 3d70358

Browse files
authored
feat: add manual tmux reattach commands (#63)
* chore: start manual tmux reattach work * feat: add manual tmux reattach commands * feat: add manual tmux reattach
1 parent 4b0a62c commit 3d70358

27 files changed

Lines changed: 2284 additions & 382 deletions

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ format: ## Auto-format elisp files using built-in indent-region (spaces only)
4141
$(BATCH) --eval "(progn (find-file \"enkan-repl.el\") (setq-local indent-tabs-mode nil) (untabify (point-min) (point-max)) (mark-whole-buffer) (indent-region (point-min) (point-max)) (save-buffer))"
4242
$(BATCH) --eval "(progn (find-file \"test/enkan-repl-test.el\") (setq-local indent-tabs-mode nil) (untabify (point-min) (point-max)) (mark-whole-buffer) (indent-region (point-min) (point-max)) (save-buffer))"
4343

44-
check: test compile checkdoc lint format ## Run all quality checks including formatting
44+
check: test compile checkdoc lint format clean ## Run all quality checks including formatting
4545

46-
check-ci: test compile checkdoc format ## Run quality checks for CI (without package-lint)
46+
check-ci: test compile checkdoc format clean ## Run quality checks for CI (without package-lint)
4747

4848
clean: ## Remove compiled files
49-
rm -f *.elc
49+
find . -path ./.git -prune -o -name '*.elc' -type f -exec rm -f {} +
5050

5151
extract-api: ## Extract public API documentation as org file
5252
$(BATCH) -l scripts/generate-docs.el --eval "(extract-public-api)"

README.org

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ compatibility with other environments has not been verified.
207207
/This ensures Claude sessions are isolated and changes are tracked safely./
208208

209209
3. *Open project file*: =M-x enkan-repl-open-project-input-file=
210-
4. *Start eat session*: =M-x enkan-repl-start-eat=
210+
4. *Start terminal session*: =M-x enkan-repl-start-session=
211211
5. *Write your thoughts* in the input org-mode file
212212
6. *Access functions easily*: Use =M-x enkan-repl-cheat-sheet= to browse and select functions
213213
7. *Send specific parts* using =M-x enkan-repl-send-region= or =M-x enkan-repl-send-rest-of-buffer=
@@ -258,12 +258,13 @@ Currently operates with a single fixed workspace (=ws:01=), with multi-workspace
258258
- =enkan-repl-send-5= - Send \\='5\\=' to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection.
259259

260260
*** Session Control
261+
- =enkan-repl-start-session= - Start a terminal session in the current directory. This is the backend-neutral session starter. It works with both the eat and tmux terminal backends configured by `enkan-repl-terminal-backend'. FORCE is accepted for interactive compatibility and currently ignored; the command always starts a new session.
261262
- =enkan-repl-setup= - Arrange windows for (the author's) optimal workflow
262263
- =enkan-repl-workspace-delete= - Delete a workspace and stop all associated terminal resources. This is the only interactive workspace deletion command. In `enkan-repl-workspace-list-mode', delete the workspace at point; otherwise delete the current workspace. With prefix ARG, prompt for a workspace. Noninteractive string ARG deletes that workspace ID. All paths use `enkan-repl--delete-workspace-completely'.
263264

264265
*** Utilities
266+
- =enkan-repl-tmux-reattach= - Reconnect Emacs state to live tmux sessions. FILE defaults to `enkan-repl-state-file'. Live tmux sessions whose names start with `enkan-repl-tmux-session-prefix' define the workspaces to restore. When a matching persisted workspace exists, its saved state is reused. When no saved state exists for a live tmux session, a minimal workspace is imported from the tmux session's windows so reattach works after Emacs state was lost. This command is intentionally manual; enkan-repl does not reattach on load.
265267
- =enkan-repl-recenter-bottom= - Recenter all enkan terminal buffers at bottom.
266-
- =enkan-repl-start-eat= -
267268
- =enkan-repl-toggle-global-mode= - Toggle enkan-repl global mode on/off.
268269
- =enkan-repl-workspace-switch= - Switch to another workspace. Uses `hmenu' if available to show workspace ID with its project.
269270

@@ -298,28 +299,39 @@ same user-facing send / layout commands (=enkan-repl-send-line=,
298299
instances of the same project become =alias=, =alias-2=, =alias-3=,
299300
... with the corresponding =*ws:NN enkan:/path/*<N>= mirror buffers
300301
inside Emacs.
301-
- A read-only mirror buffer is updated via =tmux capture-pane= so the
302+
- A read-only mirror buffer can be updated via =tmux capture-pane= so the
302303
layout / send-line code can find sessions via the usual
303-
=buffer-list= mechanism. Visible mirrors refresh every
304-
=enkan-repl-tmux-mirror-interval= seconds (default =5.0=). Hidden
305-
mirrors do not run capture until displayed or manually refreshed.
304+
=buffer-list= mechanism. Mirror refresh is manual by default: displaying
305+
or recreating a mirror buffer does not capture pane content. Press =g= in a
306+
mirror buffer, or run =M-x enkan-repl-tmux-refresh-current=, to refresh it.
307+
Automatic timer refresh is opt-in via
308+
=(setq enkan-repl-tmux-mirror-auto-refresh t)= and then uses
309+
=enkan-repl-tmux-mirror-interval= seconds.
306310
Disable mirroring with =(setq enkan-repl-tmux-mirror nil)= if not
307311
desired.
308312
- Mirror buffers show refresh state in the header line
309-
(=refreshing=, =hidden=, =fresh=, =unchanged=, =closed=). Press =g=
310-
in a mirror buffer, or run =M-x enkan-repl-tmux-refresh-current=, to
311-
force an immediate refresh.
313+
(=refreshing=, =hidden=, =fresh=, =unchanged=, =closed=).
314+
- Run =M-x enkan-repl-tmux-refresh-workspace= to recreate or force
315+
refresh all tmux mirror buffers for the currently selected workspace.
316+
This is useful when tmux windows exist but the Emacs-side mirrors are
317+
stale or missing.
312318
- =M-x enkan-repl-tmux-attach= launches an external terminal app and
313319
attaches to the current workspace's tmux session. The attach
314320
command is configurable via =enkan-repl-tmux-attach-command= (a
315321
format string with =%s= for the session name, or a function).
316322
- =M-x enkan-repl-tmux-kill-session= kills a single =enkan-*= session;
317323
=M-x enkan-repl-tmux-kill-all-enkan= confirms then kills all of them.
318324
- Persistent state is stored at =enkan-repl-state-file=
319-
(=~/.emacs.d/enkan-repl-state.eld= by default). On Emacs restart the
320-
state is reconciled with the live tmux server according to
321-
=enkan-repl-state-recovery-policy= (=reattach= / =recreate= /
322-
=prompt= / =ignore=, default =reattach=).
325+
(=~/.emacs.d/enkan-repl-state.eld= by default). enkan-repl does not
326+
automatically reconnect Emacs to live tmux sessions on startup. Run
327+
=M-x enkan-repl-tmux-reattach= when you want to manually reconnect.
328+
Live =enkan-*= tmux sessions define the workspaces to restore. When
329+
saved state exists for a live workspace it is reused; when it does not,
330+
enkan-repl imports a minimal workspace from the tmux windows so the
331+
session can be used again. Reattach ensures mirror buffers exist, but
332+
it avoids force-refreshing every restored workspace; use
333+
=M-x enkan-repl-tmux-refresh-workspace= when you explicitly want to
334+
refresh the current workspace's mirror contents.
323335

324336
**** eat backend specifics
325337

enkan-repl-constants.el

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
;;; Code:
1212

1313
(defconst enkan-repl-cheat-sheet-candidates
14-
'(("enkan-repl-send-region" . "Send region text (from START to END) to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection. Category: Text Sender")
14+
'(("enkan-repl-tmux-reattach" . "Reconnect Emacs state to live tmux sessions. FILE defaults to `enkan-repl-state-file'. Live tmux sessions whose names start with `enkan-repl-tmux-session-prefix' define the workspaces to restore. When a matching persisted workspace exists, its saved state is reused. When no saved state exists for a live tmux session, a minimal workspace is imported from the tmux session's windows so reattach works after Emacs state was lost. This command is intentionally manual; enkan-repl does not reattach on load.")
15+
("enkan-repl-send-region" . "Send region text (from START to END) to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection. Category: Text Sender")
1516
("enkan-repl-send-line" . "Send current line to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection. Category: Text Sender")
1617
("enkan-repl-send-enter" . "Send enter key to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection. Category: Text Sender")
1718
("enkan-repl-send-1" . "Send \\\\='1\\\\=' to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection. Category: Text Sender")
@@ -21,11 +22,11 @@
2122
("enkan-repl-send-5" . "Send \\\\='5\\\\=' to enkan session buffer with optional PFX. - From enkan buffer: Send to current buffer - From other buffer without prefix: Interactive buffer selection - With numeric prefix: Send to buffer at index (1-based) Uses unified backend with smart buffer detection. Category: Text Sender")
2223
("enkan-repl-recenter-bottom" . "Recenter all enkan terminal buffers at bottom. Category: Utilities")
2324
("enkan-repl-open-project-input-file" . "Open or create project input file for DIRECTORY. If DIRECTORY is nil, use current `default-directory'. If project input file exists, open it directly. If not exists, create from template then open. Category: Utilities")
24-
("enkan-repl-start-eat" . "")
25-
("enkan-repl-setup" . "Set up window layout based on context. - Standard input file: basic window layout with project input file on left and eat session on right in current workspace - Center file: auto start eat sessions using project configuration in current workspace Category: Session Controller")
25+
("enkan-repl-start-session" . "Start a terminal session in the current directory. This is the backend-neutral session starter. It works with both the eat and tmux terminal backends configured by `enkan-repl-terminal-backend'. FORCE is accepted for interactive compatibility and currently ignored; the command always starts a new session. Category: Session Controller")
26+
("enkan-repl-setup" . "Set up window layout based on context. - Standard input file: basic window layout with project input file on left and terminal session on right in current workspace - Center file: auto start terminal sessions using project configuration in current workspace Category: Session Controller")
2627
("enkan-repl-cheat-sheet" . "Display interactive `cheat-sheet' for enkan-repl commands. Category: Command Palette")
2728
("enkan-repl-toggle-global-mode" . "Toggle enkan-repl global mode on/off.")
28-
("enkan-repl-send-escape" . "Send ESC key to eat session buffer with optional PFX. - If called from enkan buffer: Send ESC to current buffer - If called from center file without prefix: Select from available enkan buffers - With numeric prefix: Send to buffer at that index (1-based) Category: Center File Multi-buffer Access")
29+
("enkan-repl-send-escape" . "Send ESC key to enkan session buffer with optional PFX. - If called from enkan buffer: Send ESC to current buffer - If called from center file without prefix: Select from available enkan buffers - With numeric prefix: Send to buffer at that index (1-based) Category: Center File Multi-buffer Access")
2930
("enkan-repl-open-project-directory" . "Open project directory in Dired from enkan-repl-projects with optional PFX. With prefix argument (\\\\[universal-argument]), select from available buffers. Category: Center File Multi-buffer Access")
3031
("enkan-repl-open-center-file" . "Open or create the center file based on enkan-repl-center-file configuration. Category: Center File Operations")
3132
("enkan-repl-print-setup-to-buffer" . "Print current setup variables for debugging. Displays enkan-repl-projects, enkan-repl-target-directories, enkan-repl-project-aliases, and current session state. Category: Debugging")
@@ -35,7 +36,7 @@
3536
Each element is a cons cell (FUNCTION-NAME . DESCRIPTION).")
3637

3738
(defconst enkan-repl-cheat-sheet-function-count
38-
20
39+
21
3940
"Number of functions in cheat-sheet.")
4041

4142
(provide 'enkan-repl-constants)

enkan-repl-state.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ Behavior is governed by `enkan-repl-state-recovery-policy':
203203
- `ignore' : do nothing.
204204
205205
Returns a plist describing the reconciliation result:
206-
(:loaded-workspaces ALIST :restored IDS :dropped IDS :orphan-tmux SESSIONS)."
206+
(:loaded-workspaces ALIST :restored IDS :dropped IDS :orphan-tmux SESSIONS
207+
:current CURRENT)."
207208
(interactive)
208209
(let ((payload (enkan-repl-state-load file)))
209210
(when (and payload (not (eq enkan-repl-state-recovery-policy 'ignore)))
@@ -231,7 +232,8 @@ Returns a plist describing the reconciliation result:
231232
(list :loaded-workspaces restored
232233
:restored keep-ids
233234
:dropped dropped
234-
:orphan-tmux tmux-only))))))
235+
:orphan-tmux tmux-only
236+
:current (plist-get payload :current)))))))
235237

236238
(provide 'enkan-repl-state)
237239
;;; enkan-repl-state.el ends here

0 commit comments

Comments
 (0)