ESC C-e to process the module.
This commit is contained in:
parent
35f60507c6
commit
e9c4ec4e4b
@ -131,26 +131,44 @@
|
|||||||
(defun ghc-completion-start-point ()
|
(defun ghc-completion-start-point ()
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((beg (save-excursion (beginning-of-line) (point))))
|
(let ((beg (save-excursion (beginning-of-line) (point))))
|
||||||
(if (search-backward " " beg t)
|
(if (re-search-backward "[ (,`]" beg t)
|
||||||
(1+ (point))
|
(1+ (point))
|
||||||
beg))))
|
beg))))
|
||||||
|
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;;
|
||||||
|
;;; Loading keywords
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(defun ghc-load-module (mod)
|
||||||
|
(when (and (member mod ghc-module-names)
|
||||||
|
(not (member mod ghc-loaded-module)))
|
||||||
|
(let ((keywords (ghc-load-keyword "browse" mod)))
|
||||||
|
(when (or (consp keywords) (null keywords))
|
||||||
|
(set (intern (concat ghc-keyword-prefix mod)) keywords)
|
||||||
|
(setq ghc-loaded-module (cons mod ghc-loaded-module))))))
|
||||||
|
|
||||||
|
(defun ghc-merge-keywords ()
|
||||||
|
(let* ((modkeys (mapcar 'ghc-module-keyword ghc-loaded-module))
|
||||||
|
(keywords (cons ghc-reserved-keyword modkeys))
|
||||||
|
(uniq-sorted (sort (ghc-uniq-lol keywords) 'string<)))
|
||||||
|
(setq ghc-merged-keyword uniq-sorted)))
|
||||||
|
|
||||||
|
(defun ghc-import-module ()
|
||||||
|
(interactive)
|
||||||
|
(ghc-load-module (ghc-read-module-name (ghc-extract-module)))
|
||||||
|
(ghc-merge-keywords))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;
|
;;;
|
||||||
;;; Background Idle Timer
|
;;; Background Idle Timer
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(defun ghc-idle-timer ()
|
(defun ghc-idle-timer ()
|
||||||
(let ((mods (ghc-gather-import-modules))
|
(dolist (mod (ghc-gather-import-modules))
|
||||||
keywords)
|
(ghc-load-module mod))
|
||||||
(dolist (mod mods)
|
(ghc-merge-keywords))
|
||||||
(when (and (member mod ghc-module-names)
|
|
||||||
(not (member mod ghc-loaded-module)))
|
|
||||||
(setq keywords (ghc-load-keyword "browse" mod))
|
|
||||||
(when (or (consp keywords) (null keywords))
|
|
||||||
(set (intern (concat ghc-keyword-prefix mod)) keywords)
|
|
||||||
(setq ghc-loaded-module (cons mod ghc-loaded-module)))))
|
|
||||||
(ghc-merge-keywords)))
|
|
||||||
|
|
||||||
(defun ghc-gather-import-modules ()
|
(defun ghc-gather-import-modules ()
|
||||||
(let ((bufs (mapcar 'buffer-name (buffer-list)))
|
(let ((bufs (mapcar 'buffer-name (buffer-list)))
|
||||||
@ -171,12 +189,6 @@
|
|||||||
(forward-line)))
|
(forward-line)))
|
||||||
ret))
|
ret))
|
||||||
|
|
||||||
(defun ghc-merge-keywords ()
|
|
||||||
(let* ((modkeys (mapcar 'ghc-module-keyword ghc-loaded-module))
|
|
||||||
(keywords (cons ghc-reserved-keyword modkeys))
|
|
||||||
(uniq-sorted (sort (ghc-uniq-lol keywords) 'string<)))
|
|
||||||
(setq ghc-merged-keyword uniq-sorted)))
|
|
||||||
|
|
||||||
(defun ghc-module-keyword (mod)
|
(defun ghc-module-keyword (mod)
|
||||||
(symbol-value (intern (concat ghc-keyword-prefix mod))))
|
(symbol-value (intern (concat ghc-keyword-prefix mod))))
|
||||||
|
|
||||||
|
@ -18,13 +18,6 @@
|
|||||||
(pkg (ghc-resolve-package-name mod)))
|
(pkg (ghc-resolve-package-name mod)))
|
||||||
(ghc-display-document pkg mod)))
|
(ghc-display-document pkg mod)))
|
||||||
|
|
||||||
(defun ghc-extract-module ()
|
|
||||||
(interactive)
|
|
||||||
(save-excursion
|
|
||||||
(beginning-of-line)
|
|
||||||
(when (looking-at "^import +\\([^ \n]+\\)")
|
|
||||||
(match-string-no-properties 1))))
|
|
||||||
|
|
||||||
(defun ghc-resolve-package-name (mod)
|
(defun ghc-resolve-package-name (mod)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(call-process "ghc-pkg" nil t nil "find-module" "--simple-output" mod)
|
(call-process "ghc-pkg" nil t nil "find-module" "--simple-output" mod)
|
||||||
@ -57,8 +50,5 @@
|
|||||||
(make-sparse-keymap)))
|
(make-sparse-keymap)))
|
||||||
(define-key ghc-input-map "\t" 'ghc-complete))
|
(define-key ghc-input-map "\t" 'ghc-complete))
|
||||||
|
|
||||||
(defun ghc-read-module-name (def)
|
|
||||||
(read-from-minibuffer "Module name: " def ghc-input-map))
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'ghc-doc)
|
(provide 'ghc-doc)
|
@ -38,4 +38,14 @@
|
|||||||
(read (current-buffer))
|
(read (current-buffer))
|
||||||
(error ()))))
|
(error ()))))
|
||||||
|
|
||||||
|
(defun ghc-extract-module ()
|
||||||
|
(interactive)
|
||||||
|
(save-excursion
|
||||||
|
(beginning-of-line)
|
||||||
|
(if (looking-at "^import +\\(qualified +\\)?\\([^ (\n]+\\)")
|
||||||
|
(match-string-no-properties 2))))
|
||||||
|
|
||||||
|
(defun ghc-read-module-name (def)
|
||||||
|
(read-from-minibuffer "Module name: " def ghc-input-map))
|
||||||
|
|
||||||
(provide 'ghc-func)
|
(provide 'ghc-func)
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
(defvar ghc-completion-key "\e\t")
|
(defvar ghc-completion-key "\e\t")
|
||||||
(defvar ghc-document-key "\e\C-d")
|
(defvar ghc-document-key "\e\C-d")
|
||||||
|
(defvar ghc-import-key "\e\C-e")
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;
|
;;;
|
||||||
@ -39,6 +40,7 @@
|
|||||||
(unless ghc-initialized
|
(unless ghc-initialized
|
||||||
(define-key haskell-mode-map ghc-completion-key 'ghc-complete)
|
(define-key haskell-mode-map ghc-completion-key 'ghc-complete)
|
||||||
(define-key haskell-mode-map ghc-document-key 'ghc-browse-document)
|
(define-key haskell-mode-map ghc-document-key 'ghc-browse-document)
|
||||||
|
(define-key haskell-mode-map ghc-import-key 'ghc-import-module)
|
||||||
(ghc-comp-init)
|
(ghc-comp-init)
|
||||||
(setq ghc-initialized t)))
|
(setq ghc-initialized t)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user