Skip to content

Commit 1616b8f

Browse files
committed
Preserve point position in haskell-utils-compose-type-at-command
Related to issue #700
1 parent 8c6662d commit 1616b8f

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

haskell-commands.el

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -930,19 +930,32 @@ to point."
930930
"Prepare :type-at command to be send to haskell process.
931931
POS is a cons cell containing min and max positions, i.e. target
932932
expression bounds."
933-
(replace-regexp-in-string
934-
"\n$"
935-
""
936-
(format ":type-at %s %d %d %d %d %s"
937-
(buffer-file-name)
938-
(progn (goto-char (car pos))
939-
(line-number-at-pos))
940-
(1+ (current-column))
941-
(progn (goto-char (cdr pos))
942-
(line-number-at-pos))
943-
(1+ (current-column))
944-
(buffer-substring-no-properties (car pos)
945-
(cdr pos)))))
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+
(replace-regexp-in-string
949+
"\n$"
950+
""
951+
(format ":type-at %s %d %d %d %d %s"
952+
(buffer-file-name)
953+
start-l
954+
start-c
955+
end-l
956+
end-c
957+
value)))))
958+
946959

947960
(defun haskell-utils-insert-type-signature (signature)
948961
"Insert type signature.

0 commit comments

Comments
 (0)