unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Avoiding code replication for hash-table
@ 2024-09-14 19:11 Heime
  0 siblings, 0 replies; only message in thread
From: Heime @ 2024-09-14 19:11 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

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)))





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-09-14 19:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-14 19:11 Avoiding code replication for hash-table Heime

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).