]> git.eshelyaron.com Git - kubed.git/commitdiff
Preserve marks in list buffers also in Emacs 29
authorEshel Yaron <me@eshelyaron.com>
Fri, 4 Oct 2024 19:03:26 +0000 (21:03 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 4 Oct 2024 19:03:26 +0000 (21:03 +0200)
Instead of relying on
'revert-buffer-restore-functions' (introduced in Emacs 30)
for preserving marks in 'kubed-list-mode' during
'revert-buffer', use a 'revert-buffer-function' to do so.

* kubed.el (kubed-list-revert): New function.
(kubed-list-mode): Use it.

kubed.el

index 5598964c7138ef6240c177172e05e46d10a2c5d2..03c99f543ca98611d94ca6a867193bf35372f3d2 100644 (file)
--- a/kubed.el
+++ b/kubed.el
@@ -1008,36 +1008,41 @@ number at point, or the numeric prefix argument if you provide one."
      (cons 'current (tabulated-list-get-id))
      (cons 'namespace kubed-list-namespace)))))
 
+(defun kubed-list-revert (&rest _)
+  "Revert the current Kubernetes resources list buffer.
+
+This is the `revert-buffer-function' for `kubed-list-mode' and its
+derivatives.  This function does not fetch new data from Kubernetes, it
+only (re)displays the existing data."
+  (let (marks)
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (eobp))
+        (unless (eq (char-after) ?\s)
+          (push (cons (tabulated-list-get-id)
+                      ;; Preserve mark text properties.
+                      (buffer-substring (point) (1+ (point))))
+                marks))
+        (forward-line)))
+    (tabulated-list-revert)
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (eobp))
+        (let ((id (tabulated-list-get-id)))
+          (when-let ((mark (alist-get id marks nil nil #'equal)))
+            (tabulated-list-put-tag mark)))
+        (forward-line)))))
+
 (define-derived-mode kubed-list-mode tabulated-list-mode "Kubernetes Resources"
   "Major mode for listing Kubernetes resources.
 
 Modes for specific resource types, such as `kubed-pods-mode', use this
 mode as their parent."
   :interactive nil
-  (add-hook 'revert-buffer-restore-functions
-            (lambda ()
-              (let (marks)
-                (save-excursion
-                  (goto-char (point-min))
-                  (while (not (eobp))
-                    (unless (eq (char-after) ?\s)
-                      (push (cons (tabulated-list-get-id)
-                                  ;; Preserve mark text properties.
-                                  (buffer-substring (point) (1+ (point))))
-                            marks))
-                    (forward-line)))
-                (lambda ()
-                  (save-excursion
-                    (goto-char (point-min))
-                    (while (not (eobp))
-                      (let ((id (tabulated-list-get-id)))
-                        (when-let ((mark (alist-get id marks nil nil #'equal)))
-                          (tabulated-list-put-tag mark)))
-                      (forward-line))))))
-            nil t)
-  (setq-local truncate-string-ellipsis (propertize ">" 'face 'shadow))
-  (setq-local tabulated-list-entries #'kubed-list-entries)
-  (setq-local bookmark-make-record-function #'kubed-list-make-bookmark)
+  (setq-local truncate-string-ellipsis (propertize ">" 'face 'shadow)
+              tabulated-list-entries #'kubed-list-entries
+              bookmark-make-record-function #'kubed-list-make-bookmark
+              revert-buffer-function #'kubed-list-revert)
   (add-hook 'context-menu-functions #'kubed-list-context-menu nil t))
 
 ;;;###autoload