[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-kawa d7cb7d9 105/119: Remove advice from "run-kawa"
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-kawa d7cb7d9 105/119: Remove advice from "run-kawa" + add "geiser-kawa-run-kawa" function |
Date: |
Sun, 1 Aug 2021 18:30:47 -0400 (EDT) |
branch: elpa/geiser-kawa
commit d7cb7d9cf6fd6870f8879ec7a54f26177f8a0433
Author: spellcard199 <spellcard199@protonmail.com>
Commit: spellcard199 <spellcard199@protonmail.com>
Remove advice from "run-kawa" + add "geiser-kawa-run-kawa" function
---
elisp/geiser-kawa-deps.el | 83 +++++++++++------------------------------------
elisp/geiser-kawa.el | 20 +++++++++++-
2 files changed, 38 insertions(+), 65 deletions(-)
diff --git a/elisp/geiser-kawa-deps.el b/elisp/geiser-kawa-deps.el
index 3e53230..7e20135 100644
--- a/elisp/geiser-kawa-deps.el
+++ b/elisp/geiser-kawa-deps.el
@@ -14,10 +14,12 @@
;; Depends on global vars:
;; `geiser-kawa-dir'
+;; `geiser-kawa-deps-jar-path'
;;; Code:
(require 'cl-lib)
+(require 'geiser-repl)
(require 'geiser-kawa-globals)
(cl-defun geiser-kawa-deps-mvnw-package
@@ -42,74 +44,27 @@ at REPL startup."
(goto-char (point-max))
(switch-to-buffer-other-window save-buf)))))
-
-;;; Manage the `geiser-kawa-deps--run-kawa--advice' advice for
-;;; `run-kawa'.
-;; `run-kawa' is adviced at the end of `geiser.kawa.el' by calling
-;; `geiser-kawa-deps--run-kawa--advice-add' after `run-kawa' has been
-;; defined by `define-geiser-implementation'.
-;; `geiser-kawa-deps--run-kawa--advice' prompts the user for running
-;; `mvnw package' when:
-;; 1. the user uses `run-kawa'
-;; 2. the fat .jar file that `geiser-kawa' depends on is not found.
-
-(defun geiser-kawa-deps--run-kawa--advice-add()
- "Add our advice to `run-kawa'."
- (add-function :override
- (symbol-function 'run-kawa)
- #'geiser-kawa-deps--run-kawa--advice))
-
-(defun geiser-kawa-deps--run-kawa--advice-remove()
- "Remove our advice from `run-kawa'."
- (remove-function (symbol-function 'run-kawa)
- #'geiser-kawa-deps--run-kawa--advice))
-
-(defun geiser-kawa-deps--run-kawa-unadviced()
- "Call `run-kawa' without triggering our advice."
- (geiser-kawa-deps--run-kawa--advice-remove)
- (unwind-protect
- (run-kawa)
- (geiser-kawa-deps--run-kawa--advice-add)))
-
-(defun geiser-kawa-deps--run-kawa--add-compil-hook()
- "Run `run-kawa' unadviced the next time a compilation finishes."
- ;; The added hook auto-removes itself after being called once.
- (add-hook 'compilation-finish-functions
- #'geiser-kawa-deps--run-kawa--remove-compil-hook))
-
-(defun geiser-kawa-deps--run-kawa--remove-compil-hook(_buf _desc)
- "Hook called when compilation finishes.
-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.
+(defun geiser-kawa-deps--run-kawa--compil-hook(_buf _desc)
+ "Hook to run Kawa when the next compilation finishes.
+Only starts Kawa if after compilation is done file at
+`geiser-kawa-deps-jar-path' exists.
+Removes itself from `compilation-finish-functions' so that Kawa is
+started only for the next compilation.
Argument BUF is passed by Emacs when compilation finishes.
Argument DESC is passed by Emacs when compilation finishes."
- (geiser-kawa-deps--run-kawa-unadviced)
+ (when (file-exists-p geiser-kawa-deps-jar-path)
+ ;; Using `run-geiser' instead of `run-kawa' so that callers can
+ ;; also be advices of `run-kawa' without it becoming an infinite
+ ;; recursion.
+ (run-geiser 'kawa))
(remove-hook 'compilation-finish-functions
- #'geiser-kawa-deps--run-kawa--remove-compil-hook))
-
-(defun geiser-kawa-deps--run-kawa--advice(&optional install-if-absent)
- "Actual advicing function for `run-kawa'.
+ #'geiser-kawa-deps--run-kawa--compil-hook))
-If the `geiser-kawa-deps-jar-path' path:
-- exists: just run unadviced `run-kawa'
-- does not exist:
- 1. ask user for permission to run `mvnw package'
- 2. if user answers `yes':
- 1. download, compile, package `kawa-geiser'
- 2. run `run-kawa' after compilation finishes
-
-Optional argument INSTALL-IF-ABSENT: when non-nil, always prompt and
-recompile kawa-geiser, ignoring existing jar."
- (if (file-exists-p geiser-kawa-deps-jar-path)
- (geiser-kawa-deps--run-kawa-unadviced)
- (when (or install-if-absent
- (y-or-n-p
- (concat
- "geiser-kawa depends on additional java libraries. "
- "Do you want to download and compile them now?")))
- (geiser-kawa-deps--run-kawa--add-compil-hook)
- (geiser-kawa-deps-mvnw-package geiser-kawa-dir))))
+(defun geiser-kawa-deps-mvnw-package--and-run-kawa ()
+ "Run `mvn package' and run Kawa if resulting jar exists."
+ (add-hook 'compilation-finish-functions
+ #'geiser-kawa-deps--run-kawa--compil-hook)
+ (geiser-kawa-deps-mvnw-package geiser-kawa-dir))
(provide 'geiser-kawa-deps)
diff --git a/elisp/geiser-kawa.el b/elisp/geiser-kawa.el
index b487772..c27b4ad 100644
--- a/elisp/geiser-kawa.el
+++ b/elisp/geiser-kawa.el
@@ -140,7 +140,25 @@ Argument MSG is passed by Geiser."
(geiser-impl--add-to-alist 'regexp "\\.sld$" 'kawa t)
;; Check for kawa-geiser jar each time `run-kawa' is called.
-(geiser-kawa-deps--run-kawa--advice-add)
+
+(defun geiser-kawa-run-kawa ()
+ "Alternative to `run-kawa' that also does check for dependencies.
+Compared to the `run-kawa' function defined by
+`define-geiser-implementation', this function also prompts the user to
+package java dependencies if the file at `geiser-kawa-deps-jar-path'
+does not exists.
+Since both here and in `geiser-kawa-deps--run-kawa--compil-hook' we
+are calling `run-geiser' instead of `run-kawa' directly, one can also
+advice `run-kawa' overriding it with `geiser-kawa-run-kawa' without it
+becoming an infinite recursion."
+ (interactive)
+ (if (file-exists-p geiser-kawa-deps-jar-path)
+ (run-geiser 'kawa)
+ (when (y-or-n-p
+ (concat
+ "`geiser-kawa' depends on additional java libraries. "
+ "Do you want to download and compile them now?"))
+ (geiser-kawa-deps-mvnw-package--and-run-kawa))))
(provide 'geiser-kawa)
- [nongnu] elpa/geiser-kawa 590968e 045/119: Add autodoc support for constructor methods, (continued)
- [nongnu] elpa/geiser-kawa 590968e 045/119: Add autodoc support for constructor methods, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 47a2956 044/119: Refactor kawageiser.Geiser.java, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 9f3a057 050/119: README - Add more information about java completion + update kawa-devutil dep, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 34b68ce 052/119: Add check for deps with run-kawa is called. Uses emacs advice on run-kawa., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 0aa42cb 040/119: Fix broken test, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa b8647aa 057/119: Fix error in func name, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 79dec54 061/119: Add support for viewing Expression tree, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 8d6202f 081/119: Refactor + Fix style + Copyright notices, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 1ffe084 097/119: Fixes for windows support + README.org: add instructions, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa ad862b1 090/119: Update README.org, TODO.org, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa d7cb7d9 105/119: Remove advice from "run-kawa" + add "geiser-kawa-run-kawa" function,
Philip Kaludercic <=
- [nongnu] elpa/geiser-kawa ff93297 112/119: README.org - small changes, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 71f8a69 114/119: Fix checkdoc and lint warnings in preparation for melpa recipe update, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 1538f1f 062/119: TODO.org: update, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 2016503 063/119: Fix error caused by undefined reg-beg and reg-end, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa e4fc302 065/119: pom.xml: update kawa-devutil dep, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 69fbe9c 067/119: Refactor: several changes + update pom.xml for kawa-devutil, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa f57efde 071/119: Change geiser version, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa f25955e 072/119: Fix broken package name, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa 0ef5baa 106/119: melpa/melpa#6858 - Fix issues found by "Suggestions/experimental static checks", Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-kawa bed937f 101/119: TODO.org: update, Philip Kaludercic, 2021/08/01