@@ -145,38 +145,34 @@ Meant to be called when `gptel-menu' is active."
145
145
" \n " ))
146
146
ov))
147
147
148
- (defconst gptel--read-with-prefix-help
148
+ (defun gptel--read-with-prefix-help (s )
149
+ " Show help for TAB key in `read-with-prefix-help' ."
149
150
(concat
150
151
(propertize " (" 'face 'default )
151
152
(propertize " TAB" 'face 'help-key-binding )
152
- (propertize " : expand, " 'face 'default )
153
- (propertize " M-n" 'face 'help-key-binding )
154
- (propertize " /" 'face 'default )
155
- (propertize " M-p" 'face 'help-key-binding )
156
- (propertize " : next/previous) " 'face 'default ))
157
- " Help string ;TODO: " )
153
+ (propertize (concat " : " s " ) " ) 'face 'default )))
158
154
159
155
(defun gptel--read-with-prefix (prefix )
160
156
" Show string PREFIX in the minibuffer after the minibuffer prompt.
161
157
162
158
PREFIX is shown in an overlay. Repeated calls to this function
163
- will toggle its visibility state."
159
+ will toggle its visibility state (one line, maximum, none) ."
164
160
(unless (minibufferp )
165
161
(user-error " This command is intended to be used in the minibuffer." ))
162
+ (set (make-local-variable 'resize-mini-windows ) t )
166
163
(let* ((update
167
164
(lambda (ov s )
168
- (overlay-put
169
- ov 'after-string
170
- ( and s ( concat ( propertize ( concat " \n " s " \n " ) 'face 'shadow )
171
- (make-separator-line)))) ))
172
- (max-width (- ( window-width ) ( minibuffer-prompt-end ) ))
165
+ (overlay-put ov 'before-string
166
+ ( and s ( propertize ( concat s ( propertize " \n " 'face '( shadow default )))
167
+ 'rear-nonsticky t 'front-nonsticky t )))) )
168
+ ( max ( or max-mini-window-height 0.4 ))
169
+ (max-width (window-max-chars-per-line ))
173
170
(max (or max-mini-window-height 0.4 ))
174
171
(max-height (- (or (and (natnump max ) max )
175
172
(floor (* max (frame-height ))))
176
- 5 )))
173
+ 5 ))
174
+ (prefix (string-replace " \n " " ⏎" prefix)))
177
175
(when (and prefix (not (string-empty-p prefix)) (> max-height 1 ))
178
- (unless visual-line-mode (visual-line-mode 1 ))
179
- (goto-char (minibuffer-prompt-end ))
180
176
(pcase-let ((`(, prop . , ov )
181
177
(get-char-property-and-overlay
182
178
(point-min ) 'gptel )))
@@ -185,33 +181,35 @@ will toggle its visibility state."
185
181
(point-min ) (minibuffer-prompt-end ) nil t )))
186
182
(pcase prop
187
183
('partial
188
- (if (> (length prefix) max-width)
189
- (progn
190
- (overlay-put ov 'gptel 'prefix )
191
- (let ((disp-size
192
- (cl-loop for char across prefix
193
- for idx upfrom 0
194
- with n = 0 with max-length = (* max-height max-width)
195
- if (eq char ?\n ) do (cl-incf n)
196
- if (> n max-height) return idx
197
- if (> idx max-length)
198
- return idx
199
- finally return nil )))
200
- (funcall update ov
201
- (if disp-size
202
- (truncate-string-to-width
203
- prefix disp-size nil nil 'ellipsis )
204
- prefix))))
205
- (overlay-put ov 'gptel 'hide )
206
- (funcall update ov nil )))
207
- ('prefix (overlay-put ov 'gptel 'hide )
208
- (funcall update ov nil ))
209
- (_ (overlay-put ov 'gptel 'partial )
210
- (funcall update ov (truncate-string-to-width
211
- prefix max-width nil nil
212
- 'ellipsis ))))))))
213
-
214
- (defun gptel--transient-read-number (prompt _initial-input history )
184
+ (overlay-put ov 'gptel 'one-line )
185
+ (funcall update ov
186
+ (with-temp-buffer
187
+ (insert (gptel--read-with-prefix-help " shrink" ))
188
+ (let ((b (point )))
189
+ (insert prefix)
190
+ (set-text-properties b (point-max ) '(face (shadow default ))))
191
+ (goto-char (point-min ))
192
+ (let ((fill-column max-width))
193
+ (fill-region (point ) (point-max )))
194
+ (goto-line (min max-height (line-number-at-pos (point-max ))))
195
+ (concat (buffer-substring 1 (point ))
196
+ (propertize (truncate-string-to-width
197
+ (buffer-substring (point ) (point-max ))
198
+ (1- max-width) nil
199
+ nil
200
+ t ) 'face '(shadow default ))))))
201
+ (_ (funcall update ov
202
+ (if (>= (length prefix) max-width)
203
+ (let ((he (gptel--read-with-prefix-help " expand" )))
204
+ (overlay-put ov 'gptel 'partial )
205
+ (concat he (propertize (truncate-string-to-width
206
+ prefix
207
+ (- max-width (length he))
208
+ nil nil t )
209
+ 'face '(shadow default ))))
210
+ (overlay-put ov 'gptel 'hide )
211
+ (propertize prefix 'face '(shadow default ))))))))))
212
+ (defun gptel--transient-read-number (prompt initial-input history )
215
213
" Read a numeric value from the minibuffer.
216
214
217
215
PROMPT, _INITIAL-INPUT and HISTORY are as in the transient reader
@@ -239,7 +237,7 @@ Handle formatting for system messages when the active
239
237
(propertize " ]" 'face 'transient-heading ))
240
238
(if message
241
239
(gptel--describe-directive
242
- message (max (- (window-width ) 12 ) 14 ) " ⮐ " )
240
+ message (max (- (window-width ) 12 ) 14 ) " ⏎ " )
243
241
" [No system message set]" )))
244
242
245
243
(defun gptel--tools-init-value (obj )
@@ -390,7 +388,7 @@ which see."
390
388
(len (length val)))
391
389
(ptv (concat
392
390
" \" " (string-replace
393
- " \n " " ⮐ "
391
+ " \n " " ⏎ "
394
392
(truncate-string-to-width
395
393
val 20 nil nil t ))
396
394
" \" " (when (> len 20 )
@@ -768,7 +766,7 @@ If EXTERNAL is non-nil, include external sources of directives."
768
766
(concat " (" (gptel--describe-directive prompt (- width 30 )) " )" )
769
767
'face 'shadow ))
770
768
`(lambda () (interactive )
771
- (message " %s : %s " , msg ,(gptel--describe-directive prompt 100 " ⮐ " ))
769
+ (message " %s : %s " , msg ,(gptel--describe-directive prompt 100 " ⏎ " ))
772
770
(gptel--set-with-scope ', sym ', prompt gptel--set-buffer-locally))
773
771
:transient 'transient--do-return )
774
772
into prompt-suffixes
@@ -1212,19 +1210,18 @@ Or in an extended conversation:
1212
1210
:display-nil 'none
1213
1211
:overlay nil
1214
1212
:argument " :"
1215
- :prompt (concat " Add instructions for next request only "
1216
- gptel--read-with-prefix-help)
1213
+ :prompt " Instruction for next request: "
1217
1214
:reader (lambda (prompt initial history )
1218
1215
(let* ((directive
1219
1216
(car-safe (gptel--parse-directive gptel--system-message 'raw )))
1220
1217
(cycle-prefix (lambda () (interactive )
1221
- (gptel--read-with-prefix directive)))
1218
+ (gptel--read-with-prefix directive)))
1222
1219
(minibuffer-local-map
1223
1220
(make-composed-keymap
1224
1221
(define-keymap " TAB" cycle-prefix " <tab>" cycle-prefix)
1225
1222
minibuffer-local-map))
1226
1223
(extra (minibuffer-with-setup-hook cycle-prefix
1227
- (read-string prompt (or initial " " ) history ))))
1224
+ (read-string prompt nil history (or initial) ))))
1228
1225
(unless (string-empty-p extra) extra)))
1229
1226
:format " %k %d %v"
1230
1227
:key " d"
0 commit comments