unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Avoiding code replication for hash-table
Date: Sat, 14 Sep 2024 19:11:34 +0000	[thread overview]
Message-ID: <aZ1Rm-q-SLxESaMYH32MkMgArepOrujUSuFH2B24DiVNS5eSZctpGYd3OtPGgqYXXeIdB3beQA6RusK8dysFCIK7-XDnJlMUmkeyYvypB4c=@protonmail.com> (raw)

I want to apply the current code for the alist to the hash-table
possibility as well (fpln can be a hash-table or alist).

But I cannot see how to accomplish this without replicating the code
for both conditions.  Can something be done here ?

(defun torium-test-chart (bfrn fpln anctr)

  (let* ( (bfrname (or bfrn "Torium F-Pln"))
          (qbuffer (get-buffer-create bfrname)) )

    (with-current-buffer qbuffer
      (erase-buffer)

      ;; Print Waypoints and corresponding directory paths
      (if (hash-table-p fpln)

            ;; ---------------------------------------------------
            ;; HASH-TABLE
            (maphash (lambda (waypt dirpath)
                       (message "waypt: %s, dirpath: %s" waypt dirpath))
                     fpln)

        ;; -------------------------------------------------------
        ;; ALIST
        (dolist (entry fpln)
          (let* ( (waypt    (car entry))
                  (dirpath  (questorium-fpln-waypt waypt fpln))
                  (wptfail  (cdr (assoc waypt anctr)))
                  (start    (point)) )

          ;; Insert waypoint
          (insert (format " - %-8s" waypt))

          ;; Apply color based on validity
          (add-text-properties start (point)
              `(face (:foreground ,(if wptfail "red" "green"))))

          ;; Insert validity text
          (insert (format "\n    %s\n" dirpath)))) )

      (goto-char (point-min)))

    (switch-to-buffer qbuffer)))





                 reply	other threads:[~2024-09-14 19:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='aZ1Rm-q-SLxESaMYH32MkMgArepOrujUSuFH2B24DiVNS5eSZctpGYd3OtPGgqYXXeIdB3beQA6RusK8dysFCIK7-XDnJlMUmkeyYvypB4c=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --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).