31
31
(require 'haskell-interactive-mode )
32
32
(require 'haskell-session )
33
33
(require 'haskell-presentation-mode )
34
+ (require 'haskell-utils )
34
35
(require 'highlight-uses-mode )
35
36
36
-
37
- (defvar haskell-utils-async-post-command-flag nil
38
- " Non-nil means some commands were triggered during async function execution." )
39
- (make-variable-buffer-local 'haskell-utils-async-post-command-flag )
40
-
41
-
42
37
;;;### autoload
43
38
(defun haskell-process-restart ()
44
39
" Restart the inferior Haskell process."
@@ -627,7 +622,7 @@ Optional argument INSERT-VALUE indicates that
627
622
recieved type signature should be inserted (but only if nothing
628
623
happened since function invocation)."
629
624
(interactive " P" )
630
- (let* ((pos (haskell-utils -capture-expr-bounds))
625
+ (let* ((pos (haskell-command -capture-expr-bounds))
631
626
(req (haskell-utils-compose-type-at-command pos))
632
627
(process (haskell-interactive-process))
633
628
(buf (current-buffer ))
@@ -682,7 +677,7 @@ happened since function invocation)."
682
677
(goto-char min-pos)
683
678
(insert (concat " (" sig " )" ))))
684
679
; ; Non-region cases
685
- (haskell-utils -insert-type-signature sig))
680
+ (haskell-command -insert-type-signature sig))
686
681
; ; Some commands registered, prevent insertion
687
682
(let* ((rev (reverse haskell-utils-async-post-command-flag))
688
683
(cs (format " %s " (cdr rev))))
@@ -693,7 +688,7 @@ happened since function invocation)."
693
688
cs))))
694
689
; ; Present the result only when response is valid and not asked
695
690
; ; to insert result
696
- (haskell-utils -echo-or-present response)))
691
+ (haskell-command -echo-or-present response)))
697
692
698
693
(haskell-utils-async-stop-watching-changes init-buffer))))))))
699
694
@@ -913,7 +908,17 @@ Requires the :uses command from GHCi."
913
908
(error (propertize " No reply. Is :uses supported?"
914
909
'face 'compilation-error )))))))
915
910
916
- (defun haskell-utils-capture-expr-bounds ()
911
+ (defun haskell-command-echo-or-present (msg )
912
+ " Present message in some manner depending on configuration.
913
+ If variable `haskell-process-use-presentation-mode' is NIL it will output
914
+ modified message MSG to echo area."
915
+ (if haskell-process-use-presentation-mode
916
+ (let ((session (haskell-process-session (haskell-interactive-process))))
917
+ (haskell-presentation-present session msg))
918
+ (let ((m (haskell-utils-reduce-string msg)))
919
+ (message m))))
920
+
921
+ (defun haskell-command-capture-expr-bounds ()
917
922
" Capture position bounds of expression at point.
918
923
If there is an active region then it returns region
919
924
bounds. Otherwise it uses `haskell-spanable-pos-at-point` to
@@ -926,43 +931,7 @@ to point."
926
931
(haskell-spanable-pos-at-point)
927
932
(cons (point ) (point ))))
928
933
929
- (defun haskell-utils-compose-type-at-command (pos )
930
- " Prepare :type-at command to be send to haskell process.
931
- POS is a cons cell containing min and max positions, i.e. target
932
- expression bounds."
933
- (save-excursion
934
- (let ((start-p (car pos))
935
- (end-p (cdr pos))
936
- start-l
937
- start-c
938
- end-l
939
- end-c
940
- value)
941
- (goto-char start-p)
942
- (setq start-l (line-number-at-pos ))
943
- (setq start-c (1+ (current-column )))
944
- (goto-char end-p)
945
- (setq end-l (line-number-at-pos ))
946
- (setq end-c (1+ (current-column )))
947
- (setq value (buffer-substring-no-properties start-p end-p))
948
- ; ; supress multiline expressions
949
- (let ((lines (split-string value " \n " t )))
950
- (when (and (cdr lines)
951
- (stringp (car lines)))
952
- (setq value (format " [ %s … ] " (car lines)))))
953
- (replace-regexp-in-string
954
- " \n $"
955
- " "
956
- (format " :type-at %s %d %d %d %d %s "
957
- (buffer-file-name )
958
- start-l
959
- start-c
960
- end-l
961
- end-c
962
- value)))))
963
-
964
-
965
- (defun haskell-utils-insert-type-signature (signature )
934
+ (defun haskell-command-insert-type-signature (signature )
966
935
" Insert type signature.
967
936
In case of active region is present, wrap it by parentheses and
968
937
append SIGNATURE to original expression. Otherwise tries to
@@ -978,72 +947,5 @@ newlines and extra whitespace in signature before insertion."
978
947
(insert sig " \n " )
979
948
(indent-to col)))))
980
949
981
- (defun haskell-utils-echo-or-present (msg )
982
- " Present message in some manner depending on configuration.
983
- If variable `haskell-process-use-presentation-mode' is NIL it will output
984
- modified message MSG to echo area."
985
- (if haskell-process-use-presentation-mode
986
- (let ((session (haskell-process-session (haskell-interactive-process))))
987
- (haskell-presentation-present session msg))
988
- (let ((m (haskell-utils-reduce-string msg)))
989
- (message m))))
990
-
991
- (defun haskell-utils-async-update-post-command-flag ()
992
- " A special hook which collects triggered commands during async execution.
993
- This hook pushes value of variable `this-command' to flag variable
994
- `haskell-utils-async-post-command-flag' ."
995
- (let* ((cmd this-command)
996
- (updated-flag (cons cmd haskell-utils-async-post-command-flag)))
997
- (setq haskell-utils-async-post-command-flag updated-flag)))
998
-
999
- (defun haskell-utils-async-watch-changes ()
1000
- " Watch for triggered commands during async operation execution.
1001
- Resets flag variable
1002
- `haskell-utils-async-update-post-command-flag' to NIL. By chanhges it is
1003
- assumed that nothing happened, e.g. nothing was inserted in
1004
- buffer, point was not moved, etc. To collect data `post-command-hook' is used."
1005
- (setq haskell-utils-async-post-command-flag nil )
1006
- (add-hook
1007
- 'post-command-hook #'haskell-utils-async-update-post-command-flag nil t ))
1008
-
1009
- (defun haskell-utils-async-stop-watching-changes (buffer )
1010
- " Clean up after async operation finished.
1011
- This function takes care about cleaning up things made by
1012
- `haskell-utils-async-watch-changes' . The BUFFER argument is a buffer where
1013
- `post-command-hook' should be disabled. This is neccessary, because
1014
- it is possible that user will change buffer during async function
1015
- execusion."
1016
- (with-current-buffer buffer
1017
- (setq haskell-utils-async-post-command-flag nil )
1018
- (remove-hook
1019
- 'post-command-hook #'haskell-utils-async-update-post-command-flag t )))
1020
-
1021
- (defun haskell-utils-reduce-string (s )
1022
- " Remove newlines ans extra whitespace from S.
1023
- Removes all extra whitespace at the beginning of each line leaving
1024
- only single one. Then removes all newlines."
1025
- (let ((s_ (replace-regexp-in-string " ^\s +" " " s)))
1026
- (replace-regexp-in-string " \n " " " s_)))
1027
-
1028
- (defun haskell-utils-parse-repl-response (r )
1029
- " Parse response R from REPL and return special kind of result.
1030
- The result is response string itself with speacial property
1031
- response-type added.
1032
-
1033
- This property could be of the following:
1034
-
1035
- + unknown-command
1036
- + option-missing
1037
- + interactive-error
1038
- + success"
1039
- (let ((first-line (car (split-string r " \n " ))))
1040
- (cond
1041
- ((string-match-p " ^unknown command" first-line) 'unknown-command )
1042
- ((string-match-p " ^Couldn't guess that module name. Does it exist?"
1043
- first-line)
1044
- 'option-missing )
1045
- ((string-match-p " ^<interactive>:" first-line) 'interactive-error )
1046
- (t 'success ))))
1047
-
1048
950
(provide 'haskell-commands )
1049
951
; ;; haskell-commands.el ends here
0 commit comments