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

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

[elpa] externals/taxy-magit-section cf93e23943 2/3: Add/Fix: Section typ


From: ELPA Syncer
Subject: [elpa] externals/taxy-magit-section cf93e23943 2/3: Add/Fix: Section type with ident values for visibility caching
Date: Wed, 12 Oct 2022 09:58:24 -0400 (EDT)

branch: externals/taxy-magit-section
commit cf93e239438f52812072eed33e9b2521ec86c1d2
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add/Fix: Section type with ident values for visibility caching
---
 README.org              |  3 ++-
 taxy-magit-section.el   | 72 ++++++++++++++++++++++++++++++++-----------------
 taxy-magit-section.info | 17 ++++++------
 3 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/README.org b/README.org
index 8fe1c05598..b35842862c 100644
--- a/README.org
+++ b/README.org
@@ -34,7 +34,8 @@ This library renders 
[[https://github.com/alphapapa/taxy.el][Taxy]] structs with
 
 ** 0.12-pre
 
-Nothing new yet.
+*Fixes*
++ Section visibility caching.
 
 ** 0.11
 
diff --git a/taxy-magit-section.el b/taxy-magit-section.el
index 3e22d14ed6..868f2beff7 100644
--- a/taxy-magit-section.el
+++ b/taxy-magit-section.el
@@ -85,6 +85,20 @@ this does not disable indentation of section headings.")
   (item-indent 2)
   (format-fn #'prin1-to-string))
 
+(defclass taxy-magit-section-section (magit-section)
+  ;; We define this class so we can use it as the type of section we insert, 
so we can
+  ;; define a method to return identifiers for our section type, so section 
visibility can
+  ;; be cached.
+  )
+
+(cl-defmethod magit-section-ident-value ((section taxy-magit-section-section))
+  ;; FIXME: The name of each taxy could be ambiguous.  Best would be to use the
+  ;; hierarchical path, but since the taxys aren't doubly linked, that isn't 
easily done.
+  ;; Could probably be worked around by binding a special variable around the 
creation of
+  ;; the taxy hierarchy that would allow the path to be saved into each taxy.
+  (when-let ((taxy (oref section value)))
+    (taxy-name taxy)))
+
 ;;;; Commands
 
 
@@ -138,30 +152,37 @@ which blank lines are inserted between sections at that 
level."
                       (when (taxy-magit-section-visibility-fn taxy)
                         (push (taxy-magit-section-visibility-fn taxy)
                               magit-section-set-visibility-hook))))
-                   (magit-insert-section (magit-section taxy)
-                     (magit-insert-heading
-                       (make-string (* (if (< depth 0) 0 depth)
-                                       (taxy-magit-section-level-indent taxy))
-                                    ? )
-                       taxy-name
-                       (format " (%s%s)"
-                               (if (taxy-description taxy)
-                                   (concat (taxy-description taxy) " ")
-                                 "")
-                               (taxy-size taxy)))
-                     (magit-insert-section-body
-                       (when (eq 'first items)
-                         (dolist (item (taxy-items taxy))
-                           (insert-item item taxy depth)))
-                       (dolist (taxy (taxy-taxys taxy))
-                         (insert-taxy taxy (1+ depth)))
-                       (when (eq 'last items)
-                         (dolist (item (taxy-items taxy))
-                           (insert-item item taxy depth))))
-                     (when (<= depth blank-between-depth)
-                       (insert "\n"))))))
-      (magit-insert-section (magit-section)
-        (insert-taxy taxy initial-depth)))))
+                   ;; HACK: We set the section's washer to nil to prevent
+                   ;; `magit-section--maybe-wash' from trying to wash the 
section when its
+                   ;; visibility is toggled back on.  I'm not sure why this is 
necessary
+                   ;; (maybe an issue in magit-section?).
+                   (oset (magit-insert-section (taxy-magit-section-section 
taxy)
+                           (magit-insert-heading
+                             (make-string (* (if (< depth 0) 0 depth)
+                                             (taxy-magit-section-level-indent 
taxy))
+                                          ? )
+                             taxy-name
+                             (format " (%s%s)"
+                                     (if (taxy-description taxy)
+                                         (concat (taxy-description taxy) " ")
+                                       "")
+                                     (taxy-size taxy)))
+                           (magit-insert-section-body
+                             (when (eq 'first items)
+                               (dolist (item (taxy-items taxy))
+                                 (insert-item item taxy depth)))
+                             (dolist (taxy (taxy-taxys taxy))
+                               (insert-taxy taxy (1+ depth)))
+                             (when (eq 'last items)
+                               (dolist (item (taxy-items taxy))
+                                 (insert-item item taxy depth))))
+                           (when (<= depth blank-between-depth)
+                             (insert "\n")))
+                         washer nil))))
+      ;; HACK: See earlier note about washer.
+      (oset (magit-insert-section (taxy-magit-section-section)
+              (insert-taxy taxy initial-depth))
+            washer nil))))
 
 (cl-defun taxy-magit-section-pp (taxy &key (items 'first))
   "Pretty-print TAXY into a buffer with `magit-section' and show it."
@@ -180,7 +201,8 @@ Default visibility function for
     ((and (pred taxy-p) taxy)
      (pcase (taxy-size taxy)
        (0 'hide)
-       (_ 'show)))
+       (_ (or (magit-section-cached-visibility section)
+              'show))))
     (_ nil)))
 
 ;;;; Column-based formatting
diff --git a/taxy-magit-section.info b/taxy-magit-section.info
index a0c22f5a86..85d825adb8 100644
--- a/taxy-magit-section.info
+++ b/taxy-magit-section.info
@@ -81,7 +81,8 @@ File: README.info,  Node: 012-pre,  Next: 011,  Up: Changelog
 4.1 0.12-pre
 ============
 
-Nothing new yet.
+*Fixes*
+   • Section visibility caching.
 
 
 File: README.info,  Node: 011,  Next: 010,  Prev: 012-pre,  Up: Changelog
@@ -159,13 +160,13 @@ Node: Installation952
 Node: COMMENT Usage1323
 Node: Changelog1448
 Node: 012-pre1651
-Node: 0111761
-Node: 0101966
-Node: 0912121
-Node: 092513
-Node: Development2703
-Node: Credits2930
-Node: License3120
+Node: 0111787
+Node: 0101992
+Node: 0912147
+Node: 092539
+Node: Development2729
+Node: Credits2956
+Node: License3146
 
 End Tag Table
 



reply via email to

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