@@ -202,6 +202,23 @@ to the boolean contained in the json returned by the client"
202
202
(setq learn-ocaml-use-passwd t )
203
203
(setq learn-ocaml-use-passwd nil )))
204
204
205
+ (defun learn-ocaml-since-upto (since upto )
206
+ " Return (SINCE . UPTO) with args possibly nil, denoting (SINCE <= v < UPTO).
207
+ Both SINCE and UPTO should be valid version strings."
208
+ (unless (or (stringp since) (null since))
209
+ (error " SINCE must be a string " ))
210
+ (unless (or (stringp upto) (null upto))
211
+ (error " UPTO must be a string " ))
212
+ (cons since upto))
213
+
214
+ (defun learn-ocaml-compat (pred-pair version )
215
+ " If PRED-PAIR is (since . upto), return (since <= VERSION < upto).
216
+ VERSION should be a list-based version, use `version-to-list' if need be.
217
+ See also `learn-ocaml-since-upto' ."
218
+ (let ((since (car pred-pair)) (upto (cdr pred-pair)))
219
+ (and (if since (version-list-<= (version-to-list since) version) t )
220
+ (if upto (version-list-< version (version-to-list upto)) t ))))
221
+
205
222
; ;
206
223
; ; package.el shortcut
207
224
; ;
@@ -360,15 +377,27 @@ Raise (error \"learn-ocaml-await-for...\") if `learn-ocaml-timeout' exceeded."
360
377
(string-trim
361
378
(cdr (learn-ocaml-command-to-string-await-cmd (list " --version" )))))
362
379
363
- (defun learn-ocaml-client-server-version ()
364
- " Run \" learn-ocaml-client server-version\" ."
365
- ; ; TODO/FIXME: Update when possible
366
- (learn-ocaml-client-version))
380
+ (defconst learn-ocaml-client-server-min-version-compat
381
+ (learn-ocaml-since-upto " 0.13.0" nil ))
367
382
368
- (defun learn-ocaml-client-server-min-version ()
383
+ ; ; (learn-ocaml-client-server-min-version
384
+ ; ; (learn-ocaml-client-server-min-version "http://localhost:8080")
385
+ (defun learn-ocaml-client-server-min-version (&optional server )
369
386
" Return the min of the learn-ocaml server and learn-ocaml-client versions."
370
- ; ; TODO/FIXME: Update when possible, "learn-ocaml-client server-version --min"
371
- (learn-ocaml-client-version))
387
+ (let* ((client (learn-ocaml-client-version))
388
+ (command (list " server-version" " --min" ))
389
+ (version-string
390
+ (if (learn-ocaml-compat learn-ocaml-client-server-min-version-compat
391
+ (version-to-list client))
392
+ ; ; TODO: Take errors into account in a better way,
393
+ ; ; instead of waiting that `version-to-list' fails
394
+ (string-trim (cdr (learn-ocaml-command-to-string-await-cmd
395
+ (if server (append command
396
+ (list " -s" server))
397
+ command))))
398
+ client))
399
+ (_check (version-to-list version-string)))
400
+ version-string))
372
401
373
402
; ;
374
403
; ; Higher-order functions, sentinels of the make-process wrapper
@@ -1130,6 +1159,9 @@ If TOKEN is \"\", interactively ask a token."
1130
1159
:secret secret
1131
1160
:callback rich-callback)))))))
1132
1161
1162
+ (defconst learn-ocaml-feature-passwd-compat
1163
+ (learn-ocaml-since-upto " 0.15.0" nil ))
1164
+
1133
1165
(defun learn-ocaml-on-load (callback )
1134
1166
" Call `learn-ocaml-login-with-token' and CALLBACK when loading mode."
1135
1167
(learn-ocaml-give-server-cmd
@@ -1141,19 +1173,19 @@ If TOKEN is \"\", interactively ask a token."
1141
1173
(progn (message-box " No server found. Please enter the server url." )
1142
1174
(read-string " Enter server URL: " " https://" ))
1143
1175
server)))
1144
- ( if ( version-list-<
1145
- ; ; https://github.com/pfitaxel/ learn-ocaml.el/pull/26#pullrequestreview-758063532
1146
- (version-to-list (learn-ocaml-client-server-min-version))
1147
- ( version-to-list " 0.15.0 " ))
1148
- (learn-ocaml-login-with-token token new- server-value callback)
1149
- ( progn (learn-ocaml-init- server-cmd
1150
- :server new-server-value
1151
- :callback
1152
- ( lambda ( _ )
1153
- (learn-ocaml-server-config ( learn-ocaml-client-config-cmd))
1154
- ( if learn-ocaml-use- passwd
1155
- (learn-ocaml-login-possibly- with-passwd new-server-value callback)
1156
- (learn-ocaml-login-with-token token new-server-value callback)))) ))))))))
1176
+ ; ; https://github.com/pfitaxel/learn-ocaml.el/pull/26#pullrequestreview-758063532
1177
+ ( if (learn-ocaml-compat learn-ocaml-feature-passwd-compat
1178
+ (version-to-list
1179
+ (learn-ocaml-client-server-min-version new-server-value) ))
1180
+ (progn ( learn-ocaml-init- server-cmd
1181
+ :server new- server-value
1182
+ :callback
1183
+ ( lambda ( _ )
1184
+ (learn-ocaml-server-config (learn-ocaml-client-config-cmd) )
1185
+ ( if learn-ocaml-use-passwd
1186
+ ( learn-ocaml-login-possibly-with- passwd new-server-value callback)
1187
+ (learn-ocaml-login-with-token token new-server-value callback)))) )
1188
+ (learn-ocaml-login-with-token token new-server-value callback))))))))
1157
1189
1158
1190
(defun learn-ocaml-logout ()
1159
1191
" Logout the user from the server by removing the token from the file client.json"
0 commit comments