From: Michael Heerdegen <michael_heerdegen@web.de>
To: Jean Louis <bugs@gnu.support>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Need to know how to goto-column
Date: Sat, 05 Dec 2020 22:40:13 +0100 [thread overview]
Message-ID: <87360kvsn6.fsf@web.de> (raw)
In-Reply-To: <X8nQzDcT8MXnKJTU@protected.rcdrun.com> (Jean Louis's message of "Fri, 4 Dec 2020 09:01:48 +0300")
Jean Louis <bugs@gnu.support> writes:
> Show me the `my-print-table-to-string' if you have it.
Thrown together late at night and in a hurry, expect some nonsense
errors (and a useless docstring):
#+begin_src emacs-lisp
(defun my-print-table-to-string (table &optional col-formatters alignments)
"Print formatted TABLE, a matrix of strings, to a string and return it."
(let* ((nb-cols (length (car table)))
(fill (lambda (l) (let ((d (- nb-cols (length l))))
(if (< 0 d) (append l (make-list d nil)) l))))
(col-formatters (funcall fill col-formatters))
(alignments (funcall fill alignments))
(table (mapcar (lambda (line)
(cl-mapcar
(lambda (entry formatter)
(if formatter (funcall formatter entry) entry))
line col-formatters))
table))
(max-col-lengths
(mapcar
(lambda (i)
(apply #'max
(mapcar #'length (mapcar (apply-partially #'nth i)
table))))
(number-sequence 0 (1- nb-cols)))))
(mapconcat (lambda (line)
(let ((i 0))
(mapconcat
#'identity
(cl-mapcar
(lambda (entry alignment)
(prog1 (let ((padding (- (nth i max-col-lengths)
(length entry))))
(pcase alignment
('right (concat (make-string padding ?\ ) entry))
((and (or 'center 'centered)
(let left (/ padding 2)))
(concat (make-string left ?\ )
entry
(make-string (- padding left) ?\ )))
(_ (concat entry (make-string padding ?\ )))))
(cl-incf i)))
line alignments)
" ")))
table "\n")))
#+end_src
Regards,
Michael.
next prev parent reply other threads:[~2020-12-05 21:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 11:20 Need to know how to goto-column Jean Louis
2020-12-03 11:46 ` tomas
2020-12-03 14:22 ` Jean Louis
2020-12-03 14:33 ` Joost Kremers
2020-12-03 16:23 ` tabulated-list-mode for dynamic knowledge repository - " Jean Louis
2020-12-03 22:27 ` Michael Heerdegen
2020-12-03 22:29 ` Jean Louis
2020-12-03 23:33 ` Michael Heerdegen
2020-12-04 0:00 ` Jean Louis
2020-12-04 1:33 ` Michael Heerdegen
2020-12-04 6:01 ` Jean Louis
2020-12-05 21:40 ` Michael Heerdegen [this message]
2020-12-06 5:02 ` Jean Louis
2020-12-06 22:34 ` Michael Heerdegen
2020-12-07 6:37 ` Jean Louis
2020-12-04 8:15 ` Eli Zaretskii
2020-12-07 6:04 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87360kvsn6.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).