summaryrefslogtreecommitdiff
path: root/elisp
diff options
context:
space:
mode:
Diffstat (limited to 'elisp')
-rw-r--r--elisp/geiser-capf.el90
-rw-r--r--elisp/geiser-completion.el69
-rw-r--r--elisp/geiser-mode.el5
-rw-r--r--elisp/geiser-reload.el3
-rw-r--r--elisp/geiser-repl.el5
5 files changed, 99 insertions, 73 deletions
diff --git a/elisp/geiser-capf.el b/elisp/geiser-capf.el
new file mode 100644
index 0000000..73a6f07
--- /dev/null
+++ b/elisp/geiser-capf.el
@@ -0,0 +1,90 @@
+;;; geiser-capf.el -- Setup for Geiser's CAPFs
+
+;; Copyright (c) 2022 Jose Antonio Ortega Ruiz
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the Modified BSD License. You should
+;; have received a copy of the license along with this program. If
+;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
+
+;; Start date: Sat Apr 23, 2022 18:39
+
+
+
+(require 'geiser-autodoc)
+(require 'geiser-impl)
+(require 'geiser-eval)
+(require 'geiser-doc)
+(require 'geiser-completion)
+(require 'geiser-edit)
+
+(defun geiser-capf--company-docsig (id)
+ (ignore-errors
+ (when (not (geiser-autodoc--inhibit))
+ (let ((help (geiser-autodoc--autodoc `((,id 0)) nil)))
+ (and help (substring-no-properties help))))))
+
+(defun geiser-capf--company-doc-buffer (id)
+ (let* ((impl geiser-impl--implementation)
+ (module (geiser-eval--get-module))
+ (symbol (make-symbol id))
+ (ds (geiser-doc--get-docstring symbol module)))
+ (when (consp ds)
+ (with-current-buffer (get-buffer-create "*company-documentation*")
+ (geiser-doc--render-docstring ds symbol module impl)
+ (current-buffer)))))
+
+(defun geiser-capf--company-location (id)
+ (ignore-errors
+ (when (not (geiser-autodoc--inhibit))
+ (let ((id (make-symbol id)))
+ (condition-case nil
+ (geiser-edit-module id 'noselect)
+ (error (geiser-edit-symbol id 'noselect)))))))
+
+(defun geiser-capf--thing-at-point (module &optional predicate)
+ (with-syntax-table scheme-mode-syntax-table
+ (let* ((beg (geiser-completion--symbol-begin module))
+ (end (or (geiser-completion--prefix-end beg module) beg))
+ (prefix (and (> end beg) (buffer-substring-no-properties beg end)))
+ (prefix (and prefix
+ (if (string-match "\\([^-]+\\)-" prefix)
+ (match-string 1 prefix)
+ prefix)))
+ (cmps (and prefix (geiser-completion--complete prefix module))))
+ (when cmps
+ (list beg end cmps
+ :company-docsig #'geiser-capf--company-docsig
+ :company-doc-buffer #'geiser-capf--company-doc-buffer
+ :company-location #'geiser-capf--company-location)))))
+
+
+(defun geiser-capf--for-symbol (&optional predicate)
+ (geiser-capf--thing-at-point nil predicate))
+
+(defun geiser-capf--for-module (&optional predicate)
+ (geiser-capf--thing-at-point t predicate))
+
+(defun geiser-capf--for-filename ()
+ (when (geiser-syntax--in-string-p)
+ (let ((comint-completion-addsuffix "\""))
+ (ignore-errors (comint-filename-completion)))))
+
+(defun geiser-capf-setup (enable)
+ (set (make-local-variable 'completion-at-point-functions)
+ (if enable
+ '(geiser-capf--for-symbol
+ geiser-capf--for-module
+ geiser-capf--for-filename)
+ (default-value 'completion-at-point-functions))))
+
+(defun geiser-capf-complete-module ()
+ "Complete module name at point."
+ (interactive)
+ (let ((completion-at-point-functions '(geiser-completion--for-module)))
+ (call-interactively 'completion-at-point)))
+
+
+
+(provide 'geiser-capf)
+;;; geiser-capf.el ends here
diff --git a/elisp/geiser-completion.el b/elisp/geiser-completion.el
index 7696ec5..599e72f 100644
--- a/elisp/geiser-completion.el
+++ b/elisp/geiser-completion.el
@@ -1,6 +1,6 @@
;;; geiser-completion.el -- tab completion
-;; Copyright (C) 2009, 2010, 2011, 2012, 2018, 2020, 2021 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2009, 2010, 2011, 2012, 2018, 2020, 2021, 2022 Jose Antonio Ortega Ruiz
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
@@ -17,8 +17,6 @@
(require 'geiser-log)
(require 'geiser-syntax)
(require 'geiser-base)
-;; (require 'geiser-edit) TODO untangle cyclic dependency
-;; (require 'geiser-doc) TODO untangle cyclic dependency
(require 'comint)
(require 'minibuffer)
@@ -134,71 +132,6 @@ we're looking for a module name.")
(point)))
(scan-error pos)))))
-(defun geiser-completion--company-docsig (id)
- (ignore-errors
- (when (not (geiser-autodoc--inhibit))
- (let ((help (geiser-autodoc--autodoc `((,id 0)))))
- (and help (substring-no-properties help))))))
-
-(defun geiser-completion--company-doc-buffer (id)
- (let* ((impl geiser-impl--implementation)
- (module (geiser-eval--get-module))
- (symbol (make-symbol id))
- (ds (geiser-doc--get-docstring symbol module)))
- (when (consp ds)
- (with-current-buffer (get-buffer-create "*company-documentation*")
- (geiser-doc--render-docstring ds symbol module impl)
- (current-buffer)))))
-
-(defun geiser-completion--company-location (id)
- (ignore-errors
- (when (not (geiser-autodoc--inhibit))
- (let ((id (make-symbol id)))
- (condition-case nil
- (geiser-edit-module id 'noselect)
- (error (geiser-edit-symbol id 'noselect)))))))
-
-(defun geiser-completion--thing-at-point (module &optional predicate)
- (with-syntax-table scheme-mode-syntax-table
- (let* ((beg (geiser-completion--symbol-begin module))
- (end (or (geiser-completion--prefix-end beg module) beg))
- (prefix (and (> end beg) (buffer-substring-no-properties beg end)))
- (prefix (and prefix
- (if (string-match "\\([^-]+\\)-" prefix)
- (match-string 1 prefix)
- prefix)))
- (cmps (and prefix (geiser-completion--complete prefix module))))
- (when cmps
- (list beg end cmps
- :company-docsig #'geiser-completion--company-docsig
- :company-doc-buffer #'geiser-completion--company-doc-buffer
- :company-location #'geiser-completion--company-location)))))
-
-(defun geiser-completion--for-symbol (&optional predicate)
- (geiser-completion--thing-at-point nil predicate))
-
-(defun geiser-completion--for-module (&optional predicate)
- (geiser-completion--thing-at-point t predicate))
-
-(defun geiser-completion--for-filename ()
- (when (geiser-syntax--in-string-p)
- (let ((comint-completion-addsuffix "\""))
- (ignore-errors (comint-filename-completion)))))
-
-(defun geiser-completion--setup (enable)
- (set (make-local-variable 'completion-at-point-functions)
- (if enable
- '(geiser-completion--for-symbol
- geiser-completion--for-module
- geiser-completion--for-filename)
- (default-value 'completion-at-point-functions))))
-
-(defun geiser-completion--complete-module ()
- "Complete module name at point."
- (interactive)
- (let ((completion-at-point-functions '(geiser-completion--for-module)))
- (call-interactively 'completion-at-point)))
-
;;; Smart tab mode:
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index 2354bf2..e0e22c6 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -13,6 +13,7 @@
;;; Code:
(require 'geiser-repl)
+(require 'geiser-capf)
(require 'geiser-menu)
(require 'geiser-doc)
(require 'geiser-compile)
@@ -341,7 +342,7 @@ With prefix, try to enter the current buffer's module."
("Complete symbol" ((kbd "M-TAB")) completion-at-point
:enable (geiser--symbol-at-point))
("Complete module name" ((kbd "M-`") (kbd "C-."))
- geiser-completion--complete-module)
+ geiser-capf-complete-module)
("Edit module" ("\C-c\C-e\C-m" "\C-c\C-em") geiser-edit-module)
("Add to load path..." ("\C-c\C-e\C-l" "\C-c\C-el") geiser-add-to-load-path)
("Toggle ()/[]" ("\C-c\C-e\C-[" "\C-c\C-e[") geiser-squarify)
@@ -385,7 +386,7 @@ interacting with the Geiser REPL is at your disposal.
(when geiser-mode (geiser-impl--set-buffer-implementation nil t))
(setq geiser-autodoc-mode-string "/A")
(setq geiser-smart-tab-mode-string "/T")
- (geiser-completion--setup geiser-mode)
+ (geiser-capf-setup geiser-mode)
(when geiser-mode-autodoc-p
(geiser-autodoc-mode (if geiser-mode 1 -1)))
(when geiser-mode-smart-tab-p
diff --git a/elisp/geiser-reload.el b/elisp/geiser-reload.el
index e6bea24..0cd3b51 100644
--- a/elisp/geiser-reload.el
+++ b/elisp/geiser-reload.el
@@ -1,6 +1,6 @@
;;; geiser-reload.el -- unload/load geiser packages
-;; Copyright (C) 2009, 2010, 2012, 2020, 2021 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2009, 2010, 2012, 2020, 2021, 2022 Jose Antonio Ortega Ruiz
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
@@ -25,6 +25,7 @@
(quote '(
geiser-mode
geiser-repl
+ geiser-capf
geiser-doc
geiser-xref
geiser-compile
diff --git a/elisp/geiser-repl.el b/elisp/geiser-repl.el
index e9567b3..5a004e5 100644
--- a/elisp/geiser-repl.el
+++ b/elisp/geiser-repl.el
@@ -10,6 +10,7 @@
;;; Code:
+(require 'geiser-capf)
(require 'geiser-doc)
(require 'geiser-autodoc)
(require 'geiser-edit)
@@ -871,7 +872,7 @@ buffer."
("Complete symbol" ((kbd "M-TAB"))
completion-at-point :enable (geiser--symbol-at-point))
("Complete module name" ((kbd "C-.") (kbd "M-`"))
- geiser-completion--complete-module :enable (geiser--symbol-at-point))
+ geiser-capf-complete-module :enable (geiser--symbol-at-point))
("Edit symbol" "\M-." geiser-edit-symbol-at-point
:enable (geiser--symbol-at-point))
--
@@ -936,7 +937,7 @@ buffer."
(set (make-local-variable 'comint-input-ignoredups)
geiser-repl-history-no-dups-p)
(setq geiser-eval--get-module-function 'geiser-repl--module-function)
- (geiser-completion--setup t)
+ (geiser-capf-setup t)
(setq geiser-smart-tab-mode-string "")
(geiser-smart-tab-mode t)