Skip to content

Commit

Permalink
Fix byte compilation errors for Emacs 31 (snapshot) (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnovation authored Jan 12, 2025
1 parent a316a75 commit 773cdd7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
57 changes: 27 additions & 30 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ NAMESPACE GVK NAME PROCESS).")
"Which major mode to use for YAML highlighting.
Set to nil to disable YAML highlighting."
:type '(choice nil symbol))
:type '(choice (const nil) symbol))

(define-error 'kele-cache-lookup-error
"Kele failed to find the requested resource in the cache.")
Expand All @@ -145,7 +145,7 @@ Set to nil to disable YAML highlighting."
"Found multiple group-versions associated with the given resource")

(defface kele-disabled-face
'((t (:inherit 'font-lock-comment-face)))
'((t (:inherit font-lock-comment-face)))
"Face used for disabled or not-applicable values."
:group 'kele)

Expand Down Expand Up @@ -430,12 +430,12 @@ If CONTEXT is nil, use the current context."
"Look up the namespaced-ness of GROUP-VERSION TYPE in CACHE.
If CONTEXT is not provided, the current context is used."
(if-let ((namespaced-p
(->> (kele--get-resource-lists-for-context cache (or context (kele-current-context-name)))
(-first (lambda (resource-list) (equal (alist-get 'groupVersion resource-list) group-version)))
(alist-get 'resources)
(-first (lambda (resource) (equal (alist-get 'name resource) type)))
(alist-get 'namespaced))))
(if-let* ((namespaced-p
(->> (kele--get-resource-lists-for-context cache (or context (kele-current-context-name)))
(-first (lambda (resource-list) (equal (alist-get 'groupVersion resource-list) group-version)))
(alist-get 'resources)
(-first (lambda (resource) (equal (alist-get 'name resource) type)))
(alist-get 'namespaced))))
(not (eq :false namespaced-p))
(signal 'kele-cache-lookup-error `(,context ,group-version ,type))))

Expand Down Expand Up @@ -686,8 +686,7 @@ returns nil."
(cl-defmethod proxy-active-p ((manager kele--proxy-manager)
context)
"Return non-nil if a proxy serve is active for CONTEXT in MANAGER."
(when-let (res (assoc context (oref manager records)))
(cdr res)))
(cdr (assoc context (oref manager records))))

(defvar kele--global-proxy-manager (kele--proxy-manager))

Expand Down Expand Up @@ -763,8 +762,8 @@ to complete. Returned value may not be up to date."

(defun kele--context-cluster-name (context-name)
"Get the name of the cluster of the context named CONTEXT-NAME."
(if-let ((context (-first (lambda (elem) (string= (alist-get 'name elem) context-name))
(alist-get 'contexts (oref kele--global-kubeconfig-cache contents)))))
(if-let* ((context (-first (lambda (elem) (string= (alist-get 'name elem) context-name))
(alist-get 'contexts (oref kele--global-kubeconfig-cache contents)))))
(alist-get 'cluster (alist-get 'context context))
(error "Could not find context of name %s" context-name)))

Expand Down Expand Up @@ -962,7 +961,7 @@ If value is nil, the namespaces need to be fetched directly.")
If the namespaces are cached, return the cached value.
If CACHE is non-nil, cache the fetched namespaces."
(if-let ((cached-namespaces (alist-get (intern context) kele--namespaces-cache)))
(if-let* ((cached-namespaces (alist-get (intern context) kele--namespaces-cache)))
cached-namespaces
(let* ((gvk (kele--gvk-create :version "v1" :kind "namespaces"))
(namespaces (kele--fetch-resource-names gvk :context context)))
Expand Down Expand Up @@ -1277,10 +1276,8 @@ context and namespace in its name."
:resource (kele--resource-container-resource object)
:namespace (kele--resource-container-namespace object)))
(put 'kele--current-resource-buffer-context 'permanent-local t))

(when kele-yaml-highlighting-mode
(funcall kele-yaml-highlighting-mode))

(kele-get-mode 1))
(select-window (display-buffer buf))))

Expand All @@ -1290,12 +1287,12 @@ context and namespace in its name."
(curr alist))
(dolist (key keys)
(setq prev curr)
(setq curr (if-let ((list-p (listp curr))
(res (assq key curr)))
(setq curr (if-let* ((list-p (listp curr))
(res (assq key curr)))
(cdr res)
nil)))
(when curr
(assq-delete-all (car (last keys)) prev))
(ignore (assq-delete-all (car (last keys)) prev)))
alist))

(defvar kele--context-keymap nil
Expand Down Expand Up @@ -1426,7 +1423,7 @@ Assumes that the current Transient prefix's :scope is an alist w/ `context' key.
;; FIXME: Make this resilient to the prefix's scope not having a context
;; value. If not present (or the scope is not an alist or the scope is not
;; defined), default to current context.
(if-let ((context (alist-get 'context (oref transient--prefix scope))))
(if-let* ((context (alist-get 'context (oref transient--prefix scope))))
(kele--namespaces-complete
:context context
:prompt prompt
Expand Down Expand Up @@ -1472,10 +1469,10 @@ Also resets any specified peer arguments on the same prefix that
match any element of `:resettees' on OBJ."
(cl-call-next-method obj val)
(dolist (arg (oref obj resettees))
(when-let ((obj (cl-find-if (lambda (obj)
(and (slot-boundp obj 'argument)
(equal (oref obj argument) arg)))
transient--suffixes)))
(when-let* ((obj (cl-find-if (lambda (obj)
(and (slot-boundp obj 'argument)
(equal (oref obj argument) arg)))
transient--suffixes)))
(transient-init-value obj))))

(defclass kele--transient-infix (kele--transient-infix-resetter
Expand Down Expand Up @@ -1599,10 +1596,9 @@ Defaults to the currently active context as set in
First checks the current Transient command's arguments if set.
Otherwise, returns the current context name from kubeconfig."
(if-let* ((cmd transient-current-command)
(args (transient-args cmd))
(value (transient-arg-value "--context=" args)))
value
(if transient-current-command
(transient-arg-value "--context=" (transient-args
transient-current-command))
(kele-current-context-name)))

(cl-defun kele--get-namespace-arg (&key (permit-nil nil) use-default group-version kind (prompt "Namespace: "))
Expand All @@ -1621,9 +1617,10 @@ In order of priority, this function attempts the following:
namespaced, return nil;
- Otherwise, ask the user to select a namespace using PROMPT."
(let ((transient-arg-maybe (->> transient-current-command
(transient-args)
(transient-arg-value "--namespace="))))
(let ((transient-arg-maybe (when transient-current-command
(->> transient-current-command
(transient-args)
(transient-arg-value "--namespace=")))))
(cond
((or transient-arg-maybe permit-nil) transient-arg-maybe)
((or (not (and group-version kind)) use-default)
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/test-kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,10 @@
(it "renders the value as YAML"
(with-temp-buffer
(kele--render-object fake-obj (current-buffer))
(expect (buffer-string) :to-equal "kind: FakeKind
;; For some reason --render-object adds in an add'l newline on Emacs 31
(expect (buffer-string) :to-match (rx "kind: FakeKind
metadata:
name: fake-name")))
name: fake-name" (zero-or-more whitespace)))))

(it "respects `kele-filtered-fields'"
(setq fake-obj '((kind . "FakeKind")
Expand All @@ -423,9 +424,10 @@ metadata:
(let ((kele-filtered-fields '((metadata foo))))
(with-temp-buffer
(kele--render-object fake-obj (current-buffer))
(expect (buffer-string) :to-equal "kind: FakeKind
;; For some reason --render-object adds in an add'l newline on Emacs 31
(expect (buffer-string) :to-match (rx "kind: FakeKind
metadata:
name: fake-name"))))
name: fake-name" (zero-or-more whitespace))))))

(describe "buffer titling"
(describe "when input is `kele--resource-container'"
Expand Down Expand Up @@ -656,6 +658,8 @@ metadata:
(describe "when called in a Transient buffer"
(before-each
(setq transient-current-command t))
(after-each
(setq transient-current-command nil))
(describe "when the current command has a `--groupversion' arg"
(before-each
(spy-on 'transient-args :and-return-value '("--groupversion=foo")))
Expand Down

0 comments on commit 773cdd7

Please sign in to comment.