Skip to content

Commit 60da3c4

Browse files
committed
Merge pull request #646 from geraldus/move-and-rename-utils
Rename prefix `hs-utils/` to `haskell-utils-`
2 parents c0855b4 + 19a0d17 commit 60da3c4

File tree

2 files changed

+42
-46
lines changed

2 files changed

+42
-46
lines changed

haskell-commands.el

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
(require 'haskell-session)
3333
(require 'highlight-uses-mode)
3434

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+
3541
;;;###autoload
3642
(defun haskell-process-restart ()
3743
"Restart the inferior Haskell process."
@@ -604,10 +610,6 @@ Query PROCESS to `:cd` to directory DIR."
604610
(string-match "^<interactive>" response))
605611
(haskell-mode-message-line response)))))))
606612

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-
611613
;;;###autoload
612614
(defun haskell-mode-show-type-at (&optional insert-value)
613615
"Show type of the thing at point or within active region asynchronously.
@@ -624,8 +626,8 @@ Optional argument INSERT-VALUE indicates that
624626
recieved type signature should be inserted (but only if nothing
625627
happened since function invocation)."
626628
(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))
629631
(process (haskell-interactive-process))
630632
(buf (current-buffer))
631633
(pos-reg (cons pos (region-active-p))))
@@ -637,7 +639,7 @@ happened since function invocation)."
637639
(lambda (state)
638640
(let* ((prc (car state))
639641
(req (nth 1 state)))
640-
(hs-utils/async-watch-changes)
642+
(haskell-utils-async-watch-changes)
641643
(haskell-process-send-string prc req)))
642644
:complete
643645
(lambda (state response)
@@ -647,8 +649,8 @@ happened since function invocation)."
647649
(wrap (cdr pos-reg))
648650
(min-pos (caar pos-reg))
649651
(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)))
652654

653655
(cl-case res-type
654656
;; neither popup presentation buffer
@@ -669,7 +671,7 @@ happened since function invocation)."
669671
(otherwise
670672
(if insert-value
671673
;; 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)
673675
(if wrap
674676
;; Handle region case
675677
(progn
@@ -679,9 +681,9 @@ happened since function invocation)."
679681
(goto-char min-pos)
680682
(insert (concat "(" sig ")"))))
681683
;; Non-region cases
682-
(hs-utils/insert-type-signature sig))
684+
(haskell-utils-insert-type-signature sig))
683685
;; 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))
685687
(cs (format "%s" (cdr rev))))
686688
(message
687689
(concat
@@ -692,9 +694,9 @@ happened since function invocation)."
692694
;; insert result
693695
(let* ((expr (car (split-string sig "\\W::\\W" t)))
694696
(buf-name (concat ":type " expr)))
695-
(hs-utils/echo-or-present response buf-name))))
697+
(haskell-utils-echo-or-present response buf-name))))
696698

697-
(hs-utils/async-stop-watching-changes init-buffer))))))))
699+
(haskell-utils-async-stop-watching-changes init-buffer))))))))
698700

699701
;;;###autoload
700702
(defun haskell-process-generate-tags (&optional and-then-find-this-tag)
@@ -912,7 +914,7 @@ Requires the :uses command from GHCi."
912914
(error (propertize "No reply. Is :uses supported?"
913915
'face 'compilation-error)))))))
914916

915-
(defun hs-utils/capture-expr-bounds ()
917+
(defun haskell-utils-capture-expr-bounds ()
916918
"Capture position bounds of expression at point.
917919
If there is an active region then it returns region
918920
bounds. Otherwise it uses `haskell-spanable-pos-at-point` to
@@ -925,7 +927,7 @@ to point."
925927
(haskell-spanable-pos-at-point)
926928
(cons (point) (point))))
927929

