@@ -108,38 +108,34 @@ Meant to be called when `gptel-menu' is active."
108
108
" \n " ))
109
109
ov))
110
110
111
- (defconst gptel--read-with-prefix-help
111
+ (defun gptel--read-with-prefix-help (s )
112
+ " Show help for TAB key in `read-with-prefix-help' ."
112
113
(concat
113
114
(propertize " (" 'face 'default )
114
115
(propertize " TAB" 'face 'help-key-binding )
115
- (propertize " : expand, " 'face 'default )
116
- (propertize " M-n" 'face 'help-key-binding )
117
- (propertize " /" 'face 'default )
118
- (propertize " M-p" 'face 'help-key-binding )
119
- (propertize " : next/previous) " 'face 'default ))
120
- " Help string ;TODO: " )
116
+ (propertize (concat " : " s " ) " ) 'face 'default )))
121
117
122
118
(defun gptel--read-with-prefix (prefix )
123
119
" Show string PREFIX in the minibuffer after the minibuffer prompt.
124
120
125
121
PREFIX is shown in an overlay. Repeated calls to this function
126
- will toggle its visibility state."
122
+ will toggle its visibility state (one line, maximum, none) ."
127
123
(unless (minibufferp )
128
124
(user-error " This command is intended to be used in the minibuffer." ))
125
+ (set (make-local-variable 'resize-mini-windows ) t )
129
126
(let* ((update
130
127
(lambda (ov s )
131
- (overlay-put
132
- ov 'after-string
133
- ( and s ( concat ( propertize ( concat " \n " s " \n " ) 'face 'shadow )
134
- (make-separator-line)))) ))
135
- (max-width (- ( window-width ) ( minibuffer-prompt-end ) ))
128
+ (overlay-put ov 'before-string
129
+ ( and s ( propertize ( concat s ( propertize " \n " 'face '( shadow default )))
130
+ 'rear-nonsticky t 'front-nonsticky t )))) )
131
+ ( max ( or max-mini-window-height 0.4 ))
132
+ (max-width (window-max-chars-per-line ))
136
133
(max (or max-mini-window-height 0.4 ))
137
134
(max-height (- (or (and (natnump max ) max )
138
135
(floor (* max (frame-height ))))
139
- 5 )))
136
+ 5 ))
137
+ (prefix (string-replace " \n " " ⏎" prefix)))
140
138
(when (and prefix (not (string-empty-p prefix)) (> max-height 1 ))
141
- (unless visual-line-mode (visual-line-mode 1 ))
142
- (goto-char (minibuffer-prompt-end ))
143
139
(pcase-let ((`(, prop . , ov )
144
140
(get-char-property-and-overlay
145
141
(point-min ) 'gptel )))
@@ -148,32 +144,34 @@ will toggle its visibility state."
148
144
(point-min ) (minibuffer-prompt-end ) nil t )))
149
145
(pcase prop
150
146
('partial
151
- (if (> (length prefix) max-width)
152
- (progn
153
- (overlay-put ov 'gptel 'prefix )
154
- (let ((disp-size
155
- (cl-loop for char across prefix
156
- for idx upfrom 0
157
- with n = 0 with max-length = (* max-height max-width)
158
- if (eq char ?\n ) do (cl-incf n)
159
- if (> n max-height) return idx
160
- if (> idx max-length)
161
- return idx
162
- finally return nil )))
163
- (funcall update ov
164
- (if disp-size
165
- (truncate-string-to-width
166
- prefix disp-size nil nil 'ellipsis )
167
- prefix))))
168
- (overlay-put ov 'gptel 'hide )
169
- (funcall update ov nil )))
170
- ('prefix (overlay-put ov 'gptel 'hide )
171
- (funcall update ov nil ))
172
- (_ (overlay-put ov 'gptel 'partial )
173
- (funcall update ov (truncate-string-to-width
174
- prefix max-width nil nil
175
- 'ellipsis ))))))))
176
-
147
+ (overlay-put ov 'gptel 'one-line )
148
+ (funcall update ov
149
+ (with-temp-buffer
150
+ (insert (gptel--read-with-prefix-help " shrink" ))
151
+ (let ((b (point )))
152
+ (insert prefix)
153
+ (set-text-properties b (point-max ) '(face (shadow default ))))
154
+ (goto-char (point-min ))
155
+ (let ((fill-column max-width))
156
+ (fill-region (point ) (point-max )))
157
+ (goto-line (min max-height (line-number-at-pos (point-max ))))
158
+ (concat (buffer-substring 1 (point ))
159
+ (propertize (truncate-string-to-width
160
+ (buffer-substring (point ) (point-max ))
161
+ (1- max-width) nil
162
+ nil
163
+ t ) 'face '(shadow default ))))))
164
+ (_ (funcall update ov
165
+ (if (>= (length prefix) max-width)
166
+ (let ((he (gptel--read-with-prefix-help " expand" )))
167
+ (overlay-put ov 'gptel 'partial )
168
+ (concat he (propertize (truncate-string-to-width
169
+ prefix
170
+ (- max-width (length he))
171
+ nil nil t )
172
+ 'face '(shadow default ))))
173
+ (overlay-put ov 'gptel 'hide )
174
+ (propertize prefix 'face '(shadow default ))))))))))
177
175
(defun gptel--transient-read-number (prompt initial-input history )
178
176
" Read a numeric value from the minibuffer.
179
177
@@ -202,7 +200,7 @@ Handle formatting for system messages when the active
202
200
(propertize " ]" 'face 'transient-heading ))
203
201
(if message
204
202
(gptel--describe-directive
205
- message (max (- (window-width ) 12 ) 14 ) " ⮐ " )
203
+ message (max (- (window-width ) 12 ) 14 ) " ⏎ " )
206
204
" [No system message set]" )))
207
205
208
206
(defun gptel--tools-init-value (obj )
@@ -353,7 +351,7 @@ which see."
353
351
(len (length val)))
354
352
(ptv (concat
355
353
" \" " (string-replace
356
- " \n " " ⮐ "
354
+ " \n " " ⏎ "
357
355
(truncate-string-to-width
358
356
val 20 nil nil t ))
359
357
" \" " (when (> len 20 )
@@ -706,7 +704,7 @@ If EXTERNAL is non-nil, include external sources of directives."
706
704
(concat " (" (gptel--describe-directive prompt (- width 30 )) " )" )
707
705
'face 'shadow ))
708
706
`(lambda () (interactive )
709
- (message " %s : %s " , msg ,(gptel--describe-directive prompt 100 " ⮐ " ))
707
+ (message " %s : %s " , msg ,(gptel--describe-directive prompt 100 " ⏎ " ))
710
708
(gptel--set-with-scope ', sym ', prompt gptel--set-buffer-locally))
711
709
:transient 'transient--do-return )
712
710
into prompt-suffixes
@@ -1076,19 +1074,18 @@ Or in an extended conversation:
1076
1074
:display-nil 'none
1077
1075
:overlay nil
1078
1076
:argument " :"
1079
- :prompt (concat " Add instructions for next request only "
1080
- gptel--read-with-prefix-help)
1077
+ :prompt " Instruction for next request: "
1081
1078
:reader (lambda (prompt initial history )
1082
1079
(let* ((directive
1083
1080
(car-safe (gptel--parse-directive gptel--system-message 'raw )))
1084
1081
(cycle-prefix (lambda () (interactive )
1085
- (gptel--read-with-prefix directive)))
1082
+ (gptel--read-with-prefix directive)))
1086
1083
(minibuffer-local-map
1087
1084
(make-composed-keymap
1088
1085
(define-keymap " TAB" cycle-prefix " <tab>" cycle-prefix)
1089
1086
minibuffer-local-map))
1090
1087
(extra (minibuffer-with-setup-hook cycle-prefix
1091
- (read-string prompt (or initial " " ) history ))))
1088
+ (read-string prompt nil history (or initial) ))))
1092
1089
(unless (string-empty-p extra) extra)))
1093
1090
:format " %k %d %v"
1094
1091
:key " d"
0 commit comments