emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/kubed eaf03ec7e2 09/70: Improve compatibility with Emac


From: ELPA Syncer
Subject: [elpa] externals/kubed eaf03ec7e2 09/70: Improve compatibility with Emacs 29
Date: Tue, 6 Aug 2024 06:58:25 -0400 (EDT)

branch: externals/kubed
commit eaf03ec7e2e3a757716698bf0ba8b53d903207c7
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    Improve compatibility with Emacs 29
    
    * kubed.el (tramp-kubernetes-namespace): Remove declaration.
    (kubed--static-if): New macro.  Compatibility definition of
    'static-if' from Emacs 30.
    (kubed-pods-dired, kubed-pods-shell): Do not rely on
    explicit Kubernetes namespace in remote file name syntax in
    Emacs versions earlier than 31.
    (kubed-define-resource): Use 'emacsclient-program-name' only
    in Emacs 30 or later.
---
 kubed.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 48 insertions(+), 7 deletions(-)

diff --git a/kubed.el b/kubed.el
index 1aabc91b89..487cde8b1c 100644
--- a/kubed.el
+++ b/kubed.el
@@ -502,7 +502,9 @@ Optional argument DEFAULT is the minibuffer default 
argument." resource)
                          `(list (,read-fun "Edit"))))
          (unless (bound-and-true-p server-process) (server-start))
          (let ((process-environment
-                (cons (concat "KUBE_EDITOR=" emacsclient-program-name)
+                (cons ,(if (<= 30 emacs-major-version)
+                           '(concat "KUBE_EDITOR=" 'emacsclient-program-name)
+                         "KUBE_EDITOR=emacsclient")
                       process-environment)))
            (start-process ,(format "*kubed-%S-edit*" plrl-var) nil
                           kubed-kubectl-program "edit"
@@ -848,7 +850,19 @@ Optional argument DEFAULT is the minibuffer default 
argument." resource)
          "E" #',expl-cmd
          ,@prf-keys))))
 
-(defvar tramp-kubernetes-namespace)
+(defmacro kubed--static-if (condition then-form &rest else-forms)
+  "A conditional compilation macro.
+Evaluate CONDITION at macro-expansion time.  If it is non-nil, expand
+the macro to THEN-FORM.  Otherwise expand it to ELSE-FORMS enclosed in a
+‘progn’ form.  ELSE-FORMS may be empty.
+
+This is the same as `static-if' from Emacs 30, defined here for
+compatibility with earlier Emacs versions."
+  (declare (indent 2)
+           (debug (sexp sexp &rest sexp)))
+  (if (eval condition lexical-binding)
+      then-form
+    (cons 'progn else-forms)))
 
 ;;;###autoload (autoload 'kubed-display-pod "kubed" nil t)
 ;;;###autoload (autoload 'kubed-edit-pod "kubed" nil t)
@@ -886,12 +900,39 @@ Optional argument DEFAULT is the minibuffer default 
argument." resource)
            "X" #'kubed-exec
            "F" #'kubed-forward-port-to-pod)
   (dired "C-d" "Start Dired in home directory of first container of"
-         (let ((ns (when k8sns (concat "%" k8sns))))
-           (dired (concat "/kubernetes:" pod ns ":"))))
+         ;; Explicit namespace in Kuberenetes remote file names
+         ;; introduced in Emacs 31.  See Bug#59797.
+         (kubed--static-if (<= 31 emacs-major-version)
+             (let ((ns (when k8sns (concat "%" k8sns))))
+               (dired (concat "/kubernetes:" pod ns ":")))
+           (when k8sns
+             (if (y-or-n-p
+                  (format "Starting Dired in a pod in a different namespace \
+requires Emacs 31 or later.
+You can proceed by first switching your current namespace.
+Switch to namespace `%s' and proceed?" k8sns))
+                 (kubed-set-namespace k8sns)
+               (user-error
+                "Cannot start Dired in a pod in different namespace `%s'"
+                k8sns)))
+           (dired (concat "/kubernetes:" pod ":"))))
   (shell "s" "Start shell in home directory of first container of"
-         (let* ((ns (when k8sns (concat "%" k8sns)))
-                (default-directory (concat "/kubernetes:" pod ns ":")))
-           (shell (format "*kubed-pod-%s-shell*" pod))))
+         (kubed--static-if (<= 31 emacs-major-version)
+             (let* ((ns (when k8sns (concat "%" k8sns)))
+                    (default-directory (concat "/kubernetes:" pod ns ":")))
+               (shell (format "*kubed-pod-%s-shell*" pod)))
+           (when k8sns
+             (if (y-or-n-p
+                  (format "Starting Shell in a pod in a different namespace \
+requires Emacs 31 or later.
+You can proceed by first switching your current namespace.
+Switch to namespace `%s' and proceed?" k8sns))
+                 (kubed-set-namespace k8sns)
+               (user-error
+                "Cannot start Dired in a pod in different namespace `%s'"
+                k8sns)))
+           (let* ((default-directory (concat "/kubernetes:" pod ":")))
+             (shell (format "*kubed-pod-%s-shell*" pod)))))
   (attach "a" "Attach to remote process running on"
           (kubed-attach pod (kubed-read-container pod "Container" t k8sns)
                         k8sns t t))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]