branch: elpa/geiser-kawa commit 8d6202feb1c347ae00f2ca139c7f31a886454cd5 Author: spellcard199 <spellcard...@protonmail.com> Commit: spellcard199 <spellcard...@protonmail.com>
Refactor + Fix style + Copyright notices --- elisp/geiser-kawa-arglist.el | 49 +++++++++---- elisp/geiser-kawa-deps.el | 26 ++++--- elisp/geiser-kawa-devutil-complete.el | 12 ++-- elisp/geiser-kawa-ext-help.el | 82 ++++++++++++++-------- elisp/geiser-kawa-globals.el | 97 ++++++++++++++++++++++++++ elisp/geiser-kawa-util.el | 3 + elisp/geiser-kawa.el | 128 +++------------------------------- 7 files changed, 223 insertions(+), 174 deletions(-) diff --git a/elisp/geiser-kawa-arglist.el b/elisp/geiser-kawa-arglist.el index 2dd4c25..f3f5dcd 100644 --- a/elisp/geiser-kawa-arglist.el +++ b/elisp/geiser-kawa-arglist.el @@ -1,5 +1,12 @@ ;;; geiser-kawa-arglist.el --- Command-line arguments for Geiser support in Kawa -*- lexical-binding: t -*- +;; Copyright (C) 2019, 2020 spellcard199 <spellcard...@protonmail.com> + +;; 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>. + ;;; Commentary: ;; Code for handling command line executable and arguments to obtain ;; geiser support in Kawa. @@ -8,19 +15,10 @@ ;; it is also supported by setting to non-nil the variable ;; `geiser-kawa-user-included-kawa'. -;;; Code: +(require 'geiser-kawa-globals) +(require 'compile) -(defvar geiser-kawa--arglist - `(;; jline "invisibly" echoes user input and prints ansi chars that - ;; makes harder detecting end of output and finding the correct - ;; prompt regexp. - "console:use-jline=no" - "-e" - "(require <kawageiser.Geiser>)" - "--") - "Variable containing the parameters to pass to Kawa at startup. -If you really want to customize this, note that the default ones -are all required for `geiser-kawa' to work.") +;;; Code: (defun geiser-kawa--binary () "Return the binary to call to start Kawa. @@ -90,6 +88,33 @@ Argument CLASSPATH is a string containing the classpath." (list "kawa.repl")) geiser-kawa--arglist)) +(defun geiser-kawa--version-command (binary) + "Return command to get kawa version. +Argument BINARY argument passed by Geiser." + (let* ((program (if geiser-kawa-use-included-kawa + "java" + "kawa")) + (args (if geiser-kawa-use-included-kawa + (list (geiser-kawa-arglist--make-classpath-arg + geiser-kawa-deps-jar-path) + "kawa.repl" + "--version") + (list "--version"))) + (output (apply #'process-lines + (cons program args))) + (progname-plus-version (car output))) + ;; `progname-plus-version' is something like: + ;; "Kawa 3.1.1" + (cadr (split-string progname-plus-version " ")))) + +(defun geiser-kawa--repl-startup (remote) + "Geiser's repl-startup. +Argument REMOTE passed by Geiser." + ;; Does nothing for now. Keeping for reference. + ;; (let ((geiser-log-verbose-p t)) + ;; (compilation-setup t)) + ) + (provide 'geiser-kawa-arglist) ;;; geiser-kawa-arglist.el ends here diff --git a/elisp/geiser-kawa-deps.el b/elisp/geiser-kawa-deps.el index 9411fd7..221cdcb 100644 --- a/elisp/geiser-kawa-deps.el +++ b/elisp/geiser-kawa-deps.el @@ -1,5 +1,12 @@ ;;; geiser-kawa-deps.el --- Manage geiser-kawa's java dependencies -*- lexical-binding:t -*- +;; Copyright (C) 2019, 2020 spellcard199 <spellcard...@protonmail.com> + +;; 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>. + ;;; Commentary: ;; This file contains code related to the download, compilation ;; and packaging of `kawa-geiser', the java dependency (with its @@ -8,17 +15,16 @@ ;; `mvnw package', which uses the pom.xml for the `kawa-geiser' ;; project, included in the `geiser-kawa-dir' directory. +;; Depends on global vars: +;; `geiser-kawa-dir' + ;;; Code: -(require 'cl) +(require 'cl-lib) +(require 'geiser-kawa-globals) -(cl-defun geiser-kawa-deps--jar-path +(cl-defun geiser-kawa-deps-mvnw-package (&optional (geiser-kawa-dir geiser-kawa-dir)) - (expand-file-name - "./target/kawa-geiser-0.1-SNAPSHOT-jar-with-dependencies.jar" - geiser-kawa-dir)) - -(defun geiser-kawa-deps-mvnw-package (geiser-kawa-dir) "Download, Compile and Package `geiser-kawa's java dependencies. When called, this function runs `mvnw package' from the path specified by the variable `GEISER-KAWA-DIR'. @@ -32,7 +38,7 @@ at REPL startup." (when mvn-buf (let ((save-buf (current-buffer))) (switch-to-buffer-other-window mvn-buf) - (end-of-buffer) + (goto-char (point-max)) (switch-to-buffer-other-window save-buf))))) @@ -74,8 +80,8 @@ at REPL startup." Runs `run-kawa' without the `geiser-kawa-deps--run-kawa--advice' advice and removes itself from `compilation-finish-functions', effectively running `run-kawa' unadviced only for one compilation. -Argument BUF passed by Emacs when compilation finishes. -Argument DESC passed by Emacs when compilation finishes." +Argument BUF is passed by Emacs when compilation finishes. +Argument DESC is passed by Emacs when compilation finishes." (geiser-kawa-deps--run-kawa-unadviced) (remove-hook 'compilation-finish-functions #'geiser-kawa-deps--run-kawa--remove-compil-hook)) diff --git a/elisp/geiser-kawa-devutil-complete.el b/elisp/geiser-kawa-devutil-complete.el index 7e01006..cc0a773 100644 --- a/elisp/geiser-kawa-devutil-complete.el +++ b/elisp/geiser-kawa-devutil-complete.el @@ -7,7 +7,6 @@ ;; have received a copy of the license along with this program. If ;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>. - ;;; Commentary: ;; Provide completions using kawa-devutil. Compared to the way plain ;; geiser provides completion this has advantages and disadvantages. @@ -37,8 +36,8 @@ must happen. It must be syntactically correct Kawa scheme. Argument CURSOR-INDEX is an integer representing where the cursor is inside `CURSOR-STR'." ;; "`code-str' is a string containing the code. -;; It must be syntatically scheme, including balanced parentheses. -;; `cursor-index' is an integer representing where the cursor is in that code." + ;; It must be syntatically scheme, including balanced parentheses. + ;; `cursor-index' is an integer representing where the cursor is in that code." (let* ((geiser-question ;; this formatting hell is caused by the fact geiser:eval ;; takes a string instead of a form. @@ -62,15 +61,15 @@ inside `CURSOR-STR'." (defun geiser-kawa-devutil-complete--user-choice-classmembers (classmember-data) "Read completion choice for members of class (Methods and Fields). - Argument CLASSMEMBER-DATA is completion data for members of class as returned by kawa-geiser." (let* ((completion-type (cadr (assoc "completion-type" classmember-data))) (before-cursor (cadr (assoc "before-cursor" classmember-data))) - (after-cursor ;; unused - (cadr (assoc "after-cursor" classmember-data))) + ;; unused + ;; (after-cursor + ;; (cadr (assoc "after-cursor" classmember-data))) (owner-class (cadr (assoc "owner-class" classmember-data))) (modifiers @@ -186,7 +185,6 @@ members of package as returned by kawa-geiser." (setq cursor-index (- (point) reg-beg)))) (setq code-str (buffer-substring-no-properties reg-beg reg-end)) - (setq moo code-str) (list `("reg-beg" . ,reg-beg) `("reg-end" . ,reg-end) diff --git a/elisp/geiser-kawa-ext-help.el b/elisp/geiser-kawa-ext-help.el index 8771eee..94464b1 100644 --- a/elisp/geiser-kawa-ext-help.el +++ b/elisp/geiser-kawa-ext-help.el @@ -1,32 +1,60 @@ ;;; geiser-kawa-ext-help.el --- Support for the "external-help" geiser feature -*- lexical-binding:t -*- +;; Copyright (C) 2020 spellcard199 <spellcard...@protonmail.com> + +;; 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>. + ;;; Commentary: ;; Functions for providing the "external-help" Geiser feature. ;; Currently, the external help for Kawa is the kawa manual in either ;; its .info or .epub format. For the feature to work ;; `geiser-kawa-manual-path' must point to where the .info or .epub ;; Kawa manual is located. +;; Depends on global variables: +;; `geiser-kawa-binary' + +(require 'cl-lib) +(require 'geiser-custom) +(require 'geiser-impl) +(require 'geiser-eval) +(require 'eww) +(require 'info) +(require 'geiser-kawa-globals) ;;; Code: ;; Support for manual in .epub format +(geiser-custom--defcustom + geiser-kawa-manual-path + (when (executable-find geiser-kawa-binary) + (expand-file-name + "../doc/kawa-manual.epub" + (file-name-directory + (executable-find geiser-kawa-binary)))) + "Path of kawa manual. Supported formats are `.epub' (using +`eww-mode') and `.info' (using `info.el')." + :type 'string + :group 'geiser-kawa) + (cl-defun geiser-kawa-manual--epub-unzip-to-tmpdir (&optional (epub-path geiser-kawa-manual-path)) "Unzip the .epub file using kawa/java. Rationale for using java instead of emacs: -- kawa is already a dependency -- kawa/java is more portable that using emacs' `arc-mode', which relies - on external executables being installed" +- Kawa is already a dependency. +- Kawa/java is more portable that using emacs' `arc-mode', + which relies on external executables being installed." (with-temp-buffer - (with--geiser-implementation - 'kawa - (geiser-eval--send/result - (format - "(geiser:eval (interaction-environment) %S)" - (format "(geiser:manual-epub-unzip-to-tmp-dir %S)" - epub-path)))))) + (geiser-impl--set-buffer-implementation 'kawa) + (geiser-eval--send/result + (format + "(geiser:eval (interaction-environment) %S)" + (format "(geiser:manual-epub-unzip-to-tmp-dir %S)" + epub-path))))) (defvar geiser-kawa-manual--epub-cached-overall-index nil @@ -37,10 +65,10 @@ the manual are more responsive.") (cl-defun geiser-kawa-manual--epub-search (needle &optional (epub-path geiser-kawa-manual-path)) ;; Validate args - (assert (stringp needle) nil (type-of needle)) - (assert (stringp epub-path) nil (type-of epub-path)) - (assert (string-suffix-p ".epub" epub-path) nil epub-path) - (assert (file-exists-p epub-path) nil epub-path) + (cl-assert (stringp needle) nil (type-of needle)) + (cl-assert (stringp epub-path) nil (type-of epub-path)) + (cl-assert (string-suffix-p ".epub" epub-path) nil epub-path) + (cl-assert (file-exists-p epub-path) nil epub-path) (with-current-buffer (get-buffer-create " *geiser-kawa-epub-manual*") @@ -55,9 +83,7 @@ the manual are more responsive.") ;; with emacs' `arc-mode'. (geiser-kawa-manual--epub-unzip-to-tmpdir epub-path)) (overall-index-file - (format "%s/OEBPS/Overall-Index.xhtml" unzipped-epub-dir)) - (epub-man-buffer - (get-buffer-create "*geiser-kawa-epub-manual*"))) + (format "%s/OEBPS/Overall-Index.xhtml" unzipped-epub-dir))) (unless unzipped-epub-dir (error "Can't open manual: Kawa did not unzip the epub when asked")) (eww-open-file overall-index-file) @@ -78,10 +104,10 @@ the manual are more responsive.") (cl-defun geiser-kawa-manual--info-search (needle &optional (info-path geiser-kawa-manual-path)) ;; Validate args - (assert (stringp needle) nil (type-of needle)) - (assert (stringp info-path) nil (type-of info-path)) - (assert (string-suffix-p ".info" info-path) nil info-path) - (assert (file-exists-p info-path) nil info-path) + (cl-assert (stringp needle) nil (type-of needle)) + (cl-assert (stringp info-path) nil (type-of info-path)) + (cl-assert (string-suffix-p ".info" info-path) nil info-path) + (cl-assert (file-exists-p info-path) nil info-path) (with-current-buffer (get-buffer-create "*geiser-kawa-info-manual*") (info info-path (current-buffer)) @@ -101,13 +127,13 @@ the manual are more responsive.") "Use epub or info manual depending on `geiser-kawa-manual-path'. Argument ID is the symbol to look for in the manual. -Argument MOD is passed by geiser, but it's not used here." - (assert (file-exists-p geiser-kawa-manual-path) - nil (format - (concat - "Kawa's manual file specified by " - "`geiser-kawa-manual-path' does not exist: \"%s\"") - geiser-kawa-manual-path)) +Argument MOD is passed by geiser, but it's not used here yet." + (cl-assert (file-exists-p geiser-kawa-manual-path) + nil (format + (concat + "Kawa's manual file specified by " + "`geiser-kawa-manual-path' does not exist: \"%s\"") + geiser-kawa-manual-path)) (cond ((string-suffix-p ".epub" geiser-kawa-manual-path) (geiser-kawa-manual--epub-search (symbol-name id) diff --git a/elisp/geiser-kawa-globals.el b/elisp/geiser-kawa-globals.el new file mode 100644 index 0000000..d3925df --- /dev/null +++ b/elisp/geiser-kawa-globals.el @@ -0,0 +1,97 @@ +;;; geiser-kawa-globals.el --- Global variables for geiser-kawa sub-packages -*- lexical-binding:t -*- + +;; Copyright (C) 2019, 2020 spellcard199 <spellcard...@protonmail.com> + +;; 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>. + +;;; Commentary: +;; Global variables that geiser-kawa's sub-packages can require. +;; The reason these variables are in a stand-alone file is so that: +;; - they can be require'd by any of the geiser-kawa sub-packages +;; without causing circular dependency errors. +;; - flycheck is happy. + +(require 'geiser-impl) + +;;; Code: + +;;; Adaptations for making this package separate from geiser + +;; Adapted from geiser.el +;;;###autoload +(defconst geiser-kawa-elisp-dir + (file-name-directory (or load-file-name (buffer-file-name))) + "Directory containing geiser-kawa's Elisp files.") + +;; Adapted from geiser.el +;;;###autoload +(defconst geiser-kawa-dir + (if (string-suffix-p "elisp/" geiser-kawa-elisp-dir) + (expand-file-name "../" geiser-kawa-elisp-dir) + geiser-kawa-elisp-dir) + "Directory where geiser-kawa is located.") + +;; Adapted from geiser.el +(custom-add-load 'geiser-kawa (symbol-name 'geiser-kawa)) +(custom-add-load 'geiser (symbol-name 'geiser-kawa)) + +;; Moved from geiser.el +;;;###autoload +(autoload 'run-kawa "geiser-kawa" "Start a Geiser Kawa Scheme REPL." t) + +;;;###autoload +(autoload 'switch-to-kawa "geiser-kawa" + "Start a Geiser Kawa Scheme REPL, or switch to a running one." t) + +;; `geiser-active-implementations' is defined in `geiser-impl.el' +(add-to-list 'geiser-active-implementations 'kawa) + +;; End of adaptations for making this package separate from geiser + +(defgroup geiser-kawa nil + "Customization for Geiser's Kawa Scheme flavour." + :group 'geiser) + +(geiser-custom--defcustom + geiser-kawa-binary "kawa" + "Name to use to call the Kawa Scheme executable when starting a REPL." + :type '(choice string (repeat string)) + :group 'geiser-kawa) + +(defcustom geiser-kawa-deps-jar-path + (expand-file-name + "./target/kawa-geiser-0.1-SNAPSHOT-jar-with-dependencies.jar" + geiser-kawa-dir) + "Path to the kawa-geiser fat jar." + :type 'string + :group 'geiser-kawa) + +(defcustom geiser-kawa-use-included-kawa + nil + "Use the Kawa included with `geiser-kawa' instead of the `kawa' binary. +Instead of downloading kawa yourself, you can use the Kawa version +included in `geiser-kawa'." + :type 'boolean + :group 'geiser-kawa) + +(defvar geiser-kawa--arglist + `(;; jline "invisibly" echoes user input and prints ansi chars that + ;; makes harder detecting end of output and finding the correct + ;; prompt regexp. + "console:use-jline=no" + "-e" + "(require <kawageiser.Geiser>)" + "--") + "Variable containing the parameters to pass to Kawa at startup. +If you really want to customize this, note that the default ones +are all required for `geiser-kawa' to work.") + +(defconst geiser-kawa--prompt-regexp + "#|kawa:[0-9]+|# ") + +(provide 'geiser-kawa-globals) + +;;; geiser-kawa-globals.el ends here diff --git a/elisp/geiser-kawa-util.el b/elisp/geiser-kawa-util.el index 5de575f..0df4200 100644 --- a/elisp/geiser-kawa-util.el +++ b/elisp/geiser-kawa-util.el @@ -10,8 +10,11 @@ ;;; Commentary: ;; Some general utility functions used by the `geiser-kawa' package. +(require 'subr-x) (require 'geiser-syntax) (require 'geiser-eval) +(require 'geiser-kawa-globals) +(require 'geiser-repl) ;; Utility functions used by other parts of `geiser-kawa'. diff --git a/elisp/geiser-kawa.el b/elisp/geiser-kawa.el index d253377..7ef3e37 100644 --- a/elisp/geiser-kawa.el +++ b/elisp/geiser-kawa.el @@ -18,7 +18,6 @@ ;; This file is NOT part of GNU Emacs. ;;; Commentary: - ;; geiser-kawa extends the `geiser' package to support the Kawa ;; scheme implementation. @@ -34,109 +33,29 @@ (require 'compile) (require 'info-look) -(require 'cl) +(require 'cl-lib) +(require 'geiser-kawa-globals) (require 'geiser-kawa-deps) (require 'geiser-kawa-devutil-complete) (require 'geiser-kawa-devutil-exprtree) (require 'geiser-kawa-arglist) (require 'geiser-kawa-ext-help) -;;; Code: - - -;; Adaptations for making this package separate from geiser - -;; Adapted from geiser.el -;;;###autoload -(defconst geiser-kawa-elisp-dir - (file-name-directory (or load-file-name (buffer-file-name))) - "Directory containing geiser-kawa's Elisp files.") - -;; Adapted from geiser.el -;;;###autoload -(defconst geiser-kawa-dir - (if (string-suffix-p "elisp/" geiser-kawa-elisp-dir) - (expand-file-name "../" geiser-kawa-elisp-dir) - geiser-kawa-elisp-dir) - "Directory where geiser-kawa is located.") - -;; Adapted from geiser.el -(custom-add-load 'geiser-kawa (symbol-name 'geiser-kawa)) -(custom-add-load 'geiser (symbol-name 'geiser-kawa)) - -;; Moved from geiser.el -;;;###autoload -(autoload 'run-kawa "geiser-kawa" "Start a Geiser Kawa Scheme REPL." t) - -;;;###autoload -(autoload 'switch-to-kawa "geiser-kawa" - "Start a Geiser Kawa Scheme REPL, or switch to a running one." t) - -;; `geiser-active-implementations' is defined in `geiser-impl.el' -(add-to-list 'geiser-active-implementations 'kawa) - -;; End of adaptations for making this package separate from geiser - - -;;; Customization: - -(defgroup geiser-kawa nil - "Customization for Geiser's Kawa Scheme flavour." - :group 'geiser) - -(geiser-custom--defcustom - geiser-kawa-binary "kawa" - "Name to use to call the Kawa Scheme executable when starting a REPL." - :type '(choice string (repeat string)) - :group 'geiser-kawa) - -(geiser-custom--defcustom - geiser-kawa-manual-path - (when (executable-find geiser-kawa-binary) - (expand-file-name - "../doc/kawa-manual.epub" - (file-name-directory - (executable-find geiser-kawa-binary)))) - "Path of kawa manual. Supported formats are `.epub' (using -`eww-mode') and `.info' (using `info.el')." - :type 'string - :group 'geiser-kawa) - -(defcustom geiser-kawa-deps-jar-path - (geiser-kawa-deps--jar-path geiser-kawa-dir) - "Path to the kawa-geiser fat jar." - :type 'string - :group 'geiser-kawa) - -(defcustom geiser-kawa-use-included-kawa - nil - "Use the Kawa included with `geiser-kawa' instead of the `kawa' binary. - -Instead of downloading kawa yourself, you can use the Kawa version -included in `geiser-kawa'." - :type 'boolean - :group 'geiser-kawa) - +;;; Code: ;;; REPL support: -(defconst geiser-kawa--prompt-regexp - "#|kawa:[0-9]+|# ") - (defun geiser-kawa--geiser-procedure (proc &rest args) "Geiser's marshall-procedure for `geiser-kawa'. Argument PROC passed by Geiser. Optional argument ARGS passed by Geiser." - (case proc + (cl-case proc ((eval compile) - (let* ((form (mapconcat 'identity args " ")) ;;unused - (send-this - (format - "(geiser:eval (interaction-environment) %S)" - (cadr args)))) - send-this)) + (format + "(geiser:eval (interaction-environment) %S)" + (cadr args))) ((load-file compile-file) (format "(geiser:load-file %s)" (car args))) @@ -175,44 +94,19 @@ Argument MODULE argument passed by Geiser." ;;; REPL startup -(defun geiser-kawa--version-command (binary) - "Return command to get kawa version. -Argument BINARY argument passed by Geiser." - (let* ((program (if geiser-kawa-use-included-kawa - "java" - "kawa")) - (args (if geiser-kawa-use-included-kawa - (list (geiser-kawa-arglist--make-classpath-arg - geiser-kawa-deps-jar-path) - "kawa.repl" - "--version") - (list "--version"))) - (output (apply #'process-lines - (cons program args))) - (progname-plus-version (car output))) - ;; `progname-plus-version' is something like: - ;; "Kawa 3.1.1" - (cadr (split-string progname-plus-version " ")))) - -(defun geiser-kawa--repl-startup (remote) - "Geiser's repl-startup. -Argument REMOTE passed by Geiser." - (let ((geiser-log-verbose-p t)) - (compilation-setup t))) - ;;; Error display ;; TODO (defun geiser-kawa--enter-debugger () - "TODO.") + "TODO") (defun geiser-kawa--display-error (module key msg) "Needed to show output (besides result). Modified from geiser-guile.el. -Argument MODULE passed by Geiser. -Argument KEY passed by Geiser. -Argument MSG passed by Geiser." +Argument MODULE is passed by Geiser. +Argument KEY is passed by Geiser. +Argument MSG is passed by Geiser." (when (stringp msg) (save-excursion (insert msg)) (geiser-edit--buttonize-files))