Subject: [bug#62664] [PATCH] [WIP] gnu: Add emacs-copilot.

From: Rostislav Svoboda <[email-masked]>
Date: Tue, 4 Apr 2023 16:30:43 +0200

---
 gnu/packages/emacs-xyz.scm | 46 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/gnu/packages/emacs-xyz.scm b/gnu/packages/emacs-xyz.scm
index 2b96c60057..d037fa9075 100644
--- a/gnu/packages/emacs-xyz.scm
+++ b/gnu/packages/emacs-xyz.scm
@@ -36689,6 +36689,52 @@ (define-public emacs-tintin-mode
       (description "This major mode focuses on highlighting as many aspects of the TinTin++ scripting language as possible, organizing commands into functional categories and highlighting specific modes that many commands use to accomplish different tasks.")
       (license license:asl2.0))))
 
+(define-public emacs-copilot
+  (let ((commit "e11847ab0c3b183a1e53fbc1ac587de82912b9cf")
+        (revision "0"))
+    (package
+      (name "emacs-copilot")
+      (version (git-version "0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/zerolfx/copilot.el.git")
+               (commit commit)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32
+           "0gsxb268vqyim65ag8d7dlgdqyxqrjcjirlnbfbfq0pdr1y2158q"))))
+      (build-system emacs-build-system)
+      (arguments
+       (list
+        #:include #~(cons "^dist/" %default-include)
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'substitute-copilot-node-executable
+              (lambda* (#:key inputs #:allow-other-keys)
+                (emacs-substitute-variables "copilot.el"
+                  ("copilot-node-executable"
+;;; Copilot requires Node 16+, however packaging v16 and/or v18 is not
+;;; trivial. See https://issues.guix.gnu.org/53414,
+;;; https://issues.guix.gnu.org/59188 .
+;;;
+;;; As a hack, download and compile recent Node version manually.
+                   (format #f "%s/node-v18.15.0/out/Release/node" (getenv "dev")) ; Remove this line when Node 16+ becomes available as a Guix package.
+                   ;; (search-input-file inputs "/bin/node")                      ; Activate this line when Node 16+ becomes available as a Guix package.
+                   )))))))
+      ;; (inputs (list node))                                                     ; Activate this line when Node 16+ becomes available as a Guix package.
+      (propagated-inputs
+       (list emacs-dash emacs-editorconfig emacs-s))
+      (home-page
+       "https://github.com/zerolfx/copilot.el.git")
+      (synopsis "An unofficial Copilot plugin for Emacs")
+      (description
+       "Copilot.el is an Emacs plugin for GitHub Copilot. This plugin is
+unofficial and based on binaries provided by copilot.vim. Note: You need
+access to GitHub Copilot to use this plugin.")
+      (license license:gpl3+))))
+
 ;;;
 ;;; Avoid adding new packages to the end of this file. To reduce the chances
 ;;; of a merge conflict, place them above by existing packages with similar
-- 
2.39.2