Enable so-long during Qt file open

ober

e3eae9e757a50187d03ddf466bd7226066ddb16c

diff --git a/src/jerboa-emacs/qt/app.ss b/src/jerboa-emacs/qt/app.ss
index 750a1b7..9c17b64 100644
--- a/src/jerboa-emacs/qt/app.ss
+++ b/src/jerboa-emacs/qt/app.ss
@@ -2541,7 +2541,9 @@
                    (when (eq? (qt-current-buffer (app-state-frame app)) target-buf)
                      (qt-plain-text-edit-set-cursor-position! ed 0))))
                (file-mtime-record! filename)
-               (qt-setup-highlighting! app buf)
+               (let ((so-long? (and text (check-so-long! app buf text))))
+                 (unless so-long?
+                   (qt-setup-highlighting! app buf)))
                (let ((mode (detect-major-mode filename)))
                  (when mode
                    (buffer-local-set! buf 'major-mode mode)
diff --git a/tests/test-qt-part2.ss b/tests/test-qt-part2.ss
index 485a433..453abd8 100644
--- a/tests/test-qt-part2.ss
+++ b/tests/test-qt-part2.ss
@@ -17,7 +17,7 @@
         (jerboa-emacs snippets)
         (jerboa-emacs qt sci-shim)
         (jerboa-emacs qt window)
-        (only (jerboa-emacs qt app) qt-call-with-key-handler-errors)
+        (only (jerboa-emacs qt app) qt-call-with-key-handler-errors qt-open-file!)
         (only (jerboa-emacs qt echo)
               qt-minibuffer-history-reset!
               qt-minibuffer-history-record!
@@ -73,6 +73,8 @@
        (unless (pred got)
          (error 'check
                 (format "~a: predicate failed for ~a" *test-name* got))))]))
+(define (sleep-ms ms)
+  (sleep (make-time 'time-duration (* ms 1000000) 0)))
 
 (unless (getenv "QT_QPA_PLATFORM")
   (setenv "QT_QPA_PLATFORM" "offscreen"))
@@ -104,7 +106,7 @@
       (loop (+ i 1)
             (cons (string-append "line " (number->string i) "\n") acc)))))
 
-(display "\n=== Qt Part2 Groups 44-58 ===\n")
+(display "\n=== Qt Part2 Groups 44-59 ===\n")
 
 (test-case "group44 qt key/mouse fidelity"
   (check (qt-key-event->string QT_KEY_RETURN 0 "") => "C-m")
@@ -248,10 +250,40 @@
   (check (qt-minibuffer-history-select "part2-58-a" "draft" 1) => "draft")
   (qt-minibuffer-history-reset! "part2-58-b")
   (check (qt-minibuffer-history-select "part2-58-b" "" -1) => "omega"))
+(test-case "group59 qt-open-file enables so-long before highlighting"
+  (let ((old-threshold *so-long-threshold*)
+        (path "/tmp/jemacs-so-long-open-test.txt")
+        (loaded-buf #f))
+    (dynamic-wind
+      (lambda ()
+        (set! *so-long-threshold* 3)
+        (call-with-output-file path
+          (lambda (port) (display "xxxxx" port))
+          'replace))
+      (lambda ()
+        (let-values (((ed w app) (make-qt-test-app "part2-59")))
+          (qt-open-file! app path
+            (lambda (loaded-app buf)
+              (set! loaded-buf buf)))
+          (let loop ((n 0))
+            (when (and (not loaded-buf) (< n 100))
+              (sleep-ms 10)
+              (master-timer-tick!)
+              (loop (+ n 1))))
+          (unless loaded-buf
+            (error 'group59 "qt-open-file! load callback did not run"))
+          (unless (hash-get *so-long-buffers* (buffer-name loaded-buf))
+            (error 'group59 "qt-open-file! did not enable so-long"))))
+      (lambda ()
+        (set! *so-long-threshold* old-threshold)
+        (when loaded-buf
+          (hash-remove! *so-long-buffers* (buffer-name loaded-buf)))
+        (with-catch (lambda (e) #f)
+          (lambda () (delete-file path)))))))
 
 (newline)
 (let ([total (+ *pass* *fail*)])
-  (printf "Part2 results: ~a/~a tests passed (groups 44-58)~n" *pass* total)
+  (printf "Part2 results: ~a/~a tests passed (groups 44-59)~n" *pass* total)
   (when (> *fail* 0)
     (printf "FAILED: ~a test(s)~n" *fail*))
   (when (= *fail* 0)