emacs-devel
[Top][All Lists]
Advanced

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

hierarchy-print doesn't allow sending indent-string arg to hierarchy-map


From: Damien Cassou
Subject: hierarchy-print doesn't allow sending indent-string arg to hierarchy-map
Date: Wed, 26 Jul 2023 18:16:04 +0200

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

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill



reply via email to

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