Skip to content

Commit f73b1ce

Browse files
committed
Merge pull request #1195 from geraldus/g/fix-XXXX
Prevent automatic haskell-doc-mode actions when point in string or comment
2 parents d9fba6c + 96553c7 commit f73b1ce

File tree

1 file changed

+34
-46
lines changed

1 file changed

+34
-46
lines changed

haskell-doc.el

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,12 +1392,14 @@ is not."
13921392
This function is run by an idle timer to print the type
13931393
automatically if `haskell-doc-mode' is turned on."
13941394
(and haskell-doc-mode
1395+
(haskell-doc-in-code-p)
13951396
(not haskell-mode-interactive-prompt-state)
13961397
(not (eobp))
13971398
(not executing-kbd-macro)
13981399
;; Having this mode operate in the minibuffer makes it impossible to
13991400
;; see what you're doing.
14001401
(not (eq (selected-window) (minibuffer-window)))
1402+
;; not in string or comment
14011403
;; take a nap, if run straight from post-command-hook.
14021404
(if (fboundp 'run-with-idle-timer) t
14031405
(sit-for haskell-doc-idle-delay))
@@ -1416,12 +1418,11 @@ This function is run by an idle timer to print the type
14161418
Meant for `eldoc-documentation-function'."
14171419
;; There are a number of possible documentation functions.
14181420
;; Some of them are asynchronous.
1419-
(let ((msg (or
1420-
(haskell-doc-current-info--interaction)
1421-
(haskell-doc-sym-doc (haskell-ident-at-point)))))
1422-
(unless (symbolp msg) msg)))
1423-
1424-
1421+
(when (haskell-doc-in-code-p)
1422+
(let ((msg (or
1423+
(haskell-doc-current-info--interaction)
1424+
(haskell-doc-sym-doc (haskell-ident-at-point)))))
1425+
(unless (symbolp msg) msg))))
14251426

14261427
(defun haskell-doc-ask-mouse-for-type (event)
14271428
"Read the identifier under the mouse and echo its type.
@@ -1434,6 +1435,7 @@ function. Only the user interface is different."
14341435
(haskell-doc-show-type)))
14351436

14361437
(defun haskell-doc-in-code-p ()
1438+
"A predicate indicating suitable case to show docs."
14371439
(not (or (and (eq haskell-literate 'bird)
14381440
;; Copied from haskell-indent-bolp.
14391441
(<= (current-column) 2)
@@ -1442,7 +1444,7 @@ function. Only the user interface is different."
14421444

14431445
;;;###autoload
14441446
(defun haskell-doc-show-type (&optional sym)
1445-
"Show the type of the function near point.
1447+
"Show the type of the function near point or given symbol SYM.
14461448
For the function under point, show the type in the echo area.
14471449
This information is extracted from the `haskell-doc-prelude-types' alist
14481450
of prelude functions and their types, or from the local functions in the
@@ -1461,36 +1463,39 @@ current buffer."
14611463
(message "%s" doc))))))
14621464

14631465
(defvar haskell-doc-current-info--interaction-last nil
1464-
"If non-nil, a previous eldoc message from an async call, that
1465-
hasn't been displayed yet.")
1466+
"Async message stack.
1467+
If non-nil, a previous eldoc message from an async call, that
1468+
hasn't been displayed yet.")
14661469

14671470
(defun haskell-doc-current-info--interaction (&optional sync)
1468-
"Asynchronous call to `haskell-process-get-type', suitable for
1469-
use in the eldoc function `haskell-doc-current-info'.
1471+
"Asynchronous call to `haskell-process-get-type'.
1472+
Suitable for use in the eldoc function `haskell-doc-current-info'.
14701473
14711474
If SYNC is non-nil, the call will be synchronous instead, and
14721475
instead of calling `eldoc-print-current-symbol-info', the result
14731476
will be returned directly."
14741477
;; Return nil if nothing is available, or 'async if something might
14751478
;; be available, but asynchronously later. This will call
14761479
;; `eldoc-print-current-symbol-info' later.
1477-
(let (sym prev-message)
1478-
(cond
1479-
((setq prev-message haskell-doc-current-info--interaction-last)
1480-
(setq haskell-doc-current-info--interaction-last nil)
1481-
(cdr prev-message))
1482-
((setq sym
1483-
(if (use-region-p)
1484-
(buffer-substring-no-properties
1485-
(region-beginning) (region-end))
1486-
(haskell-ident-at-point)))
1487-
(if sync
1488-
(haskell-process-get-type sym #'identity t)
1489-
(haskell-process-get-type
1490-
sym (lambda (response)
1491-
(setq haskell-doc-current-info--interaction-last
1492-
(cons 'async response))
1493-
(eldoc-print-current-symbol-info))))))))
1480+
(when (haskell-doc-in-code-p)
1481+
;; do nothing when inside string or comment
1482+
(let (sym prev-message)
1483+
(cond
1484+
((setq prev-message haskell-doc-current-info--interaction-last)
1485+
(setq haskell-doc-current-info--interaction-last nil)
1486+
(cdr prev-message))
1487+
((setq sym
1488+
(if (use-region-p)
1489+
(buffer-substring-no-properties
1490+
(region-beginning) (region-end))
1491+
(haskell-ident-at-point)))
1492+
(if sync
1493+
(haskell-process-get-type sym #'identity t)
1494+
(haskell-process-get-type
1495+
sym (lambda (response)
1496+
(setq haskell-doc-current-info--interaction-last
1497+
(cons 'async response))
1498+
(eldoc-print-current-symbol-info)))))))))
14941499

14951500
(defun haskell-process-get-type (expr-string &optional callback sync)
14961501
"Asynchronously get the type of a given string.
@@ -1547,7 +1552,7 @@ If SYNC is non-nil, make the call synchronously instead."
15471552
'async))))
15481553

15491554
(defun haskell-doc-sym-doc (sym)
1550-
"Show the type of the function near point.
1555+
"Show the type of given symbol SYM.
15511556
For the function under point, show the type in the echo area.
15521557
This information is extracted from the `haskell-doc-prelude-types' alist
15531558
of prelude functions and their types, or from the local functions in the
@@ -1734,23 +1739,6 @@ ToDo: Also eliminate leading and trailing whitespace."
17341739
(setq str (replace-match " " t t str)))
17351740
str))
17361741

1737-
;; ToDo: make this more efficient!!
1738-
;;(defun haskell-doc-string-nub-ws (str)
1739-
;; "Replace all sequences of whitespaces in STR by just one whitespace."
1740-
;; (let ( (res "")
1741-
;; (l (length str))
1742-
;; (i 0)
1743-
;; (j 0)
1744-
;; (in-ws nil))
1745-
;; (while (< i l)
1746-
;; (let* ( (c (string-to-char (substring str i (1+ i))))
1747-
;; (is-ws (eq (char-syntax c) ? )) )
1748-
;; (if (not (and in-ws is-ws))
1749-
;; (setq res (concat res (char-to-string c))))
1750-
;; (setq in-ws is-ws)
1751-
;; (setq i (1+ i))))
1752-
;; res))
1753-
17541742
(defun haskell-doc-chop-off-context (str)
17551743
"Eliminate the context in a type represented by the string STR."
17561744
(let ((i (string-match "=>" str)) )

0 commit comments

Comments
 (0)