@@ -614,6 +614,10 @@ command from GHCi."
614
614
(string-match " ^<interactive>" response))
615
615
(haskell-mode-message-line response)))))))
616
616
617
+ (defvar hs-utils/async-post-command-flag nil
618
+ " Non-nil means some commands were triggered during async function execution." )
619
+ (make-variable-buffer-local 'hs-utils/async-post-command-flag )
620
+
617
621
;;;### autoload
618
622
(defun haskell-mode-show-type-at (&optional insert-value )
619
623
" Show the type of the thing at point."
@@ -921,4 +925,35 @@ Optinal NAME will be used as presentation mode buffer name."
921
925
(haskell-present bufname session msg))
922
926
(let (m (hs-utils/reduce-string msg))
923
927
(message m))))
928
+
929
+ (defun hs-utils/async-update-post-command-flag ()
930
+ " A special hook which collects triggered commands during async execution.
931
+ This hook pushes value of variable `this-command' to flag variable
932
+ `hs-utils/async-post-command-flag' ."
933
+ (let* ((cmd this-command)
934
+ (updated-flag (cons cmd hs-utils/async-post-command-flag)))
935
+ (setq hs-utils/async-post-command-flag updated-flag)))
936
+
937
+ (defun hs-utils/async-watch-changes ()
938
+ " Watch for triggered commands during async operation execution.
939
+ Resets flag variable
940
+ `hs-utils/async-update-post-command-flag' to NIL. By chanhges it is
941
+ assumed that nothing happened, e.g. nothing was inserted in
942
+ buffer, point was not moved, etc. To collect data `post-command-hook' is used."
943
+ (setq hs-utils/async-post-command-flag nil )
944
+ (add-hook
945
+ 'post-command-hook #'hs-utils/async-update-post-command-flag nil t ))
946
+
947
+ (defun hs-utils/async-stop-watching-changes (buffer )
948
+ " Clean up after async operation finished.
949
+ This function takes care about cleaning up things made by
950
+ `hs-utils/async-watch-changes' . The BUFFER argument is a buffer where
951
+ `post-command-hook' should be disabled. This is neccessary, because
952
+ it is possible that user will change buffer during async function
953
+ execusion."
954
+ (with-current-buffer buffer
955
+ (setq hs-utils/async-post-command-flag nil )
956
+ (remove-hook
957
+ 'post-command-hook #'hs-utils/async-update-post-command-flag t )))
958
+
924
959
(provide 'haskell-commands )
0 commit comments