Skip to content

Modernize haskell-doc.el. #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 0 additions & 163 deletions haskell-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -294,41 +294,6 @@

;;; Code:

;;@menu
;;* Constants and Variables::
;;* Install as minor mode::
;;* Menubar Support::
;;* Haskell Doc Mode::
;;* Switch it on or off::
;;* Check::
;;* Top level function::
;;* Mouse interface::
;;* Print fctsym::
;;* Movement::
;;* Bug Reports::
;;* Visit home site::
;;* Index::
;;* Token::
;;@end menu

;;@node top, Constants and Variables, (dir), (dir)
;;@top

;;@node Constants and Variables, Install as minor mode, top, top
;;@section Constants and Variables

;;@menu
;;* Emacs portability::
;;* Maintenance stuff::
;;* Mode Variable::
;;* Variables::
;;* Prelude types::
;;* Test membership::
;;@end menu

;;@node Emacs portability, Maintenance stuff, Constants and Variables, Constants and Variables
;;@subsection Emacs portability

(eval-when-compile (require 'cl))

(require 'haskell-mode)
Expand All @@ -343,8 +308,6 @@
:group 'haskell
:prefix "haskell-doc-")

;;@node Mode Variable, Variables, Maintenance stuff, Constants and Variables
;;@subsection Mode Variable

(defvar haskell-doc-mode nil
"*If non-nil, show the type of the function near point or a related comment.
Expand Down Expand Up @@ -439,8 +402,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.")

;;@node Variables, Prelude types, Mode Variable, Constants and Variables
;;@subsection Variables

(defvar haskell-doc-idle-delay 0.50
"*Number of seconds of idle time to wait before printing.
Expand Down Expand Up @@ -494,11 +455,6 @@ It is probably best to manipulate this data structure with the commands
"*String to display in mode line when Haskell-Doc Mode is enabled.")


;;@node Prelude types, Test membership, Variables, Constants and Variables
;;@subsection Prelude types

;;@cindex haskell-doc-reserved-ids

(defvar haskell-doc-reserved-ids
'(("case" . "case exp of { alts [;] }")
("class" . "class [context =>] simpleclass [where { cbody [;] }]")
Expand Down Expand Up @@ -560,7 +516,6 @@ the keyword is used.")
list)))
(nreverse list))))))

;;@cindex haskell-doc-prelude-types

(defun haskell-doc-extract-types (url)
(with-temp-buffer
Expand Down Expand Up @@ -1215,7 +1170,6 @@ URL is the URL of the online doc."
)
"Alist of prelude functions and their types.")

;;@cindex haskell-doc-strategy-ids