928-
(defun hs-utils/compose-type-at-command (pos)
930+
(defun haskell-utils-compose-type-at-command (pos)
929931
"Prepare :type-at command to be send to haskell process.
930932
POS is a cons cell containing min and max positions, i.e. target
931933
expression bounds."
@@ -943,14 +945,7 @@ expression bounds."
943945
(buffer-substring-no-properties (car pos)
944946
(cdr pos)))))
945947

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)
954949
"Insert type signature.
955950
In case of active region is present, wrap it by parentheses and
956951
append SIGNATURE to original expression. Otherwise tries to
@@ -959,14 +954,14 @@ newlines and extra whitespace in signature before insertion."
959954
(let* ((ident-pos (or (haskell-ident-pos-at-point)
960955
(cons (point) (point))))
961956
(min-pos (car ident-pos))
962-
(sig (hs-utils/reduce-string signature)))
957+
(sig (haskell-utils-reduce-string signature)))
963958
(save-excursion
964959
(goto-char min-pos)
965960
(let ((col (current-column)))
966961
(insert sig "\n")
967962
(indent-to col)))))
968963

969-
(defun hs-utils/echo-or-present (msg &optional name)
964+
(defun haskell-utils-echo-or-present (msg &optional name)
970965
"Present message in some manner depending on configuration.
971966
If variable `haskell-process-use-presentation-mode' is NIL it will output
972967
modified message MSG to echo area.
@@ -975,40 +970,47 @@ Optinal NAME will be used as presentation mode buffer name."
975970
(let ((bufname (or name "*Haskell Presentation*"))
976971
(session (haskell-process-session (haskell-interactive-process))))
977972
(haskell-present bufname session msg))
978-
(let (m (hs-utils/reduce-string msg))
973+
(let (m (haskell-utils-reduce-string msg))
979974
(message m))))
980975

981-
(defun hs-utils/async-update-post-command-flag ()
976+
(defun haskell-utils-async-update-post-command-flag ()
982977
"A special hook which collects triggered commands during async execution.
983978
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'."
985980
(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)))
988983

989-
(defun hs-utils/async-watch-changes ()
984+
(defun haskell-utils-async-watch-changes ()
990985
"Watch for triggered commands during async operation execution.
991986
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
993988
assumed that nothing happened, e.g. nothing was inserted in
994989
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)
996991
(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))
998993

999-
(defun hs-utils/async-stop-watching-changes (buffer)
994+
(defun haskell-utils-async-stop-watching-changes (buffer)
1000995
"Clean up after async operation finished.
1001996
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
1003998
`post-command-hook' should be disabled. This is neccessary, because
1004999
it is possible that user will change buffer during async function
10051000
execusion."
10061001
(with-current-buffer buffer
1007-
(setq hs-utils/async-post-command-flag nil)
1002+
(setq haskell-utils-async-post-command-flag nil)
10081003
(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_)))
10101012

1011-
(defun hs-utils/parse-repl-response (r)
1013+
(defun haskell-utils-parse-repl-response (r)
10121014
"Parse response R from REPL and return special kind of result.
10131015
The result is response string itself with speacial property
10141016
response-type added.
@@ -1028,8 +1030,5 @@ This property could be of the following:
10281030
((string-match-p "^<interactive>:" first-line) 'interactive-error)
10291031
(t 'success))))
10301032

1031-
1032-
1033-
10341033
(provide 'haskell-commands)
10351034
;;; haskell-commands.el ends here

haskell-utils.el

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ DEFAULT."
5050
(concat (replace-regexp-in-string "/$" "" filename)
5151
"/")))
5252

53-
5453
(defun haskell-utils-parse-import-statement-at-point ()
5554
"Return imported module name if on import statement or nil otherwise.
5655
This currently assumes that the \"import\" keyword and the module
@@ -68,7 +67,5 @@ Note: doesn't detect if in {--}-style comment."
6867
"\\([[:digit:][:upper:][:lower:]_.]+\\)"))
6968
(match-string-no-properties 1))))
7069

71-
7270
(provide 'haskell-utils)
73-
7471
;;; haskell-utils.el ends here

0 commit comments

Comments
 (0)