@@ -1392,12 +1392,14 @@ is not."
1392
1392
This function is run by an idle timer to print the type
1393
1393
automatically if `haskell-doc-mode' is turned on."
1394
1394
(and haskell-doc-mode
1395
+ (haskell-doc-in-code-p)
1395
1396
(not haskell-mode-interactive-prompt-state)
1396
1397
(not (eobp ))
1397
1398
(not executing-kbd-macro)
1398
1399
; ; Having this mode operate in the minibuffer makes it impossible to
1399
1400
; ; see what you're doing.
1400
1401
(not (eq (selected-window ) (minibuffer-window )))
1402
+ ; ; not in string or comment
1401
1403
; ; take a nap, if run straight from post-command-hook.
1402
1404
(if (fboundp 'run-with-idle-timer ) t
1403
1405
(sit-for haskell-doc-idle-delay))
@@ -1416,12 +1418,11 @@ This function is run by an idle timer to print the type
1416
1418
Meant for `eldoc-documentation-function' ."
1417
1419
; ; There are a number of possible documentation functions.
1418
1420
; ; 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))))
1425
1426
1426
1427
(defun haskell-doc-ask-mouse-for-type (event )
1427
1428
" Read the identifier under the mouse and echo its type.
@@ -1434,6 +1435,7 @@ function. Only the user interface is different."
1434
1435
(haskell-doc-show-type )))
1435
1436
1436
1437
(defun haskell-doc-in-code-p ()
1438
+ " A predicate indicating suitable case to show docs."
1437
1439
(not (or (and (eq haskell-literate 'bird )
1438
1440
; ; Copied from haskell-indent-bolp.
1439
1441
(<= (current-column ) 2 )
@@ -1442,7 +1444,7 @@ function. Only the user interface is different."
1442
1444
1443
1445
;;;### autoload
1444
1446
(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 .
1446
1448
For the function under point, show the type in the echo area.
1447
1449
This information is extracted from the `haskell-doc-prelude-types' alist
1448
1450
of prelude functions and their types, or from the local functions in the
@@ -1461,36 +1463,39 @@ current buffer."
1461
1463
(message " %s " doc))))))
1462
1464
1463
1465
(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." )
1466
1469
1467
1470
(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' .
1470
1473
1471
1474
If SYNC is non-nil, the call will be synchronous instead, and
1472
1475
instead of calling `eldoc-print-current-symbol-info' , the result
1473
1476
will be returned directly."
1474
1477
; ; Return nil if nothing is available, or 'async if something might
1475
1478
; ; be available, but asynchronously later. This will call
1476
1479
; ; `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 )))))))))
1494
1499
1495
1500
(defun haskell-process-get-type (expr-string &optional callback sync )
1496
1501
" Asynchronously get the type of a given string.
@@ -1547,7 +1552,7 @@ If SYNC is non-nil, make the call synchronously instead."
1547
1552
'async ))))
1548
1553
1549
1554
(defun haskell-doc-sym-doc (sym )
1550
- " Show the type of the function near point .
1555
+ " Show the type of given symbol SYM .
1551
1556
For the function under point, show the type in the echo area.
1552
1557
This information is extracted from the `haskell-doc-prelude-types' alist
1553
1558
of prelude functions and their types, or from the local functions in the
@@ -1734,23 +1739,6 @@ ToDo: Also eliminate leading and trailing whitespace."
1734
1739
(setq str (replace-match " " t t str)))
1735
1740
str))
1736
1741
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
-
1754
1742
(defun haskell-doc-chop-off-context (str )
1755
1743
" Eliminate the context in a type represented by the string STR."
1756
1744
(let ((i (string-match " =>" str)) )
0 commit comments