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

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

[elpa] externals/dict-tree 1ec9d58 102/154: Restore trie print/read tran


From: Stefan Monnier
Subject: [elpa] externals/dict-tree 1ec9d58 102/154: Restore trie print/read transformer functions.
Date: Mon, 14 Dec 2020 12:21:54 -0500 (EST)

branch: externals/dict-tree
commit 1ec9d58a671b13b6a106533c485b0d4fbc8ff13d
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>

    Restore trie print/read transformer functions.
    
    Byte-compilation of the (mildly) circular avl-tree structures currently
    appears to flatten the data structure, thereby massively bloating the
    size of the byte-compiled version.
---
 dict-tree.el | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/dict-tree.el b/dict-tree.el
index 48864f0..50964777 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -2657,8 +2657,7 @@ and OVERWRITE is the prefix argument."
              (find-file-noselect
               (setq tmpfile (make-temp-file dictname))))
        (set-buffer buff)
-       ;; call the appropriate write function to write the dictionary
-       ;; code
+       ;; call the appropriate write function to write the dictionary code
        (if (dictree--meta-dict-p dict)
            (dictree--write-meta-dict-code dict dictname filename)
          (dictree--write-dict-code dict dictname filename))
@@ -2684,11 +2683,9 @@ and OVERWRITE is the prefix argument."
              ;; destination
              (unless (eq compilation 'uncompiled)
                (if (save-window-excursion
-                     (let ((restore byte-compile-disable-print-circle)
+                     (let ((byte-compile-disable-print-circle t)
                            err)
-                       (setq byte-compile-disable-print-circle t)
                        (setq err (byte-compile-file tmpfile))
-                       (setq byte-compile-disable-print-circle restore)
                        err))
                    (rename-file (concat tmpfile ".elc")
                                 (concat filename ".elc") t)
@@ -3042,7 +3039,20 @@ is the prefix argument."
       (insert "(eval-when-compile (require 'cl))\n")
       (insert "(require 'dict-tree)\n")
       (insert "(defvar " dictname " nil \"Dictionary " dictname ".\")\n")
-      (insert "(setq " dictname " " (prin1-to-string tmpdict) ")\n")
+      (unwind-protect
+         (progn
+           ;; transform trie to print form
+           (trie-transform-for-print (dictree--trie tmpdict))
+           (insert "(setq " dictname
+                   " '" (prin1-to-string tmpdict) ")\n"))
+       ;; if dictionary doesn't use any custom save functions, tmpdict's trie
+       ;; is identical to original dict, so transform it back to usable form
+       ;; on write error
+       (unless (or (dictree--data-savefun dict)
+                   (dictree--plist-savefun dict))
+         (trie-transform-from-read (dictree--trie tmpdict))))
+      (insert "(trie-transform-from-read (dictree--trie "
+             dictname "))\n")
       (when hashcode (insert hashcode))
       (insert "(unless (memq " dictname " dictree-loaded-list)\n"
              "  (push " dictname " dictree-loaded-list))\n"))))
@@ -3560,17 +3570,17 @@ extension, suitable for passing to `load-library'."
                             (concat "#<dict-tree \""
                                     (dictree-name d) "\">"))
                           object " ") ")"))
-   ;; ((vectorp object)
-   ;;  (let ((pretty "[") (len (length object)))
-   ;;    (dotimes (i (1- len))
-   ;;  (setq pretty
-   ;;        (concat pretty
-   ;;                (if (trie-p (aref object i))
-   ;;                    "#<trie>" (prin1-to-string (aref object i))) " ")))
-   ;;    (concat pretty
-   ;;        (if (trie-p (aref object (1- len)))
-   ;;            "#<trie>" (prin1-to-string (aref object (1- len))))
-   ;;        "]")))
+;; ((vectorp object)
+;;  (let ((pretty "[") (len (length object)))
+;;    (dotimes (i (1- len))
+;;     (setq pretty
+;;           (concat pretty
+;;                   (if (trie-p (aref object i))
+;;                       "#<trie>" (prin1-to-string (aref object i))) " ")))
+;;    (concat pretty
+;;           (if (trie-p (aref object (1- len)))
+;;               "#<trie>" (prin1-to-string (aref object (1- len))))
+;;           "]")))
    ))
 
 



reply via email to

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