(defvar haskell-doc-strategy-ids
(list
Expand Down Expand Up @@ -1277,30 +1231,20 @@ URL is the URL of the online doc."
(defvar haskell-doc-user-defined-ids nil
"Alist of functions and strings defined by the user.")

;;@node Test membership, , Prelude types, Constants and Variables
;;@subsection Test membership

;;@cindex haskell-doc-is-of
(defsubst haskell-doc-is-of (fn types)
"Check whether FN is one of the functions in the alist TYPES and return the type."
(assoc fn types) )

;;@node Install as minor mode, Menubar Support, Constants and Variables, top
;;@section Install as minor mode

;; Put this minor mode on the global minor-mode-alist.
(or (assq 'haskell-doc-mode (default-value 'minor-mode-alist))
(setq-default minor-mode-alist
(append (default-value 'minor-mode-alist)
'((haskell-doc-mode haskell-doc-minor-mode-string)))))


;;@node Menubar Support, Haskell Doc Mode, Install as minor mode, top
;;@section Menubar Support

;; a dummy definition needed for XEmacs (I know, it's horrible :-(

;;@cindex haskell-doc-install-keymap

(defvar haskell-doc-keymap
(let ((map (make-sparse-keymap)))
Expand Down Expand Up @@ -1344,11 +1288,6 @@ URL is the URL of the online doc."
(local-set-key [(control shift meta mouse-3)]
'haskell-doc-ask-mouse-for-type))


;;@node Haskell Doc Mode, Switch it on or off, Menubar Support, top
;;@section Haskell Doc Mode

;;@cindex haskell-doc-mode

(defvar haskell-doc-timer nil)
(defvar haskell-doc-buffers nil)
Expand Down Expand Up @@ -1411,61 +1350,46 @@ See variable docstring."
(>= (prefix-numeric-value ,prefix) 0)
(not ,id))) )

;;@cindex haskell-doc-show-global-types
(defun haskell-doc-show-global-types (&optional prefix)
"Turn on global types information in `haskell-doc-mode'."
(interactive "P")
(haskell-doc-toggle-var haskell-doc-show-global-types prefix)
(if haskell-doc-show-global-types
(haskell-doc-make-global-fct-index)))

;;@cindex haskell-doc-show-reserved
(defun haskell-doc-show-reserved (&optional prefix)
"Toggle the automatic display of a doc string for reserved ids."
(interactive "P")
(haskell-doc-toggle-var haskell-doc-show-reserved prefix))

;;@cindex haskell-doc-show-prelude
(defun haskell-doc-show-prelude (&optional prefix)
"Toggle the automatic display of a doc string for reserved ids."
(interactive "P")
(haskell-doc-toggle-var haskell-doc-show-prelude prefix))

;;@cindex haskell-doc-show-strategy
(defun haskell-doc-show-strategy (&optional prefix)
"Toggle the automatic display of a doc string for strategy ids."
(interactive "P")
(haskell-doc-toggle-var haskell-doc-show-strategy prefix))

;;@cindex haskell-doc-show-user-defined
(defun haskell-doc-show-user-defined (&optional prefix)
"Toggle the automatic display of a doc string for user defined ids."
(interactive "P")
(haskell-doc-toggle-var haskell-doc-show-user-defined prefix))

;;@node Switch it on or off, Check, Haskell Doc Mode, top
;;@section Switch it on or off

;;@cindex turn-on-haskell-doc-mode

;;;###autoload
(defalias 'turn-on-haskell-doc-mode 'haskell-doc-mode)

;;;###autoload
(defalias 'turn-on-haskell-doc 'haskell-doc-mode)

;;@cindex turn-off-haskell-doc-mode
(defalias 'turn-off-haskell-doc-mode 'turn-off-haskell-doc)

(defun turn-off-haskell-doc ()
"Unequivocally turn off `haskell-doc-mode' (which see)."
(haskell-doc-mode 0))

;;@node Check, Top level function, Switch it on or off, top
;;@section Check

;;@cindex haskell-doc-check-active

(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
Expand All @@ -1479,10 +1403,7 @@ is not."
(substitute-command-keys
"haskell-doc is not ACTIVE \(Use \\[haskell-doc-mode] to turn it on\)"))))

;;@node Top level function, Mouse interface, Check, top
;;@section Top level function

;;@cindex haskell-doc-mode-print-current-symbol-info
;; 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.
Expand Down Expand Up @@ -1519,10 +1440,7 @@ Meant for `eldoc-documentation-function'."
(unless (symbolp msg) msg)))


;;@node Mouse interface, Print fctsym, Top level function, top
;;@section Mouse interface for interactive query

;;@cindex haskell-doc-ask-mouse-for-type
(defun haskell-doc-ask-mouse-for-type (event)
"Read the identifier under the mouse and echo its type.
This uses the same underlying function `haskell-doc-show-type' as the hooked
Expand All @@ -1533,22 +1451,6 @@ function. Only the user interface is different."
(goto-char (posn-point (event-end event)))
(haskell-doc-show-type)))


;;@node Print fctsym, Movement, Mouse interface, top
;;@section Print fctsym

;;@menu
;;* Show type::
;;* Aux::
;;* Global fct type::
;;* Local fct type::
;;@end menu

;;@node Show type, Aux, Print fctsym, Print fctsym
;;@subsection Show type

;;@cindex haskell-doc-show-type

(defun haskell-doc-in-code-p ()
(not (or (and (eq haskell-literate 'bird)
;; Copied from haskell-indent-bolp.
Expand Down Expand Up @@ -1769,12 +1671,9 @@ the haskell-doc database."
;; (and (symbolp sym)
;; sym)))

;;@node Aux, Global fct type, Show type, Print fctsym
;;@subsection Aux

;; ToDo: handle open brackets to decide if it's a wrapped type

;;@cindex haskell-doc-grab-line
(defun haskell-doc-grab-line (fct-and-pos)
"Get the type of an \(FCT POSITION\) pair from the current buffer."
;; (if (null fct-and-pos)
Expand All @@ -1797,7 +1696,6 @@ the haskell-doc database."
str)))))
;; (concat (car fct-and-pos) "::" (haskell-doc-string-nub-ws str))))

;;@cindex haskell-doc-wrapped-type-p
(defun haskell-doc-wrapped-type-p ()
"Check whether the type under the cursor is wrapped over several lines.
The cursor must be at the end of a line, which contains the type.
Expand Down Expand Up @@ -1843,7 +1741,6 @@ ToDo: Check for matching parenthesis!."
(setq res t))))))
res)))

;;@cindex haskell-doc-grab
(defun haskell-doc-grab ()
"Return the text from point to the end of the line, chopping off comments.
Leaves point at end of line."
Expand All @@ -1853,7 +1750,6 @@ Leaves point at end of line."
(substring str 0 (match-beginning 0))
str)))

