Skip to content

Commit c27b9bc

Browse files
committed
Support inserting type signature for local declarations or selected expressions
1 parent 0dd5055 commit c27b9bc

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

haskell-commands.el

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,27 @@ command from GHCi."
616616
(defun haskell-mode-show-type-at (&optional insert-value)
617617
"Show the type of the thing at point."
618618
(interactive "P")
619-
(let ((ty (haskell-mode-type-at)))
619+
(let ((ty (haskell-mode-type-at))
620+
(orig (point)))
620621
(if insert-value
621-
(progn (goto-char (line-beginning-position))
622-
(insert (haskell-fontify-as-mode ty 'haskell-mode)
623-
"\n"))
622+
(let ((ident-pos (haskell-ident-pos-at-point)))
623+
(cond
624+
((region-active-p)
625+
(delete-region (region-beginning)
626+
(region-end))
627+
(insert "(" ty ")")
628+
(goto-char (1+ orig)))
629+
((= (line-beginning-position) (car ident-pos))
630+
(goto-char (line-beginning-position))
631+
(insert (haskell-fontify-as-mode ty 'haskell-mode)
632+
"\n"))
633+
(t
634+
(save-excursion
635+
(let ((col (save-excursion (goto-char (car ident-pos))
636+
(current-column))))
637+
(save-excursion (insert "\n")
638+
(indent-to col))
639+
(insert (haskell-fontify-as-mode ty 'haskell-mode)))))))
624640
(message "%s" (haskell-fontify-as-mode ty 'haskell-mode)))))
625641

626642
(defun haskell-process-generate-tags (&optional and-then-find-this-tag)

0 commit comments

Comments
 (0)