[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-mode 922f730cbd 5/7: Merge pull request #1802 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-mode 922f730cbd 5/7: Merge pull request #1802 from haskell/haskell-doc-mode-tidyup |
Date: |
Fri, 3 Mar 2023 13:01:20 -0500 (EST) |
branch: elpa/haskell-mode
commit 922f730cbd4fe4d79d5beff45eccef607f6db472
Merge: a34ccdc54b 310d8907c5
Author: Steve Purcell <steve@sanityinc.com>
Commit: GitHub <noreply@github.com>
Merge pull request #1802 from haskell/haskell-doc-mode-tidyup
Haskell doc mode tidyup
---
.github/workflows/test.yml | 2 +-
haskell-doc.el | 203 +++++++++++++--------------------------------
haskell-mode.el | 16 ++--
tests/haskell-doc-tests.el | 6 +-
4 files changed, 66 insertions(+), 161 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index b8204fb9fe..627ba4b419 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -25,7 +25,7 @@ jobs:
- emacs_version: 28.2
target: deploy-manual
steps:
- - uses: cachix/install-nix-action@v16
+ - uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: purcell/setup-emacs@master
diff --git a/haskell-doc.el b/haskell-doc.el
index bd9e4ccbdc..b132ddddf7 100644
--- a/haskell-doc.el
+++ b/haskell-doc.el
@@ -314,38 +314,6 @@
:prefix "haskell-doc-")
-(defvar-local haskell-doc-mode nil
- "*If non-nil, show the type of the function near point or a related comment.
-
-If the identifier near point is a Haskell keyword and the variable
-`haskell-doc-show-reserved' is non-nil show a one line summary
-of the syntax.
-
-If the identifier near point is a Prelude or one of the standard library
-functions and `haskell-doc-show-prelude' is non-nil show its type.
-
-If the identifier near point is local \(i.e. defined in this module\) check
-the `imenu' list of functions for the type. This obviously requires that
-your language mode uses `imenu'.
-
-If the identifier near point is global \(i.e. defined in an imported module\)
-and the variable `haskell-doc-show-global-types' is non-nil show the type of
its
-function.
-
-If the identifier near point is a standard strategy or a function, type related
-related to strategies and `haskell-doc-show-strategy' is non-nil show the type
-of the function. Strategies are special to the parallel execution of Haskell.
-If you're not interested in that just turn it off.
-
-If the identifier near point is a user defined function that occurs as key
-in the alist `haskell-doc-user-defined-ids' and the variable
-`haskell-doc-show-user-defined' is non-nil show the type of the function.
-
-This variable is buffer-local.")
-
-(defvar haskell-doc-mode-hook nil
- "Hook invoked when entering `haskell-doc-mode'.")
-
(defvar-local haskell-doc-index nil
"Variable holding an alist matching file names to fct-type alists.
The function `haskell-doc-make-global-fct-index' rebuilds this variables
@@ -405,14 +373,6 @@ This variable is buffer-local."
(defvar haskell-doc-search-distance 40 ; distance in characters
"*How far to search when looking for the type declaration of fct under
cursor.")
-
-(defvar haskell-doc-idle-delay 0.50
- "*Number of seconds of idle time to wait before printing.
-If user input arrives before this interval of time has elapsed after the
-last input, no documentation will be printed.
-
-If this variable is set to 0, no idle time is required.")
-
(defvar haskell-doc-argument-case 'identity ; 'upcase
"Case in which to display argument names of functions, as a symbol.
This has two preferred values: `upcase' or `downcase'.
@@ -1238,81 +1198,56 @@ URL is the URL of the online doc."
'("Toggle display of reserved ids" . haskell-doc-show-reserved))
(define-key map [haskell-doc-on]
'("Toggle haskell-doc mode" . haskell-doc-mode))
+ (define-key map [(control shift meta mouse-3)]
+ 'haskell-doc-ask-mouse-for-type)
map))
-(defun haskell-doc-install-keymap ()
- "Install a menu for `haskell-doc-mode' as a submenu of \"Hugs\"."
- (interactive)
- ;; Add the menu to the hugs menu as last entry.
- (let ((hugsmap (lookup-key (current-local-map) [menu-bar Hugs])))
- (if (not (or (featurep 'xemacs) ; XEmacs has problems here
- (not (keymapp hugsmap))
- (lookup-key hugsmap [haskell-doc])))
- (if (functionp 'define-key-after)
- (define-key-after hugsmap [haskell-doc]
- (cons "Haskell-doc" haskell-doc-keymap)
- [Haskell-doc mode]))))
- ;; Add shortcuts for these commands.
- (local-set-key "\C-c\e/" 'haskell-doc-check-active)
- ;; Conflicts with the binding of haskell-insert-otherwise.
- ;; (local-set-key "\C-c\C-o" 'haskell-doc-mode)
- (local-set-key [(control shift meta mouse-3)]
- 'haskell-doc-ask-mouse-for-type))
-
-
-(defvar haskell-doc-timer nil)
-(defvar haskell-doc-buffers nil)
;;;###autoload
-(defun haskell-doc-mode (&optional arg)
+(define-minor-mode haskell-doc-mode
"Enter `haskell-doc-mode' for showing fct types in the echo area.
-See variable docstring."
- (interactive (list (or current-prefix-arg 'toggle)))
-
- (setq haskell-doc-mode
- (cond
- ((eq arg 'toggle) (not haskell-doc-mode))
- (arg (> (prefix-numeric-value arg) 0))
- (t)))
-
- ;; First, unconditionally turn the mode OFF.
-
- (setq haskell-doc-buffers (delq (current-buffer) haskell-doc-buffers))
- ;; Refresh the buffers list.
- (dolist (buf haskell-doc-buffers)
- (unless (and (buffer-live-p buf)
- (with-current-buffer buf haskell-doc-mode))
- (setq haskell-doc-buffers (delq buf haskell-doc-buffers))))
- ;; Turn off the idle timer (or idle post-command-hook).
- (when (and haskell-doc-timer (null haskell-doc-buffers))
- (cancel-timer haskell-doc-timer)
- (setq haskell-doc-timer nil))
- (remove-hook 'post-command-hook
- 'haskell-doc-mode-print-current-symbol-info 'local)
- (when haskell-doc-mode
- ;; Turning the mode ON.
- (push (current-buffer) haskell-doc-buffers)
+When enabled, shows the type of the function near point or a related comment.
- (if (fboundp 'run-with-idle-timer)
- (unless haskell-doc-timer
- (setq haskell-doc-timer
- (run-with-idle-timer
- haskell-doc-idle-delay t
- 'haskell-doc-mode-print-current-symbol-info)))
- (add-hook 'post-command-hook
- 'haskell-doc-mode-print-current-symbol-info nil 'local))
- (and haskell-doc-show-global-types
- (haskell-doc-make-global-fct-index)) ; build type index for global
fcts
+If the identifier near point is a Haskell keyword and the variable
+`haskell-doc-show-reserved' is non-nil show a one line summary
+of the syntax.
- (haskell-doc-install-keymap)
+If the identifier near point is a Prelude or one of the standard library
+functions and `haskell-doc-show-prelude' is non-nil show its type.
- (run-hooks 'haskell-doc-mode-hook))
+If the identifier near point is local \(i.e. defined in this module\) check
+the `imenu' list of functions for the type. This obviously requires that
+your language mode uses `imenu'.
- (and (called-interactively-p 'any)
- (message "haskell-doc-mode is %s"
- (if haskell-doc-mode "enabled" "disabled")))
- haskell-doc-mode)
+If the identifier near point is global \(i.e. defined in an imported module\)
+and the variable `haskell-doc-show-global-types' is non-nil show the type of
its
+function.
+
+If the identifier near point is a standard strategy or a function, type related
+related to strategies and `haskell-doc-show-strategy' is non-nil show the type
+of the function. Strategies are special to the parallel execution of Haskell.
+If you're not interested in that just turn it off.
+
+If the identifier near point is a user defined function that occurs as key
+in the alist `haskell-doc-user-defined-ids' and the variable
+`haskell-doc-show-user-defined' is non-nil show the type of the function.
+
+This variable is buffer-local."
+ :global nil
+ :keymap haskell-doc-keymap
+
+ (and haskell-doc-show-global-types
+ (haskell-doc-make-global-fct-index)) ; build type index for global fcts
+ (if (boundp 'eldoc-documentation-functions)
+ (if haskell-doc-mode
+ (add-hook 'eldoc-documentation-functions 'haskell-doc-eldoc-function
nil t)
+ (remove-hook 'eldoc-documentation-functions
'haskell-doc-eldoc-function t))
+ (if haskell-doc-mode
+ (setq-local eldoc-documentation-function 'haskell-doc-eldoc-function)
+ (kill-local-variable eldoc-documentation-function)))
+ (when haskell-doc-mode
+ (eldoc-mode)))
(defmacro haskell-doc-toggle-var (id prefix)
;; toggle variable or set it based on prefix value
@@ -1367,46 +1302,22 @@ See variable docstring."
"Unequivocally turn off `haskell-doc-mode' (which see)."
(haskell-doc-mode 0))
-(defun haskell-doc-check-active ()
- "Check whether the print function is hooked in.
-Should be the same as the value of `haskell-doc-mode' but alas currently it
-is not."
- (interactive)
- (message "%s"
- (if (or (and haskell-doc-mode haskell-doc-timer)
- (memq 'haskell-doc-mode-print-current-symbol-info
- post-command-hook))
- "haskell-doc is ACTIVE"
- (substitute-command-keys
- "haskell-doc is not ACTIVE \(Use \\[haskell-doc-mode] to turn it
on\)"))))
-
-
-;; This is the function hooked into the elisp command engine
-(defun haskell-doc-mode-print-current-symbol-info ()
- "Print the type of the symbol under the cursor.
-
-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))
- ;; good morning! read the word under the cursor for breakfast
- (haskell-doc-show-type)))
-;; ;; ToDo: find surrounding fct
-;; (cond ((eq current-symbol current-fnsym)
-;; (haskell-doc-show-type current-fnsym))
-;; (t
-;; (or nil ; (haskell-doc-print-var-docstring current-symbol)
-;; (haskell-doc-show-type current-fnsym)))))))
+;;;###autoload
+(defun haskell-doc-eldoc-function (&optional callback)
+ "Function for use by eldoc.
+
+By accepting CALLBACK, it is designed to be used in
+`eldoc-documentation-functions' in Emacs >= 28.1, but by making
+that argument optional it can also be set directly as
+`eldoc-documentation-function' in older Emacsen."
+ (when (and haskell-doc-mode
+ (haskell-doc-in-code-p)
+ (not haskell-mode-interactive-prompt-state)
+ (not (eobp))
+ (not executing-kbd-macro))
+ (if callback
+ (funcall callback (haskell-doc-current-info))
+ (haskell-doc-current-info))))
;;;###autoload
(defun haskell-doc-current-info ()
@@ -1450,7 +1361,7 @@ current buffer."
;; if printed before do not print it again
(unless (string= sym (car haskell-doc-last-data))
(let ((doc (or (haskell-doc-current-info--interaction t)
- (haskell-doc-sym-doc sym))))
+ (haskell-doc-sym-doc sym))))
(when (and doc (haskell-doc-in-code-p))
;; In Emacs 19.29 and later, and XEmacs 19.13 and later, all
;; messages are recorded in a log. Do not put haskell-doc messages
diff --git a/haskell-mode.el b/haskell-mode.el
index bfbf0fbd68..0930680fb8 100644
--- a/haskell-mode.el
+++ b/haskell-mode.el
@@ -228,11 +228,8 @@ be set to the preferred literate style."
"---"
["Load tidy core" ghc-core-create-core]
"---"
- ,(if (default-boundp 'eldoc-documentation-function)
- ["Doc mode" eldoc-mode
- :style toggle :selected (bound-and-true-p eldoc-mode)]
- ["Doc mode" haskell-doc-mode
- :style toggle :selected (and (boundp 'haskell-doc-mode)
haskell-doc-mode)])
+ ["Doc mode" haskell-doc-mode
+ :style toggle :selected (and (boundp 'haskell-doc-mode) haskell-doc-mode)]
["Customize" (customize-group 'haskell)]
))
@@ -733,8 +730,6 @@ Prefix ARG is handled as per `delete-indentation'."
(let ((fill-prefix (or fill-prefix (if (eq haskell-literate 'bird) ">"))))
(delete-indentation arg)))
-(defvar eldoc-print-current-symbol-info-function)
-
(defvar electric-pair-inhibit-predicate)
(declare-function electric-pair-default-inhibit "elec-pair")
(defun haskell-mode--inhibit-bracket-inside-comment-or-default (ch)
@@ -798,12 +793,13 @@ Other modes:
Scans top-level declarations, and places them in a menu.
`haskell-doc-mode', Hans-Wolfgang Loidl
- Echoes types of functions or syntax of keywords when the cursor is idle.
+ Sets up eldoc to echo types of functions or syntax of keywords
+ when the cursor is idle.
To activate a minor-mode, simply run the interactive command. For
example, `M-x haskell-doc-mode'. Run it again to disable it.
-To enable a mode for every haskell-mode buffer, add a hook in
+To enable a mode for every `haskell-mode' buffer, add a hook in
your Emacs configuration. To do that you can customize
`haskell-mode-hook' or add lines to your .emacs file. For
example, to enable `interactive-haskell-mode', use the following:
@@ -832,8 +828,6 @@ Minor modes that work well with `haskell-mode':
(setq-local parse-sexp-ignore-comments nil)
(setq-local syntax-propertize-function #'haskell-syntax-propertize)
- ;; Set things up for eldoc-mode.
- (setq-local eldoc-documentation-function 'haskell-doc-current-info)
;; Set things up for imenu.
(setq-local imenu-create-index-function 'haskell-ds-create-imenu-index)
;; Set things up for font-lock.
diff --git a/tests/haskell-doc-tests.el b/tests/haskell-doc-tests.el
index 41010d7c32..37556ee3f0 100644
--- a/tests/haskell-doc-tests.el
+++ b/tests/haskell-doc-tests.el
@@ -44,13 +44,13 @@
(forward-line)
(should (string=
"import [qualified] modid [as modid] [impspec]"
- (haskell-doc-mode-print-current-symbol-info)))
+ (haskell-doc-eldoc-function)))
(haskell-mode-toggle-interactive-prompt-state)
(should (eq nil
- (haskell-doc-mode-print-current-symbol-info)))
+ (haskell-doc-eldoc-function)))
(haskell-mode-toggle-interactive-prompt-state t)
(should (string=
"import [qualified] modid [as modid] [impspec]"
- (haskell-doc-mode-print-current-symbol-info)))))
+ (haskell-doc-eldoc-function)))))
;;; haskell-doc-tests.el ends here
- [nongnu] elpa/haskell-mode updated (a34ccdc54b -> 810b08e317), ELPA Syncer, 2023/03/03
- [nongnu] elpa/haskell-mode abce84fef3 6/7: Merge branch 'master' into cull-markers, ELPA Syncer, 2023/03/03
- [nongnu] elpa/haskell-mode 810b08e317 7/7: Merge pull request #1760 from mattiase/cull-markers, ELPA Syncer, 2023/03/03
- [nongnu] elpa/haskell-mode 310d8907c5 4/7: Update install-nix-action, ELPA Syncer, 2023/03/03
- [nongnu] elpa/haskell-mode 9cf0ad4ee5 1/7: Reduce (over)use of markers (#1751), ELPA Syncer, 2023/03/03
- [nongnu] elpa/haskell-mode 6aa9473951 2/7: Don't use user-reserved "C-c e" keybinding in haskell-doc-mode, ELPA Syncer, 2023/03/03
- [nongnu] elpa/haskell-mode 922f730cbd 5/7: Merge pull request #1802 from haskell/haskell-doc-mode-tidyup,
ELPA Syncer <=
- [nongnu] elpa/haskell-mode e80a5d4749 3/7: Use eldoc consistently in haskell-doc-mode instead of reimplementing it, ELPA Syncer, 2023/03/03