From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Wamm K. D." Newsgroups: gmane.emacs.bugs Subject: bug#55900: [PATCH] Hierarchy =?UTF-8?Q?=E2=80=93?= Defer the Computation of Children Date: Sat, 11 Jun 2022 01:52:13 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8565"; mail-complaints-to="usenet@ciao.gmane.io" To: 55900@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 11 08:58:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzv4W-00024u-9R for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Jun 2022 08:58:12 +0200 Original-Received: from localhost ([::1]:58472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzv4U-0001gs-Nu for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Jun 2022 02:58:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzv4M-0001gj-Nn for bug-gnu-emacs@gnu.org; Sat, 11 Jun 2022 02:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57863) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzv4M-0001cO-CH for bug-gnu-emacs@gnu.org; Sat, 11 Jun 2022 02:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nzv4M-0001f9-AS for bug-gnu-emacs@gnu.org; Sat, 11 Jun 2022 02:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Wamm K. D." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Jun 2022 06:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55900 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16549306626353 (code B ref -1); Sat, 11 Jun 2022 06:58:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Jun 2022 06:57:42 +0000 Original-Received: from localhost ([127.0.0.1]:51760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzv42-0001eP-6J for submit@debbugs.gnu.org; Sat, 11 Jun 2022 02:57:42 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:37734) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzv3w-0001e9-G8 for submit@debbugs.gnu.org; Sat, 11 Jun 2022 02:57:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzv3w-0001f1-5k for bug-gnu-emacs@gnu.org; Sat, 11 Jun 2022 02:57:36 -0400 Original-Received: from mail-bn8nam12olkn20802.outbound.protection.outlook.com ([2a01:111:f400:fe5b::802]:36033 helo=NAM12-BN8-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzv3t-0001aC-VH for bug-gnu-emacs@gnu.org; Sat, 11 Jun 2022 02:57:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nNUS4WGiLbrF+zlvk+6XUCMxZxVFy7ch2Ejq6CMHQasusixuOLPPjk2CHXUdY6TW2DphV2dKH68MG6jsVJKtF4K1c1w1h15wUIQ0HYt0C19wH+UZMKbz7tT6WnyomR0Ayt9k9mxPCcBRKMyr7zi6DAU6L1+5Fc4KMO0x+GvwwO4TNDWkJTxsgSjDIx5lumSXa1/1aI1GG0+bfaL2VWaiC14j06ymf/8H+uXZyJk+lf13xFB3a9FYJgvla7bwEYMZxfX1zLAsRSIu0GVOddVHlngBipujzdpxsSk1aOFDSALhv8wqNwoB55ev5/3mhlbcdeOmVjPkaEGGN1bQ68eQiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HMkF13+KB0UT5IZK9BZg8UJ81HF/uA+cB6hhZxb0UCU=; b=A7I174dH0zYJdT+GUmExiCZPHAVC9oxRRrVa0nQGczlx3YNWhaW22RJrz7KU9MpWtvmP94SliOfA+fsfDLBNMYBqmYRjoCSHe2GkITcNmGNEo4TpGICD7I509/VLMD1PO19tbqcUgxpHqYYD03RfNWuADzDZcaRx+WIUAIkMDdfiJisYUHlud/BBKF/dn2FvKP6rPRaqOHs71RrB2zviaDe5ZrR/LfJ/+ulkqWAYSBvm5ngHWzZL3Dt+2B7CwnLrg+AzcqJxw6Z68gWT5mg2Gp6Al39Z6aSuQOJA5MAyZToM/HzWIcrMMDKzuMvETUOs4l0vjiXohtypptPrVzLj6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HMkF13+KB0UT5IZK9BZg8UJ81HF/uA+cB6hhZxb0UCU=; b=UXm6t2VmedEpxVmqS6fxc2+0DCpc19N9teSYklqbOjMtmJ7FSC6FrmNqUKBVoLb8V+FqNgaNqVskzjj0v/j8ftiMHTrYqPRvJY4asnA6gGJxBuRsfLIkjZkQhqeUIlkSOb/tkMnjAIugwzRpNoJauGYBHmsnO2coZ/J1HAUT8DuITx+Mcu4rid4eBC4HzqUxDeXdnFQte6xFryd4Efvcrj2HOgfWeNb3U/IIgsfPd/C/U6W0BpWcPygtwt7Uee8H8IaRpa/0NSshVI17jeLPQGs8q718aCTg3v8nwP0EYcr1B8aUULaa5Veuj5l+Q/qdDFYhp8DejzSRhuUxTz59lA== Original-Received: from BY5PR07MB7029.namprd07.prod.outlook.com (2603:10b6:a03:1f0::20) by SA1PR07MB8547.namprd07.prod.outlook.com (2603:10b6:806:192::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.15; Sat, 11 Jun 2022 06:52:28 +0000 Original-Received: from BY5PR07MB7029.namprd07.prod.outlook.com ([fe80::8dc1:2aac:41b5:1e74]) by BY5PR07MB7029.namprd07.prod.outlook.com ([fe80::8dc1:2aac:41b5:1e74%3]) with mapi id 15.20.5332.017; Sat, 11 Jun 2022 06:52:28 +0000 X-TMN: [Fom7K9BlEGhvzEWD6xEPi4yCtSUl904S] X-ClientProxiedBy: MN2PR03CA0003.namprd03.prod.outlook.com (2603:10b6:208:23a::8) To BY5PR07MB7029.namprd07.prod.outlook.com (2603:10b6:a03:1f0::20) X-Microsoft-Original-Message-ID: <87czff66aq.fsf@outlook.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6372c9a-ecb0-418a-63e2-08da4b76f2cc X-MS-TrafficTypeDiagnostic: SA1PR07MB8547:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /pfB2Ms3fOHPV7tbspPrUmFuc6ApOrF7sCCmp0JUhd2R/76QLAJp74LvR4GbHGtH3HbeFmEp5elnWN9YS6mcAcLNzi6isExHtfsYErhljluutiZxNHv68i9ehhKzS0pAu6paDFUNO45Lx7weUYoKFXKdxq6HQnnIYRpOYP304pgVh/s6ahzte6d0RVW/HOfFikdo5l2LyR/l9vR5gDnOI0Ln7mvE3rJZyxMAy5L/JIeF7uDJ4EFcfGuAUEHglMDObqAtrzqmgBXFzdI0ydhBfjiC9dZCTPnTNJ3dvsKEF7qz8Vo94zl8Pnsi7JrFd94ZJlW4TsEp39agS5vHdE/YdBYn2BbCU4em8gRX9h1zxXQZ87MYBOIOJEZGTCcepw8SnucJacYBIZ8uZhGKdLAx7IX0fwuPP8OvCpqkuN6feBSpGstp4PWSUt6T5S3nP//imTpcI43pEkaHYauFjPBPIrdN7vrAHNmfHI0XGc/CxqtShoj3EUK8TSft+sXxLJiSV3tc+96OVSzPYIekT+60jM5LhxUrIQiLTYnfVJrMrZrltXBScVpu3HfyoWOtciR6 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xHaoTt5Oh5+jDa+8inAFiTgWox5qEVvRVxPse+BBV9jq2jP1OBud2foYeED0K/KEym5uwRZN2Va+v12du9X+Ds9iN08bxqTel6OOfYV2sYNjiyWsKGd4QDdIq+HCLfUOvsQ71dRPy3lLLxDAR9Pr1kT/NGW4YyMVBOtS0u7pNbpQzV6B/VwgjxHvnvu4jTYvlTP/PI1AFaAnaLyDPR/qFM4A28DHacfttvuwo5ceCbSi7cOurCyqqiOn456zIPz4gfjrLJJCGuUjgcMsEsHWrv1Ps9HmuGoviL/sgtxBhnQ5T5gklex8X4zbcHES3DsZIpULQOM+OqPyFtm+uEmyw3Itwdh63lyYt+gNpZluCvb0WkFH87obQ9RV+Q3WH8vSDL0U0APGGI6z4O8RfDh2KG3YnpFLsE4MNJmwvSSR7veIPoo1N7/dG5Ganlx4eTVD2FyZD/g34XepXgIYqZpjhIojo05Prmq+n+GWNGjR9bWKUd0PJ7zGqbmXHYwJhg8A8afJy8011nb1PKkSXg/drzSEyK/8YdPV6ATTLIB/TQLNSNfZPHDlsYy2ed7TK4AijG1YnBKzxtIoGvzNaVqWWdD+RqsdbLi4Cq629uhHVYV7IXF9pOtlT3AfJfbCiy/Bk6YWO92BgPwkGrLchZIEqpOKPpQxNJXHtgwdy4n8hPtmTzhIr9nYityoN0s55+vWEaIRifk0uaU7Nw9UYFfd8csRTPfM4lUlKrLTRSQrg4/dyPYmKVGUtM6W7R 5aSUsdiCjLsaj4SkAbisYsJccS1mJ5hkclXJQDiX9rnr81EIr3YYHvBsl0kv+D2ThCeEOocE0AzbFmakYGN30pyFVHXnL2een7 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6372c9a-ecb0-418a-63e2-08da4b76f2cc X-MS-Exchange-CrossTenant-AuthSource: BY5PR07MB7029.namprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2022 06:52:28.1957 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR07MB8547 Received-SPF: pass client-ip=2a01:111:f400:fe5b::802; envelope-from=jaft.r@outlook.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:234251 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Pretty much as the subject describes; this should allow for users to lazily load hierarchy branches when loading everything at once would otherwise be too consuming, up-front (or if dealing with an infinite tree). My current use-case with this feature is mapping a file hierarchy on a server; each node has to be queried against the API of the server so it only makes sense to make the HTTP call when the user wants to load the node (rather than a bunch of HTTP calls, all at once). In GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0) System Description: Guix System Configured using: 'configure CONFIG_SHELL=/gnu/store/4y5m9lb8k3qkb1y9m02sw9w9a6hacd16-bash-minimal-5.1.8/bin/bash SHELL=/gnu/store/4y5m9lb8k3qkb1y9m02sw9w9a6hacd16-bash-minimal-5.1.8/bin/bash --prefix=/gnu/store/8avvrqis68nvpnv7z4vmd745hji5jyrk-emacs-28.1 --enable-fast-install --with-modules --with-cairo --disable-build-details' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Allow-Hierarchy-to-delay-computing-children.patch >From 44c5f8bf00ea51d47c4a9d5127233ef303734f92 Mon Sep 17 00:00:00 2001 From: "Wamm K. D" Date: Sat, 11 Jun 2022 01:21:43 -0500 Subject: [PATCH] Allow Hierarchy to delay computing children Add an option to allow users to specify that computing the children of the hierarchy should be delayed to when the user calls for them, by utilizing the tree-widget :expander property. * lisp/emacs-lisp/hierarchy.el (hierarchy-add-tree) (hierarchy-add-trees): Add parameter 'delay-children-p'. * lisp/emacs-lisp/hierarchy.el (hierarchy--create-delayed-tree-widget): Add function. * lisp/emacs-lisp/hierarchy.el (hierarchy-convert-to-tree-widget): Utilize ':expander' if delaying children. --- lisp/emacs-lisp/hierarchy.el | 78 ++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/lisp/emacs-lisp/hierarchy.el b/lisp/emacs-lisp/hierarchy.el index 6c95d86b47..55faaa1b3f 100644 --- a/lisp/emacs-lisp/hierarchy.el +++ b/lisp/emacs-lisp/hierarchy.el @@ -71,7 +71,8 @@ (:conc-name hierarchy--)) (roots (list)) ; list of the hierarchy roots (no parent) (parents (make-hash-table :test 'equal)) ; map an item to its parent - (children (make-hash-table :test 'equal)) ; map an item to its childre + (children (make-hash-table :test 'equal)) ; map an item to its children + (delaying-parents (make-hash-table :test 'equal)) ; map an item to its childrenfn ;; cache containing the set of all items in the hierarchy (seen-items (make-hash-table :test 'equal))) ; map an item to t @@ -133,7 +134,8 @@ keys are :key and :test." "Create a hierarchy and return it." (hierarchy--make)) -(defun hierarchy-add-tree (hierarchy item parentfn &optional childrenfn acceptfn) +(defun hierarchy-add-tree (hierarchy item parentfn + &optional childrenfn acceptfn delay-children-p) "In HIERARCHY, add ITEM. PARENTFN is either nil or a function defining the child-to-parent @@ -151,7 +153,12 @@ CHILDRENFN are expected to be coherent with each other. ACCEPTFN is a function returning non-nil if its parameter (any object) should be an item of the hierarchy. By default, ACCEPTFN returns non-nil -if its parameter is non-nil." +if its parameter is non-nil. + +DELAY-CHILDREN-P is a predicate determining whether the children that would +normally be processed by CHILDRENFN should, instead, have their processing be +delayed and stored to be processed by CHILDRENFN when the child is selected +during use of the hierarchy." (unless (hierarchy-has-item hierarchy item) (let ((acceptfn (or acceptfn #'identity))) (hierarchy--seen-items-add hierarchy item) @@ -159,19 +166,25 @@ if its parameter is non-nil." (when (funcall acceptfn parent) (hierarchy--add-relation hierarchy item parent acceptfn) (hierarchy-add-tree hierarchy parent parentfn childrenfn))) - (let ((children (and childrenfn (funcall childrenfn item)))) - (mapc (lambda (child) - (when (funcall acceptfn child) - (hierarchy--add-relation hierarchy child item acceptfn) - (hierarchy-add-tree hierarchy child parentfn childrenfn))) - children))))) - -(defun hierarchy-add-trees (hierarchy items parentfn &optional childrenfn acceptfn) + (if delay-children-p + (map-put! (hierarchy--delaying-parents hierarchy) item childrenfn) + (let ((children (and childrenfn (funcall childrenfn item)))) + (map-put! (hierarchy--delaying-parents hierarchy) item nil) + (mapc (lambda (child) + (when (funcall acceptfn child) + (hierarchy--add-relation hierarchy child item acceptfn) + (hierarchy-add-tree hierarchy child parentfn childrenfn))) + children)))))) + +(defun hierarchy-add-trees (hierarchy items parentfn + &optional childrenfn acceptfn delay-children-p) "Call `hierarchy-add-tree' on HIERARCHY and each element of ITEMS. -PARENTFN, CHILDRENFN and ACCEPTFN have the same meaning as in `hierarchy-add'." +PARENTFN, CHILDRENFN, ACCEPTFN, and DELAY-CHILDREN-P have the same meaning as in +`hierarchy-add'." (seq-map (lambda (item) - (hierarchy-add-tree hierarchy item parentfn childrenfn acceptfn)) + (hierarchy-add-tree hierarchy item parentfn + childrenfn acceptfn delay-children-p)) items)) (defun hierarchy-add-list (hierarchy list &optional wrap childrenfn) @@ -541,6 +554,26 @@ nil. The buffer is returned." buffer)) (declare-function widget-convert "wid-edit") +(defun hierarchy--create-delayed-tree-widget (elem labelfn indent fn) + "Return a list of tree-widgets for a hierarchy created from the childrenfn. +ELEM is the element of the hierarchy passed from +`hierarchy-convert-to-tree-widget'; it and the children function are used +to generate the children of the element dynamically. +LABELFN is the same function passed to `hierarchy-convert-to-tree-widget'. +INDENT is the same function passed to `hierarchy-convert-to-tree-widget'. +FN is the function used to discover the children of ELEM." + (lambda (widget) + (mapcar + (lambda (item) + (widget-convert + 'tree-widget + :tag (hierarchy-labelfn-to-string labelfn item indent) + :expander (hierarchy--create-delayed-tree-widget + item + labelfn + (1+ indent) + fn))) + (funcall fn elem)))) (defun hierarchy-convert-to-tree-widget (hierarchy labelfn) "Return a tree-widget for HIERARCHY. @@ -550,10 +583,21 @@ node label." (require 'wid-edit) (require 'tree-widget) (hierarchy-map-tree (lambda (item indent children) - (widget-convert - 'tree-widget - :tag (hierarchy-labelfn-to-string labelfn item indent) - :args children)) + (let ((childrenfn (map-elt + (hierarchy--delaying-parents hierarchy) + item))) + (apply + #'widget-convert + (list 'tree-widget + :tag (hierarchy-labelfn-to-string labelfn item indent) + (if childrenfn :expander :args) + (if childrenfn + (hierarchy--create-delayed-tree-widget + item + labelfn + (1+ indent) + childrenfn) + children))))) hierarchy)) (defun hierarchy-tree-display (hierarchy labelfn &optional buffer) -- 2.36.1 --=-=-=--