From e9c4ec4e4b1baff592319eba70e44be1a2f25c22 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 6 Jan 2010 14:39:30 +0900 Subject: [PATCH] ESC C-e to process the module. --- Setup.hs | 2 -- elisp/ghc-comp.el | 46 +++++++++++++++++++++++++++++----------------- elisp/ghc-doc.el | 10 ---------- elisp/ghc-func.el | 10 ++++++++++ elisp/ghc.el | 2 ++ 5 files changed, 41 insertions(+), 29 deletions(-) delete mode 100644 Setup.hs diff --git a/Setup.hs b/Setup.hs deleted file mode 100644 index 9a994af..0000000 --- a/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/elisp/ghc-comp.el b/elisp/ghc-comp.el index b4163ed..a4a9ea6 100644 --- a/elisp/ghc-comp.el +++ b/elisp/ghc-comp.el @@ -131,26 +131,44 @@ (defun ghc-completion-start-point () (save-excursion (let ((beg (save-excursion (beginning-of-line) (point)))) - (if (search-backward " " beg t) + (if (re-search-backward "[ (,`]" beg t) (1+ (point)) 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 ;;; (defun ghc-idle-timer () - (let ((mods (ghc-gather-import-modules)) - keywords) - (dolist (mod mods) - (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))) + (dolist (mod (ghc-gather-import-modules)) + (ghc-load-module mod)) + (ghc-merge-keywords)) (defun ghc-gather-import-modules () (let ((bufs (mapcar 'buffer-name (buffer-list))) @@ -171,12 +189,6 @@ (forward-line))) 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) (symbol-value (intern (concat ghc-keyword-prefix mod)))) diff --git a/elisp/ghc-doc.el b/elisp/ghc-doc.el index 6f1fa16..5af31ab 100644 --- a/elisp/ghc-doc.el +++ b/elisp/ghc-doc.el @@ -18,13 +18,6 @@ (pkg (ghc-resolve-package-name 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) (with-temp-buffer (call-process "ghc-pkg" nil t nil "find-module" "--simple-output" mod) @@ -57,8 +50,5 @@ (make-sparse-keymap))) (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) \ No newline at end of file diff --git a/elisp/ghc-func.el b/elisp/ghc-func.el index 81f7b3d..824b184 100644 --- a/elisp/ghc-func.el +++ b/elisp/ghc-func.el @@ -38,4 +38,14 @@ (read (current-buffer)) (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) diff --git a/elisp/ghc.el b/elisp/ghc.el index e522ca5..99caa73 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -27,6 +27,7 @@ (defvar ghc-completion-key "\e\t") (defvar ghc-document-key "\e\C-d") +(defvar ghc-import-key "\e\C-e") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -39,6 +40,7 @@ (unless ghc-initialized (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-import-key 'ghc-import-module) (ghc-comp-init) (setq ghc-initialized t)))