From 277aff1639428f47a4ee00ca2c8fc65ce7845145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 6 Mar 2016 03:58:55 +0500 Subject: [PATCH 1/3] Improve some docs --- haskell-doc.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/haskell-doc.el b/haskell-doc.el index 6766efdae..72c2741e2 100644 --- a/haskell-doc.el +++ b/haskell-doc.el @@ -1434,6 +1434,7 @@ function. Only the user interface is different." (haskell-doc-show-type))) (defun haskell-doc-in-code-p () + "A predicate indicating suitable case to show docs." (not (or (and (eq haskell-literate 'bird) ;; Copied from haskell-indent-bolp. (<= (current-column) 2) @@ -1442,7 +1443,7 @@ function. Only the user interface is different." ;;;###autoload (defun haskell-doc-show-type (&optional sym) - "Show the type of the function near point. + "Show the type of the function near point or given symbol SYM. For the function under point, show the type in the echo area. This information is extracted from the `haskell-doc-prelude-types' alist of prelude functions and their types, or from the local functions in the @@ -1461,12 +1462,13 @@ current buffer." (message "%s" doc)))))) (defvar haskell-doc-current-info--interaction-last nil - "If non-nil, a previous eldoc message from an async call, that - hasn't been displayed yet.") + "Async message stack. +If non-nil, a previous eldoc message from an async call, that +hasn't been displayed yet.") (defun haskell-doc-current-info--interaction (&optional sync) - "Asynchronous call to `haskell-process-get-type', suitable for -use in the eldoc function `haskell-doc-current-info'. + "Asynchronous call to `haskell-process-get-type'. +Suitable for use in the eldoc function `haskell-doc-current-info'. If SYNC is non-nil, the call will be synchronous instead, and instead of calling `eldoc-print-current-symbol-info', the result @@ -1547,7 +1549,7 @@ If SYNC is non-nil, make the call synchronously instead." 'async)))) (defun haskell-doc-sym-doc (sym) - "Show the type of the function near point. + "Show the type of given symbol SYM. For the function under point, show the type in the echo area. This information is extracted from the `haskell-doc-prelude-types' alist of prelude functions and their types, or from the local functions in the From 81d5bebab2f70147b784977391f03d33244680e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 6 Mar 2016 03:59:13 +0500 Subject: [PATCH 2/3] Remove some obsolete code --- haskell-doc.el | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/haskell-doc.el b/haskell-doc.el index 72c2741e2..f31c64dce 100644 --- a/haskell-doc.el +++ b/haskell-doc.el @@ -1736,23 +1736,6 @@ ToDo: Also eliminate leading and trailing whitespace." (setq str (replace-match " " t t str))) str)) -;; ToDo: make this more efficient!! -;;(defun haskell-doc-string-nub-ws (str) -;; "Replace all sequences of whitespaces in STR by just one whitespace." -;; (let ( (res "") -;; (l (length str)) -;; (i 0) -;; (j 0) -;; (in-ws nil)) -;; (while (< i l) -;; (let* ( (c (string-to-char (substring str i (1+ i)))) -;; (is-ws (eq (char-syntax c) ? )) ) -;; (if (not (and in-ws is-ws)) -;; (setq res (concat res (char-to-string c)))) -;; (setq in-ws is-ws) -;; (setq i (1+ i)))) -;; res)) - (defun haskell-doc-chop-off-context (str) "Eliminate the context in a type represented by the string STR." (let ((i (string-match "=>" str)) ) From 96553c79e12570b2667c7defa38815e097c53fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Fayzrakhmanov=20=28=D0=90=D1=80=D1=82=D1=83=D1=80?= =?UTF-8?q?=20=D0=A4=D0=B0=D0=B9=D0=B7=D1=80=D0=B0=D1=85=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=29?= Date: Sun, 6 Mar 2016 03:59:35 +0500 Subject: [PATCH 3/3] Do nothing when in string or comment --- haskell-doc.el | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/haskell-doc.el b/haskell-doc.el index f31c64dce..44aa55438 100644 --- a/haskell-doc.el +++ b/haskell-doc.el @@ -1392,12 +1392,14 @@ is not." This function is run by an idle timer to print the type automatically if `haskell-doc-mode' is turned on." (and haskell-doc-mode + (haskell-doc-in-code-p) (not haskell-mode-interactive-prompt-state) (not (eobp)) (not executing-kbd-macro) ;; Having this mode operate in the minibuffer makes it impossible to ;; see what you're doing. (not (eq (selected-window) (minibuffer-window))) + ;; not in string or comment ;; take a nap, if run straight from post-command-hook. (if (fboundp 'run-with-idle-timer) t (sit-for haskell-doc-idle-delay)) @@ -1416,12 +1418,11 @@ This function is run by an idle timer to print the type Meant for `eldoc-documentation-function'." ;; There are a number of possible documentation functions. ;; Some of them are asynchronous. - (let ((msg (or - (haskell-doc-current-info--interaction) - (haskell-doc-sym-doc (haskell-ident-at-point))))) - (unless (symbolp msg) msg))) - - + (when (haskell-doc-in-code-p) + (let ((msg (or + (haskell-doc-current-info--interaction) + (haskell-doc-sym-doc (haskell-ident-at-point))))) + (unless (symbolp msg) msg)))) (defun haskell-doc-ask-mouse-for-type (event) "Read the identifier under the mouse and echo its type. @@ -1476,23 +1477,25 @@ will be returned directly." ;; Return nil if nothing is available, or 'async if something might ;; be available, but asynchronously later. This will call ;; `eldoc-print-current-symbol-info' later. - (let (sym prev-message) - (cond - ((setq prev-message haskell-doc-current-info--interaction-last) - (setq haskell-doc-current-info--interaction-last nil) - (cdr prev-message)) - ((setq sym - (if (use-region-p) - (buffer-substring-no-properties - (region-beginning) (region-end)) - (haskell-ident-at-point))) - (if sync - (haskell-process-get-type sym #'identity t) - (haskell-process-get-type - sym (lambda (response) - (setq haskell-doc-current-info--interaction-last - (cons 'async response)) - (eldoc-print-current-symbol-info)))))))) + (when (haskell-doc-in-code-p) + ;; do nothing when inside string or comment + (let (sym prev-message) + (cond + ((setq prev-message haskell-doc-current-info--interaction-last) + (setq haskell-doc-current-info--interaction-last nil) + (cdr prev-message)) + ((setq sym + (if (use-region-p) + (buffer-substring-no-properties + (region-beginning) (region-end)) + (haskell-ident-at-point))) + (if sync + (haskell-process-get-type sym #'identity t) + (haskell-process-get-type + sym (lambda (response) + (setq haskell-doc-current-info--interaction-last + (cons 'async response)) + (eldoc-print-current-symbol-info))))))))) (defun haskell-process-get-type (expr-string &optional callback sync) "Asynchronously get the type of a given string.