I have this couple of alists:

((melpa . 49) (gnu . 14) (nongnu . 1))

((nongnu (nongnu . markdown-mode)) (gnu (gnu . adaptive-wrap) (gnu . auctex) (gnu . company) (gnu . consult) (gnu . csv-mode) (gnu . dash) (gnu . diff-hl) (gnu . hydra) (gnu . json-mode) (gnu . queue) (gnu . rainbow-mode) (gnu . spinner) (gnu . transient) (gnu . vertico)) (melpa (melpa . a) (melpa . biblio) (melpa . biblio-core) (melpa . bibtex-actions) (melpa . bibtex-completion) (melpa . cider) (melpa . clojure-mode) (melpa . embark) (melpa . embark-consult) (melpa . envrc) (melpa . epl) (melpa . f) (melpa . flymake-kondor) (melpa . flymake-proselint) (melpa . flymake-quickdef) (melpa . flyspell-correct) (melpa . git-commit) (melpa . git-identity) (melpa . goto-last-change) (melpa . ibuffer-vc) (melpa . inheritenv) (melpa . keychain-environment) (melpa . magit) (melpa . magit-section) (melpa . modus-themes) (melpa . multiple-cursors) (melpa . no-littering) (melpa . olivetti) (melpa . orderless) (melpa . package-lint) (melpa . package-lint-flymake) (melpa . parsebib) (melpa . parseclj) (melpa . parseedn) (melpa . pdf-tools) (melpa . pkg-info) (melpa . restart-emacs) (melpa . s) (melpa . scratch) (melpa . sesman) (melpa . symbol-overlay) (melpa . tablist) (melpa . typo) (melpa . uuidgen) (melpa . web-mode) (melpa . wgrep) (melpa . with-editor) (melpa . xterm-color) (melpa . yaml-mode)))

What I am looking for is printing them in format like the following:

  • melpa (49): a, biblio, biblio-core ...
  • gnu (14): adaptive-wrap, auctex, company ...
  • nongnu (1): markdown-mode

Is it possible?

  • Your question seems to really be about printing (displaying) alists, and has nothing to do with packages. It would be clearer if you removed the example, perhaps replacing it with a much simpler example of an arbitrary alist and how you would like it to be shown.
    – Drew
    May 30 '21 at 15:17
  • I see what you mean, but the example was meant to give the context of the problem I am facing with the actual code I am using. I'll see what I can do. May 30 '21 at 15:28
  • 1
    That context is irrelevant to the alist question. If you get a good answer to your alist question, it might help you solve your underlying, context-dependent question - or not. If not, then pose another question related to that context (and not to this alist question).
    – Drew
    May 30 '21 at 16:47
  • You're right, I updated my question. May 31 '21 at 5:54

I am not sure what kind of answer you expect, but of course it is possible to get the output as a string. It looks like you already know some elisp (assuming that you posted a self defined function), so I guess you are mainly interested in how to print bullet points. You can just insert a bullet into a string using M-x insert-char, for example

(print "•")

where you use the aforementioned command to insert the bullet point.

Ah... what the heck, it is a nice little exercise, so here is the code to get your requested format:

 (lambda (archive)
   (concat "•"
           (format "%s (%s)" (car archive) (cdr archive))
           ": "
            (lambda (ap-pair)
              (symbol-name (cdr ap-pair)))
            (alist-get (car archive) list2)
            " ")))

where I have named your first and second list list1 and list2 respectively

  • 1
    Thank you, I updated the question with only the two alists I need to format. You're answer got me there. May 31 '21 at 5:54
  • 1
    Your welcome. You can also remove the strayed concat. I had not noticed it was still there. I have removed the 'strayed' concat from the answer May 31 '21 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.