32
32
(require 'haskell-session )
33
33
(require 'highlight-uses-mode )
34
34
35
+
36
+ (defvar haskell-utils-async-post-command-flag nil
37
+ " Non-nil means some commands were triggered during async function execution." )
38
+ (make-variable-buffer-local 'haskell-utils-async-post-command-flag )
39
+
40
+
35
41
;;;### autoload
36
42
(defun haskell-process-restart ()
37
43
" Restart the inferior Haskell process."
@@ -604,10 +610,6 @@ Query PROCESS to `:cd` to directory DIR."
604
610
(string-match " ^<interactive>" response))
605
611
(haskell-mode-message-line response)))))))
606
612
607
- (defvar hs-utils/async-post-command-flag nil
608
- " Non-nil means some commands were triggered during async function execution." )
609
- (make-variable-buffer-local 'hs-utils/async-post-command-flag )
610
-
611
613
;;;### autoload
612
614
(defun haskell-mode-show-type-at (&optional insert-value )
613
615
" Show type of the thing at point or within active region asynchronously.
@@ -624,8 +626,8 @@ Optional argument INSERT-VALUE indicates that
624
626
recieved type signature should be inserted (but only if nothing
625
627
happened since function invocation)."
626
628
(interactive " P" )
627
- (let* ((pos (hs -utils/ capture-expr-bounds))
628
- (req (hs -utils/ compose-type-at-command pos))
629
+ (let* ((pos (haskell -utils- capture-expr-bounds))
630
+ (req (haskell -utils- compose-type-at-command pos))
629
631
(process (haskell-interactive-process))
630
632
(buf (current-buffer ))
631
633
(pos-reg (cons pos (region-active-p ))))
@@ -637,7 +639,7 @@ happened since function invocation)."
637
639
(lambda (state )
638
640
(let* ((prc (car state))
639
641
(req (nth 1 state)))
640
- (hs -utils/ async-watch-changes)
642
+ (haskell -utils- async-watch-changes)
641
643
(haskell-process-send-string prc req)))
642
644
:complete
643
645
(lambda (state response )
@@ -647,8 +649,8 @@ happened since function invocation)."
647
649
(wrap (cdr pos-reg))
648
650
(min-pos (caar pos-reg))
649
651
(max-pos (cdar pos-reg))
650
- (sig (hs -utils/ reduce-string response))
651
- (res-type (hs -utils/ parse-repl-response sig)))
652
+ (sig (haskell -utils- reduce-string response))
653
+ (res-type (haskell -utils- parse-repl-response sig)))
652
654
653
655
(cl-case res-type
654
656
; ; neither popup presentation buffer
@@ -669,7 +671,7 @@ happened since function invocation)."
669
671
(otherwise
670
672
(if insert-value
671
673
; ; Only insert type signature and do not present it
672
- (if (= (length hs -utils/ async-post-command-flag) 1 )
674
+ (if (= (length haskell -utils- async-post-command-flag) 1 )
673
675
(if wrap
674
676
; ; Handle region case
675
677
(progn
@@ -679,9 +681,9 @@ happened since function invocation)."
679
681
(goto-char min-pos)
680
682
(insert (concat " (" sig " )" ))))
681
683
; ; Non-region cases
682
- (hs -utils/ insert-type-signature sig))
684
+ (haskell -utils- insert-type-signature sig))
683
685
; ; Some commands registered, prevent insertion
684
- (let* ((rev (reverse hs -utils/ async-post-command-flag))
686
+ (let* ((rev (reverse haskell -utils- async-post-command-flag))
685
687
(cs (format " %s " (cdr rev))))
686
688
(message
687
689
(concat
@@ -692,9 +694,9 @@ happened since function invocation)."
692
694
; ; insert result
693
695
(let* ((expr (car (split-string sig " \\ W::\\ W" t )))
694
696
(buf-name (concat " :type " expr)))
695
- (hs -utils/ echo-or-present response buf-name))))
697
+ (haskell -utils- echo-or-present response buf-name))))
696
698
697
- (hs -utils/ async-stop-watching-changes init-buffer))))))))
699
+ (haskell -utils- async-stop-watching-changes init-buffer))))))))
698
700
699
701
;;;### autoload
700
702
(defun haskell-process-generate-tags (&optional and-then-find-this-tag )
@@ -912,7 +914,7 @@ Requires the :uses command from GHCi."
912
914
(error (propertize " No reply. Is :uses supported?"
913
915
'face 'compilation-error )))))))
914
916
915
- (defun hs -utils/ capture-expr-bounds ()
917
+ (defun haskell -utils- capture-expr-bounds ()
916
918
" Capture position bounds of expression at point.
917
919
If there is an active region then it returns region
918
920
bounds. Otherwise it uses `haskell-spanable-pos-at-point` to
@@ -925,7 +927,7 @@ to point."
925
927
(haskell-spanable-pos-at-point)
926
928
(cons (point ) (point ))))
927
929
928
- (defun hs -utils/ compose-type-at-command (pos )
930
+ (defun haskell -utils- compose-type-at-command (pos )
929
931
" Prepare :type-at command to be send to haskell process.
930
932
POS is a cons cell containing min and max positions, i.e. target
931
933
expression bounds."
@@ -943,14 +945,7 @@ expression bounds."
943
945
(buffer-substring-no-properties (car pos)
944
946
(cdr pos)))))
945
947
946
- (defun hs-utils/reduce-string (s )
947
- " Remove newlines ans extra whitespace from S.
948
- Removes all extra whitespace at the beginning of each line leaving
949
- only single one. Then removes all newlines."
950
- (let ((s_ (replace-regexp-in-string " ^\s +" " " s)))
951
- (replace-regexp-in-string " \n " " " s_)))
952
-
953
- (defun hs-utils/insert-type-signature (signature )
948
+ (defun haskell-utils-insert-type-signature (signature )
954
949
" Insert type signature.
955
950
In case of active region is present, wrap it by parentheses and
956
951
append SIGNATURE to original expression. Otherwise tries to
@@ -959,14 +954,14 @@ newlines and extra whitespace in signature before insertion."
959
954
(let* ((ident-pos (or (haskell-ident-pos-at-point)
960
955
(cons (point ) (point ))))
961
956
(min-pos (car ident-pos))
962
- (sig (hs -utils/ reduce-string signature)))
957
+ (sig (haskell -utils- reduce-string signature)))
963
958
(save-excursion
964
959
(goto-char min-pos)
965
960
(let ((col (current-column )))
966
961
(insert sig " \n " )
967
962
(indent-to col)))))
968
963
969
- (defun hs -utils/ echo-or-present (msg &optional name )
964
+ (defun haskell -utils- echo-or-present (msg &optional name )
970
965
" Present message in some manner depending on configuration.
971
966
If variable `haskell-process-use-presentation-mode' is NIL it will output
972
967
modified message MSG to echo area.
@@ -975,40 +970,47 @@ Optinal NAME will be used as presentation mode buffer name."
975
970
(let ((bufname (or name " *Haskell Presentation*" ))
976
971
(session (haskell-process-session (haskell-interactive-process))))
977
972
(haskell-present bufname session msg))
978
- (let (m (hs -utils/ reduce-string msg))
973
+ (let (m (haskell -utils- reduce-string msg))
979
974
(message m))))
980
975
981
- (defun hs -utils/ async-update-post-command-flag ()
976
+ (defun haskell -utils- async-update-post-command-flag ()
982
977
" A special hook which collects triggered commands during async execution.
983
978
This hook pushes value of variable `this-command' to flag variable
984
- `hs -utils/ async-post-command-flag' ."
979
+ `haskell -utils- async-post-command-flag' ."
985
980
(let* ((cmd this-command)
986
- (updated-flag (cons cmd hs -utils/ async-post-command-flag)))
987
- (setq hs -utils/ async-post-command-flag updated-flag)))
981
+ (updated-flag (cons cmd haskell -utils- async-post-command-flag)))
982
+ (setq haskell -utils- async-post-command-flag updated-flag)))
988
983
989
- (defun hs -utils/ async-watch-changes ()
984
+ (defun haskell -utils- async-watch-changes ()
990
985
" Watch for triggered commands during async operation execution.
991
986
Resets flag variable
992
- `hs -utils/ async-update-post-command-flag' to NIL. By chanhges it is
987
+ `haskell -utils- async-update-post-command-flag' to NIL. By chanhges it is
993
988
assumed that nothing happened, e.g. nothing was inserted in
994
989
buffer, point was not moved, etc. To collect data `post-command-hook' is used."
995
- (setq hs -utils/ async-post-command-flag nil )
990
+ (setq haskell -utils- async-post-command-flag nil )
996
991
(add-hook
997
- 'post-command-hook #'hs -utils/ async-update-post-command-flag nil t ))
992
+ 'post-command-hook #'haskell -utils- async-update-post-command-flag nil t ))
998
993
999
- (defun hs -utils/ async-stop-watching-changes (buffer )
994
+ (defun haskell -utils- async-stop-watching-changes (buffer )
1000
995
" Clean up after async operation finished.
1001
996
This function takes care about cleaning up things made by
1002
- `hs -utils/ async-watch-changes' . The BUFFER argument is a buffer where
997
+ `haskell -utils- async-watch-changes' . The BUFFER argument is a buffer where
1003
998
`post-command-hook' should be disabled. This is neccessary, because
1004
999
it is possible that user will change buffer during async function
1005
1000
execusion."
1006
1001
(with-current-buffer buffer
1007
- (setq hs -utils/ async-post-command-flag nil )
1002
+ (setq haskell -utils- async-post-command-flag nil )
1008
1003
(remove-hook
1009
- 'post-command-hook #'hs-utils/async-update-post-command-flag t )))
1004
+ 'post-command-hook #'haskell-utils-async-update-post-command-flag t )))
1005
+
1006
+ (defun haskell-utils-reduce-string (s )
1007
+ " Remove newlines ans extra whitespace from S.
1008
+ Removes all extra whitespace at the beginning of each line leaving
1009
+ only single one. Then removes all newlines."
1010
+ (let ((s_ (replace-regexp-in-string " ^\s +" " " s)))
1011
+ (replace-regexp-in-string " \n " " " s_)))
1010
1012
1011
- (defun hs -utils/ parse-repl-response (r )
1013
+ (defun haskell -utils- parse-repl-response (r )
1012
1014
" Parse response R from REPL and return special kind of result.
1013
1015
The result is response string itself with speacial property
1014
1016
response-type added.
@@ -1028,8 +1030,5 @@ This property could be of the following:
1028
1030
((string-match-p " ^<interactive>:" first-line) 'interactive-error )
1029
1031
(t 'success ))))
1030
1032
1031
-
1032
-
1033
-
1034
1033
(provide 'haskell-commands )
1035
1034
; ;; haskell-commands.el ends here
0 commit comments