From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: mousebot Newsgroups: gmane.emacs.devel Subject: Re: hierarchy-print doesn't allow sending indent-string arg to hierarchy-map Date: Sat, 29 Jul 2023 15:33:22 +0200 Message-ID: References: <87a5vi4piz.fsf@cassou.me> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15004"; mail-complaints-to="usenet@ciao.gmane.io" To: Damien Cassou , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jul 29 16:07:57 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qPkbs-0003e1-OB for ged-emacs-devel@m.gmane-mx.org; Sat, 29 Jul 2023 16:07:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPkFg-0001M0-Tw; Sat, 29 Jul 2023 09:45:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qPk4j-0003zW-N6 for emacs-devel@gnu.org; Sat, 29 Jul 2023 09:33:42 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qPk4h-0008H8-Vx for emacs-devel@gnu.org; Sat, 29 Jul 2023 09:33:41 -0400 Original-Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx1.riseup.net (Postfix) with ESMTPS id 4RClns2B8MzDqHx; Sat, 29 Jul 2023 13:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1690637617; bh=AN09ZxUH6aLuFbbWlJ99QNOM9WEVMlt5+OmyexwRUQo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=kew2NXA+2Igu4mNmEZK8zp/ENMlrH2FfRPwAzCOKmRZLUNBNygt2MuJrhh0GpI7U6 7HLnfT3Ct3JWGZNMqniX/6NL8Gi1YpKKADfQ+5S7eXnNxCV1J4hM2bF5lCgXcCdUCS S9dqxcv693Hdrql68VReK/LlKKnEJ+uEr3pcnuGQ= X-Riseup-User-ID: B9ACCE453989ED6934A6448F9B1BA17E90191471AFF37CCFA0696A956F5846C2 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4RClnd3Rw2zFpyb; Sat, 29 Jul 2023 13:33:24 +0000 (UTC) Content-Language: en-US In-Reply-To: <87a5vi4piz.fsf@cassou.me> Received-SPF: pass client-ip=198.252.153.129; envelope-from=mousebot@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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-Mailman-Approved-At: Sat, 29 Jul 2023 09:44:57 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:308200 Archived-At: Hi Damien, I tried our your suggestion in my library, and it works fine. My initial query was also a way of asking if there is any (other) way in hierarchy.el of printing while respecting indentation. I don't know the library well at all. I guess the answer is no, given your response? I'm unsure as to how to refactor hierarchy-print, as I don't understand what you think it ought to do differently once hierarchy-print-line is added. I also wonder if it's perhaps a little confusing to have an arg 'to-string' that is now likely to be a call to `hierarchy-labelfn-indent`, whereas in `hierarchy-print` `to-string` is a function handed to hierarchy-labelfn-indent as an argument. In that case, perhaps -print-line should have the same call to `hierarchy-labelfn-indent` in its body, so that the to-string arg is of a similar form to -print? Finally, is there anything wrong with simply making the indent arg in the lambda in my original suggestion '&optional'? i.e. (defun hierarchy-print (hierarchy &optional to-string indent-string) (let ((to-string (or to-string (lambda (item) (format "%s" item))))) (hierarchy-map (hierarchy-labelfn-indent (lambda (item &optional indent) (insert (funcall to-string item indent) "\n")) indent-string) hierarchy))) Maybe sending 'nil' as an argument to funcall is bad news? I don't really understand why the -print function shouldn't take an indent-string argument, but it's your pkg not mine. kind regards, m On 7/26/23 18:16, Damien Cassou wrote: > Hi, > > you are right that something isn't good enough. The fix you suggest > fixes the problem. Unfortunately, it is backward incompatible: all > usages of `hierarchy-print' passing a custom value for TO-STRING will > now fail because TO-STRING should now read a second argument. > Additionally, I think it shouldn't be the responsibility of > `hierarchy-print' to take care of the indentation. > > Had I been smart enough, I would probably have written `hierarchy-print' > this way instead: > > (defun hierarchy-print (hierarchy &optional to-string) > (let ((to-string (or to-string (lambda (item) (format "%s" item))))) > (hierarchy-map > (lambda (item indent) > (insert (funcall to-string item ident) "\n")) > hierarchy))) > > That is: > - TO-STRING takes 2 parameters > > - indentation should be decided by the user through a dedicated value > TO-STRING value, e.g., with > (hierarchy-labelfn-indent (lambda (item) (format "%s" item))) > > But this implementation also breaks backward compatibility. What I > suggest: > > 1. Implement `hierarchy-print-line' with the implementation above (this > way we have a good implementation anyone can use) > > 2. Refactor and simplify `hierarchy-print` to avoid duplication with > `hierarchy-print-line' but keeping backward compatibility. > > What do you think? Would you mind sending a patch? > > (please keep me on CC) > > Best >