Skip to content

Commit b4a33be

Browse files
authored
Make thinking and Markdown input visible by default (#217)
New Pi sessions now keep completed thinking expanded, so the assistant's reasoning remains visible after it finishes. The prompt buffer also gets Markdown highlighting by default, while still showing the raw markup that users type. Users who prefer the old behavior can still collapse completed thinking or use plain text input through the existing customization options.
1 parent 44b7973 commit b4a33be

6 files changed

Lines changed: 58 additions & 53 deletions

README.org

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ M-x package-install RET pi-coding-agent RET
8181
#+end_src
8282

8383
MELPA installs =transient=, =md-ts-mode=, and =markdown-table-wrap= automatically.
84-
=pi-coding-agent= uses =md-ts-mode= only for its own chat buffers, so
85-
installing or loading it does not change how unrelated =.md= files open.
84+
=pi-coding-agent= uses =md-ts-mode= only for its own chat and input buffers,
85+
so installing or loading it does not change how unrelated =.md= files open.
8686
If you want tree-sitter Markdown globally, configure =md-ts-mode=
8787
separately.
8888

@@ -157,7 +157,7 @@ pi instead. If =M-x pi-coding-agent= starts but says no model is available,
157157
the CLI usually still needs authentication.
158158

159159
pi-coding-agent uses Emacs's built-in tree-sitter support to render
160-
markdown and highlight code blocks in the chat buffer. This requires
160+
markdown and highlight code blocks in the chat and input buffers. This requires
161161
small grammar libraries to be compiled and installed — a one-time step
162162
that needs a C compiler (=gcc= or =cc=).
163163

@@ -226,9 +226,9 @@ Press =C-c C-p= to access the full menu with model selection, thinking level,
226226
completed-thinking settings for this chat and for future chat buffers, session
227227
management (new, resume, fork, export), statistics, and custom commands.
228228

229-
Completed thinking is collapsed by default. Press =TAB= on a completed-thinking
230-
line to expand that block, use =C-c C-p h= for this chat, or =C-c C-p H= for
231-
future chat buffers in the current Emacs session.
229+
Completed thinking is expanded by default. Press =TAB= inside a completed-thinking
230+
block to collapse or expand that block, use =C-c C-p h= for this chat, or
231+
=C-c C-p H= for future chat buffers in the current Emacs session.
232232

233233
* Tips & Tricks
234234

@@ -270,8 +270,8 @@ component-based views are unavailable or fall back.
270270

271271
New chat buffers inherit the user option =pi-coding-agent-thinking-display=,
272272
which controls how completed assistant thinking is shown. The default is
273-
=hidden=: live thinking still streams while the assistant is working, then it
274-
collapses when that thinking block finishes. Use =C-c C-p h= to switch this
273+
=visible=: live thinking streams while the assistant is working and remains
274+
expanded when that thinking block finishes. Use =C-c C-p h= to switch this
275275
chat, or =C-c C-p H= to change the default for future chat buffers in the
276276
current Emacs session. To make that default stick across restarts, set
277277
=pi-coding-agent-thinking-display= in your init file or via
@@ -359,10 +359,10 @@ Example configuration with =use-package=:
359359
(pi-coding-agent-context-error-threshold 90) ; Critical when context exceeds this %
360360
(pi-coding-agent-visit-file-other-window t) ; RET opens file in other window (nil for same)
361361
(pi-coding-agent-hot-tail-turn-count 3) ; Recent headed turns that re-wrap on resize
362-
;; (pi-coding-agent-thinking-display 'visible) ; Expand completed thinking by default
362+
;; (pi-coding-agent-thinking-display 'hidden) ; Collapse completed thinking by default
363363
;; (pi-coding-agent-thinking-hidden-preview nil) ; Always use generic "Thinking hidden…" stubs
364364
;; (pi-coding-agent-copy-raw-markdown t) ; Keep raw markdown on copy (default: strip hidden markup)
365-
;; (pi-coding-agent-input-markdown-highlighting t) ; tree-sitter markdown highlighting in input buffer
365+
;; (pi-coding-agent-input-markdown-highlighting nil) ; Plain text input buffer
366366
)
367367
#+end_src
368368

@@ -371,9 +371,10 @@ Copying from the chat buffer strips hidden markdown markup by default —
371371
=pi-coding-agent-copy-raw-markdown= to =t= for raw markdown, useful
372372
when pasting into docs, Slack, or other markdown-aware contexts.
373373

374-
The input buffer uses plain =text-mode= by default. Set
375-
=pi-coding-agent-input-markdown-highlighting= to =t= for tree-sitter
376-
markdown highlighting (bold, code spans, fenced blocks) in new sessions.
374+
The input buffer uses tree-sitter Markdown highlighting by default (bold,
375+
code spans, fenced blocks) while keeping the typed markup characters visible.
376+
Set =pi-coding-agent-input-markdown-highlighting= to =nil= for plain text input
377+
buffers in new sessions.
377378

378379
** Markdown tables
379380

pi-coding-agent-input.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,18 @@ For backward search: go to current input (nil index)."
232232

233233
(define-derived-mode pi-coding-agent-input-mode text-mode "Pi-Input"
234234
"Major mode for composing pi prompts.
235-
Defaults to plain `text-mode'. Set
236-
`pi-coding-agent-input-markdown-highlighting' to non-nil for tree-sitter
237-
markdown highlighting while preserving mode identity and keybindings."
235+
Uses tree-sitter markdown highlighting by default while preserving raw
236+
markup visibility, mode identity, and keybindings. Set
237+
`pi-coding-agent-input-markdown-highlighting' to nil for plain text."
238238
:group 'pi-coding-agent
239239
(when pi-coding-agent-input-markdown-highlighting
240240
(md-ts-mode)
241241
(setq major-mode 'pi-coding-agent-input-mode)
242242
(setq mode-name "Pi-Input")
243243
(use-local-map pi-coding-agent-input-mode-map)
244244
;; Users see exactly what they type — never hide markup in input.
245-
(setq-local md-ts-hide-markup nil))
245+
(setq-local md-ts-hide-markup nil)
246+
(md-ts--set-hide-markup nil))
246247
(setq-local header-line-format '(:eval (pi-coding-agent--header-line-string)))
247248
;; Reset inherited completions (text-mode adds ispell, etc.) — our
248249
;; input buffer should only offer slash commands, file refs, and paths.

pi-coding-agent-ui.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ Prefix arg toggles the behavior."
151151
:type 'boolean
152152
:group 'pi-coding-agent)
153153

154-
(defcustom pi-coding-agent-input-markdown-highlighting nil
154+
(defcustom pi-coding-agent-input-markdown-highlighting t
155155
"Whether to enable markdown syntax highlighting in the input buffer.
156156
When non-nil, the input buffer gets tree-sitter markdown highlighting
157-
\(bold, italic, code spans, fenced blocks). When nil, the input buffer
158-
uses plain `text-mode'.
157+
\(bold, italic, code spans, fenced blocks) while keeping raw markdown
158+
markup visible. When nil, the input buffer uses plain `text-mode'.
159159
160160
Takes effect for new sessions; existing input buffers keep their mode."
161161
:type 'boolean
@@ -205,7 +205,7 @@ inside that suffix; older history stays frozen until explicitly rebuilt."
205205
:type 'natnum
206206
:group 'pi-coding-agent)
207207

208-
(defcustom pi-coding-agent-thinking-display 'hidden
208+
(defcustom pi-coding-agent-thinking-display 'visible
209209
"Default display mode for completed assistant thinking in new chat buffers.
210210
New chat buffers copy this user preference into a buffer-local session value.
211211
Later per-buffer toggles affect only that chat buffer; they do not change this

pi-coding-agent.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
;; - pi coding agent @earendil-works/pi-coding-agent 0.75.5 or later, installed and in PATH
3838
;; - tree-sitter grammars for markdown and markdown-inline
3939
;;
40-
;; pi-coding-agent uses `md-ts-mode` for its chat buffers only; loading it
41-
;; does not change global Markdown file associations.
40+
;; pi-coding-agent uses `md-ts-mode` for its own chat and input buffers;
41+
;; loading it does not change global Markdown file associations.
4242
;;
4343
;; Usage:
4444
;; M-x pi-coding-agent Start or focus session in current project

test/pi-coding-agent-input-test.el

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3892,46 +3892,48 @@ display-agent-end must finalize the pending overlay with error face."
38923892
;; Inline backticks shouldn't affect heading transform
38933893
(should (string-match-p "^## Heading" (buffer-string)))))
38943894

3895-
;;; Input Mode — Markdown Highlighting (opt-in)
3895+
;;; Input Mode — Markdown Highlighting
38963896

3897-
(ert-deftest pi-coding-agent-test-input-mode-md-ts-when-enabled ()
3898-
"With markdown highlighting enabled, input mode has tree-sitter font-lock."
3897+
(ert-deftest pi-coding-agent-test-input-mode-md-ts-by-default ()
3898+
"By default, input mode has tree-sitter markdown font-lock."
38993899
(with-temp-buffer
3900-
(let ((pi-coding-agent-input-markdown-highlighting t))
3901-
(pi-coding-agent-input-mode)
3902-
(should (derived-mode-p 'pi-coding-agent-input-mode))
3903-
(insert "some **bold** text")
3904-
(font-lock-ensure)
3905-
(goto-char (point-min))
3906-
(search-forward "bold")
3907-
(should (memq 'bold
3908-
(let ((f (get-text-property (1- (point)) 'face)))
3909-
(if (listp f) f (list f))))))))
3900+
(pi-coding-agent-input-mode)
3901+
(should (derived-mode-p 'pi-coding-agent-input-mode))
3902+
(insert "some **bold** text")
3903+
(font-lock-ensure)
3904+
(goto-char (point-min))
3905+
(search-forward "bold")
3906+
(should (memq 'bold
3907+
(let ((f (get-text-property (1- (point)) 'face)))
3908+
(if (listp f) f (list f)))))))
39103909

39113910
(ert-deftest pi-coding-agent-test-input-mode-no-metadata-face ()
39123911
"With markdown highlighting, lines ending with colon have no metadata face.
39133912
Tree-sitter markdown doesn't have metadata face, so this verifies
39143913
no spurious faces are applied to plain colon-ending lines."
39153914
(with-temp-buffer
3916-
(let ((pi-coding-agent-input-markdown-highlighting t))
3917-
(pi-coding-agent-input-mode)
3918-
(insert "Fix the bug:\n- item\n")
3919-
(font-lock-ensure)
3920-
(goto-char (point-min))
3921-
(let ((f (get-text-property (point) 'face)))
3922-
;; No heading, bold, or other markdown face on plain text
3923-
(should-not (and f (not (eq f 'default))))))))
3915+
(pi-coding-agent-input-mode)
3916+
(insert "Fix the bug:\n- item\n")
3917+
(font-lock-ensure)
3918+
(goto-char (point-min))
3919+
(let ((f (get-text-property (point) 'face)))
3920+
;; No heading, bold, or other markdown face on plain text
3921+
(should-not (and f (not (eq f 'default)))))))
39243922

39253923
(ert-deftest pi-coding-agent-test-input-mode-no-hidden-markup ()
39263924
"Input mode does NOT hide markup, even when user customizes it globally."
39273925
(with-temp-buffer
3928-
(let ((pi-coding-agent-input-markdown-highlighting t)
3929-
(old-default (default-value 'md-ts-hide-markup)))
3926+
(let ((old-default (default-value 'md-ts-hide-markup)))
39303927
(unwind-protect
39313928
(progn
39323929
(setq-default md-ts-hide-markup t)
39333930
(pi-coding-agent-input-mode)
3934-
(should-not md-ts-hide-markup))
3931+
(should-not md-ts-hide-markup)
3932+
(insert "some **bold** text")
3933+
(font-lock-ensure)
3934+
(goto-char (point-min))
3935+
(search-forward "**")
3936+
(should-not (get-text-property (1- (point)) 'invisible)))
39353937
(setq-default md-ts-hide-markup old-default)))))
39363938

39373939
(ert-deftest pi-coding-agent-test-input-mode-no-fontification-without-markdown ()

test/pi-coding-agent-ui-test.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ This ensures all files get code fences for consistent display."
112112
(pi-coding-agent-chat-mode)
113113
(should (derived-mode-p 'pi-coding-agent-chat-mode)))))
114114

115-
(ert-deftest pi-coding-agent-test-thinking-display-default-is-hidden ()
116-
"Package default keeps completed thinking collapsed in new chat buffers."
117-
(should (eq (default-value 'pi-coding-agent-thinking-display) 'hidden)))
115+
(ert-deftest pi-coding-agent-test-thinking-display-default-is-visible ()
116+
"Package default keeps completed thinking expanded in new chat buffers."
117+
(should (eq (default-value 'pi-coding-agent-thinking-display) 'visible)))
118118

119119
(ert-deftest pi-coding-agent-test-chat-mode-initializes-thinking-display-from-default ()
120120
"New chat buffers inherit the configured completed-thinking display default."
@@ -301,12 +301,13 @@ This ensures all files get code fences for consistent display."
301301
(ignore-errors (delete-file file))
302302
(ignore-errors (delete-directory root t)))))
303303

304-
(ert-deftest pi-coding-agent-test-input-mode-derives-from-text ()
305-
"pi-coding-agent-input-mode derives from text-mode, not md-ts-mode by default."
304+
(ert-deftest pi-coding-agent-test-input-mode-keeps-own-mode-with-markdown-default ()
305+
"pi-coding-agent-input-mode keeps its identity with markdown highlighting."
306306
(with-temp-buffer
307307
(pi-coding-agent-input-mode)
308+
(should (derived-mode-p 'pi-coding-agent-input-mode))
308309
(should (derived-mode-p 'text-mode))
309-
(should-not (derived-mode-p 'md-ts-mode))))
310+
(should-not md-ts-hide-markup)))
310311

311312
(ert-deftest pi-coding-agent-test-input-mode-not-read-only ()
312313
"pi-coding-agent-input-mode allows editing."

0 commit comments

Comments
 (0)