From 359f70de49fbc5c8a7d306a3f5203519fc11e4c8 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: Thu, 23 Jul 2015 12:06:13 +0500 Subject: [PATCH 1/4] Introduce completion candidates limit customization --- haskell-customize.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/haskell-customize.el b/haskell-customize.el index e6ac83ebd..fe837d6ce 100644 --- a/haskell-customize.el +++ b/haskell-customize.el @@ -347,6 +347,15 @@ same vein as `haskell-indent-spaces'." :group 'haskell :type '(repeat 'string)) +(defcustom haskell-completion-candidates-limit + 100 + "Maximum number of completion candidates. Value must be +positive integer to take effect. In othercase completion +candidates count supposed to be unlimited. Some predifed +completions sources (e.g. pragma completions) currently ignore +this option." + :group 'haskell + :type '(integer)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Accessor functions From 196936e5eef1ddf0fed250c8f76a23acd7fe29a9 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: Thu, 23 Jul 2015 12:09:42 +0500 Subject: [PATCH 2/4] Define a safe function to get completion candidates limit --- haskell-completions.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/haskell-completions.el b/haskell-completions.el index b99e6dc19..606e38d43 100644 --- a/haskell-completions.el +++ b/haskell-completions.el @@ -39,6 +39,7 @@ (require 'haskell-mode) (require 'haskell-process) (require 'haskell-interactive-mode) +(require 'haskell-customize) (defvar haskell-completions-pragma-names (list "DEPRECATED" @@ -272,5 +273,13 @@ This function is supposed for internal use." (dabbrev--reset-global-variables) (dabbrev--find-all-expansions prefix nil)) +(defun haskell-completions-get-candidates-limit () + "Return valid completion candidates limit." + (if (and haskell-completion-candidates-limit + (< haskell-completion-candidates-limit 1)) + nil + haskell-completion-candidates-limit)) + + (provide 'haskell-completions) ;;; haskell-completions.el ends here From a14f0c91feec2085f06fbfad70cdb3dd092be2b7 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: Thu, 23 Jul 2015 12:10:45 +0500 Subject: [PATCH 3/4] Take completion candidates limit into account Take into account completion candidates limit when searching completions using REPL or DABBREV facility. Also clean up completion list from REPL: currently `haskell-process-get-repl-completions` returns unused part of line as first item of list (e.g. it will be "map " for line "map co", and empty string for "ma" line). --- haskell-completions.el | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/haskell-completions.el b/haskell-completions.el index 606e38d43..c4405a00a 100644 --- a/haskell-completions.el +++ b/haskell-completions.el @@ -261,17 +261,41 @@ Returns nil if no completions available." When optional IMPORT argument is non-nil complete PREFIX prepending \"import \" keyword (useful for module names). This function is supposed for internal use." - (haskell-process-get-repl-completions - (haskell-interactive-process) - (if import - (concat "import " prefix) - prefix))) + (let ((ccs (haskell-process-get-repl-completions + (haskell-interactive-process) + (if import + (concat "import " prefix) + prefix) + (haskell-completions-get-candidates-limit)))) + ;; `haskell-process-get-repl-completions' returns unused part of line as + ;; first item in completions list, e.g. for "map co" prefix first element + ;; will be "map " followed by completions for "co" part of input. It is + ;; currently unused. + (when ccs (cdr ccs)))) (defun haskell-completions-dabbrev-completions (prefix) "Return completion list for PREFIX using dabbrev facility. This function is supposed for internal use." - (dabbrev--reset-global-variables) - (dabbrev--find-all-expansions prefix nil)) + (let ((limit (haskell-completions-get-candidates-limit))) + (dabbrev--reset-global-variables) + (if limit + (haskell-completions-dabbrev-find-limit-expansions prefix limit) + (dabbrev--find-all-expansions prefix nil)))) + +(defun haskell-completions-dabbrev-find-limit-expansions (prefix limit) + "Search list of dabbrev expansions for PREFIX limited by LIMIT." + ;; The idea stolen from http://emacswiki.org/emacs/ac-dabbrev.el + (let ((i 0) + (all-expansions nil) + expansion) + (while (and (< i limit) + (setq expansion (dabbrev--find-expansion prefix -1 nil))) + (setq all-expansions (cons expansion all-expansions)) + ;; Note: sometimes dabbrev expansions return such list: + ;; m ma map mapC ... mapConcat + ;; this is the best place to introduce workaround for this stuff. + (setq i (+ i 1))) + all-expansions)) (defun haskell-completions-get-candidates-limit () "Return valid completion candidates limit." From 66e822a0dfd7355f77af4c8a4789e3853d3f979f 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: Tue, 28 Jul 2015 12:56:15 +0500 Subject: [PATCH 4/4] Disable dabbrev completions mechanism --- haskell-completions.el | 69 ++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/haskell-completions.el b/haskell-completions.el index c4405a00a..86ca3c8f8 100644 --- a/haskell-completions.el +++ b/haskell-completions.el @@ -249,10 +249,10 @@ Returns nil if no completions available." ;; for completions list in case of module name or ;; identifier prefixes (haskell-completions-sync-complete-repl pfx imp))))) - (when (or (equal '("") lst) - (eql nil lst)) - ;; complete things using dabbrev - (setq lst (haskell-completions-dabbrev-completions pfx))) + ;; (when (or (equal '("") lst) + ;; (eql nil lst)) + ;; ;; complete things using dabbrev + ;; (setq lst (haskell-completions-dabbrev-completions pfx))) (when lst (list beg end lst))))))) @@ -261,41 +261,36 @@ Returns nil if no completions available." When optional IMPORT argument is non-nil complete PREFIX prepending \"import \" keyword (useful for module names). This function is supposed for internal use." - (let ((ccs (haskell-process-get-repl-completions - (haskell-interactive-process) - (if import - (concat "import " prefix) - prefix) - (haskell-completions-get-candidates-limit)))) - ;; `haskell-process-get-repl-completions' returns unused part of line as - ;; first item in completions list, e.g. for "map co" prefix first element - ;; will be "map " followed by completions for "co" part of input. It is - ;; currently unused. - (when ccs (cdr ccs)))) + (haskell-process-get-repl-completions + (haskell-interactive-process) + (if import + (concat "import " prefix) + prefix) + (haskell-completions-get-candidates-limit))) -(defun haskell-completions-dabbrev-completions (prefix) - "Return completion list for PREFIX using dabbrev facility. -This function is supposed for internal use." - (let ((limit (haskell-completions-get-candidates-limit))) - (dabbrev--reset-global-variables) - (if limit - (haskell-completions-dabbrev-find-limit-expansions prefix limit) - (dabbrev--find-all-expansions prefix nil)))) +;; (defun haskell-completions-dabbrev-completions (prefix) +;; "Return completion list for PREFIX using dabbrev facility. +;; This function is supposed for internal use." +;; (let ((limit (haskell-completions-get-candidates-limit))) +;; (dabbrev--reset-global-variables) +;; (if limit +;; (haskell-completions-dabbrev-find-limit-expansions prefix limit) +;; (dabbrev--find-all-expansions prefix nil)))) -(defun haskell-completions-dabbrev-find-limit-expansions (prefix limit) - "Search list of dabbrev expansions for PREFIX limited by LIMIT." - ;; The idea stolen from http://emacswiki.org/emacs/ac-dabbrev.el - (let ((i 0) - (all-expansions nil) - expansion) - (while (and (< i limit) - (setq expansion (dabbrev--find-expansion prefix -1 nil))) - (setq all-expansions (cons expansion all-expansions)) - ;; Note: sometimes dabbrev expansions return such list: - ;; m ma map mapC ... mapConcat - ;; this is the best place to introduce workaround for this stuff. - (setq i (+ i 1))) - all-expansions)) +;; (defun haskell-completions-dabbrev-find-limit-expansions (prefix limit) +;; "Search list of dabbrev expansions for PREFIX limited by LIMIT." +;; ;; The idea stolen from http://emacswiki.org/emacs/ac-dabbrev.el +;; (let ((i 0) +;; (all-expansions nil) +;; expansion) +;; (while (and (< i limit) +;; (setq expansion (dabbrev--find-expansion prefix -1 nil))) +;; (setq all-expansions (cons expansion all-expansions)) +;; ;; Note: sometimes dabbrev expansions return such list: +;; ;; m ma map mapC ... mapConcat +;; ;; this is the best place to introduce workaround for this stuff. +;; (setq i (+ i 1))) +;; all-expansions)) (defun haskell-completions-get-candidates-limit () "Return valid completion candidates limit."