;;@cindex haskell-doc-string-nub-ws
(defun haskell-doc-string-nub-ws (str)
"Replace all sequences of whitespace in STR by just one space.
ToDo: Also eliminate leading and trailing whitespace."
Expand All @@ -1879,15 +1775,13 @@ ToDo: Also eliminate leading and trailing whitespace."
;; (setq i (1+ i))))
;; res))

;;@cindex haskell-doc-chop-off-context
(defun haskell-doc-chop-off-context (str)
"Eliminate the context in a type represented by the string STR."
(let ((i (string-match "=>" str)) )
(if (null i)
str
(substring str (+ i 2)))))

;;@cindex haskell-doc-get-imenu-info
(defun haskell-doc-get-imenu-info (obj kind)
"Return a string describing OBJ of KIND \(Variables, Types, Data\)."
(cond
Expand All @@ -1900,14 +1794,10 @@ ToDo: Also eliminate leading and trailing whitespace."
(t ;; (error "Cannot get local functions in %s mode, sorry" major-mode)))
nil)))

;;@node Global fct type, Local fct type, Aux, Print fctsym
;;@subsection Global fct type

;; ToDo:
;; - modular way of defining a mapping of module name to file
;; - use a path to search for file (not just current directory)

;;@cindex haskell-doc-imported-list

(defun haskell-doc-imported-list ()
"Return a list of the imported modules in current buffer."
Expand All @@ -1929,8 +1819,6 @@ ToDo: Also eliminate leading and trailing whitespace."

;; ToDo: generalise this to "Types" etc (not just "Variables")

;;@cindex haskell-doc-rescan-files

(defun haskell-doc-rescan-files (filelist)
"Do an `imenu' rescan on every file in FILELIST and return the fct-list.
This function switches to and potentially loads many buffers."
Expand All @@ -1944,8 +1832,6 @@ This function switches to and potentially loads many buffers."
(cdr (assoc "Variables" imenu--index-alist)))))
filelist)))

;;@cindex haskell-doc-make-global-fct-index

(defun haskell-doc-make-global-fct-index ()
"Scan imported files for types of global fcts and update `haskell-doc-index'."
(interactive)
Expand All @@ -1954,8 +1840,6 @@ This function switches to and potentially loads many buffers."

;; ToDo: use a separate munge-type function to format type concisely

;;@cindex haskell-doc-get-global-fct-type

(defun haskell-doc-get-global-fct-type (&optional sym)
"Get type for function symbol SYM by examining `haskell-doc-index'."
(interactive) ; "fName of outer `include' file: \nsFct:")
Expand Down Expand Up @@ -1984,11 +1868,6 @@ This function switches to and potentially loads many buffers."
(setq fal (cdr fal))))
res))) ; (message res)) )

;;@node Local fct type, , Global fct type, Print fctsym
;;@subsection Local fct type

;;@cindex haskell-doc-get-and-format-fct-type

(defun haskell-doc-get-and-format-fct-type (fn)
"Get the type and kind of FN by checking local and global functions."
(save-excursion
Expand All @@ -2012,48 +1891,6 @@ This function switches to and potentially loads many buffers."
;; return the result
doc ))))


;;@appendix

;;@node Index, Token, Visit home site, top
;;@section Index

;;@index
;;* haskell-doc-ask-mouse-for-type::
;;* haskell-doc-check-active::
;;* haskell-doc-chop-off-context::
;;* haskell-doc-get-and-format-fct-type::
;;* haskell-doc-get-global-fct-type::
;;* haskell-doc-get-imenu-info::
;;* haskell-doc-grab::
;;* haskell-doc-grab-line::
;;* haskell-doc-imported-list::
;;* haskell-doc-install-keymap::
;;* haskell-doc-is-of::
;;* haskell-doc-make-global-fct-index::
;;* haskell-doc-mode::
;;* haskell-doc-mode-print-current-symbol-info::
;;* haskell-doc-prelude-types::
;;* haskell-doc-rescan-files::
;;* haskell-doc-reserved-ids::
;;* haskell-doc-show-global-types::
;;* haskell-doc-show-prelude::
;;* haskell-doc-show-reserved::
;;* haskell-doc-show-strategy::
;;* haskell-doc-show-type::
;;* haskell-doc-show-user-defined::
;;* haskell-doc-strategy-ids::
;;* haskell-doc-string-nub-ws::
;;* haskell-doc-submit-bug-report::
;;* haskell-doc-visit-home::
;;* haskell-doc-wrapped-type-p::
;;* turn-off-haskell-doc-mode::
;;* turn-on-haskell-doc-mode::
;;@end index

;;@node Token, , Index, top
;;@section Token

(provide 'haskell-doc)

;;; haskell-doc.el ends here