[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: |
mousebot |
Subject: |
hierarchy-print doesn't allow sending indent-string arg to hierarchy-map |
Date: |
Wed, 12 Jul 2023 15:43:58 +0200 |
hi emacs,
`hierarchy-labelfn-indent' takes an optional second argument `indent-string'.
`hierarchy-print' calls `hierarchy-labelfn-indent', but doesn't allow providing
it with an `indent-string' arg.
it also provides no second argument to the labelfn arg of
`hierarchy-labelfn-indent'.
hierarchy-print looks like this:
```
(defun hierarchy-print (hierarchy &optional to-string)
"Insert HIERARCHY in current buffer as plain text.
Use TO-STRING to convert each element to a string. TO-STRING is
a function taking an item of HIERARCHY as input and returning a
string. If nil, TO-STRING defaults to a call to `format' with \"%s\"."
(let ((to-string (or to-string (lambda (item) (format "%s" item)))))
(hierarchy-map
(hierarchy-labelfn-indent (lambda (item _)
(insert (funcall to-string item) "\n")))
hierarchy)))
```
i'm working on a client and i'm using a copy of `hierarchy-print' that looks
like this:
```
(defun hierarchy-print (hierarchy &optional to-string indent-string)
"Insert HIERARCHY in current buffer as plain text.
Use TO-STRING to convert each element to a string. TO-STRING is
a function taking an item of HIERARCHY as input and returning a
string. If nil, TO-STRING defaults to a call to `format' with \"%s\"."
(let ((to-string (or to-string (lambda (item) (format "%s" item)))))
(hierarchy-map
(hierarchy-labelfn-indent (lambda (item indent) ; add indent
(insert (funcall to-string item indent) "\n"))
; add indent
indent-string) ; add indent-string
hierarchy)))
```
i provide optional arg `indent-string' and hand it to `hierarchy-map'. i also
provide a second 'indent' arg to the lambda that is the first arg for
`hierarchy-labelfn-indent', indent is then given as the last arg of `funcall'.
this allows me to print indented tree structures, which i was unable to achieve
otherwise.
is there a reason this isn't the way `hierarchy-print' is coded? is there
perhaps another way to achieve the same result? i have little experience with
`hierarchy.el'.
regards,
m
- hierarchy-print doesn't allow sending indent-string arg to hierarchy-map,
mousebot <=