]> git.eshelyaron.com Git - kubed.git/commitdiff
New commands for table navigation
authorEshel Yaron <me@eshelyaron.com>
Fri, 2 Aug 2024 07:43:08 +0000 (09:43 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 2 Aug 2024 07:43:08 +0000 (09:43 +0200)
* kubed.el (kubed-list-previous-column)
(kubed-list-next-column): New commands.
(kubed-list-mode-map): Bind them.

kubed.el

index 6164cee93bb979dfad49b4bab3fd33cec98485d6..61c35cf82cdf40126477a5ea84e8b7db29da0b92 100644 (file)
--- a/kubed.el
+++ b/kubed.el
@@ -328,12 +328,44 @@ atomic FILTER (= Name foobar)."
   (interactive "" kubed-list-mode)
   (tabulated-list-put-tag " " t))
 
+(defun kubed-list-previous-column (&optional n)
+  "Move backward N columns.
+
+Interactively, N is the numeric value of the prefix argument, defaulting
+to 1."
+  (interactive "p" kubed-list-mode)
+  (kubed-list-next-column (- n)))
+
+(defun kubed-list-next-column (&optional n)
+  "Move forward N columns.
+
+Interactively, N is the numeric value of the prefix argument, defaulting
+to 1."
+  (interactive "p" kubed-list-mode)
+  (let ((next (point))
+        (times (abs (or n 1)))
+        (dir-fn (if (< 0 n)
+                    #'next-single-property-change
+                  #'previous-single-property-change)))
+    (dotimes (_ times)
+      (setq next (funcall dir-fn next 'tabulated-list-column-name))
+      (when (= (char-after next) ?\n)
+        ;; At line boundary, go to first/last column of next line.
+        (setq next (funcall dir-fn next 'tabulated-list-column-name)))
+      (unless next (user-error "End of table")))
+    (goto-char next)))
+
 (defvar-keymap kubed-list-mode-map
   :doc "Common keymap for Kubernetes resource list buffers."
   "/" #'kubed-list-set-filter
   "A" #'kubed-all-namespaces-mode
   "d" #'kubed-list-mark-for-deletion
-  "u" #'kubed-list-unmark)
+  "u" #'kubed-list-unmark
+  "C-i" #'kubed-list-next-column
+  "TAB" #'kubed-list-next-column
+  "C-S-i" #'kubed-list-previous-column
+  "S-TAB" #'kubed-list-previous-column
+  "<backtab>" #'kubed-list-previous-column)
 
 (define-derived-mode kubed-list-mode tabulated-list-mode "Kubernetes Resources"
   "Major mode for listing Kubernetes resources.