Skip to content

Commit

Permalink
add me-focus-on-consistent-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea committed Oct 11, 2021
1 parent 1c57267 commit 859e553
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions moldable-emacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -1278,4 +1278,9 @@ For example, (me-get-in '(:a (:b (:c 1))) '(:a :b :c)) yields 1."

;; (me-plist-focus '(:a a :b b :c c) '(:a :c))

(defun me-focus-on-consistent-keys (list-of-plist)
"Focus on common keys of LIST-OF-PLIST. For example ((:a 1 :b 1 :c 1) (:a 2 :c 2)) becomes ((:a 1 :c 1) (:a 2 :c 2)). This is useful for plotting."
(let ((keys (-reduce '-intersection (--map (-filter 'symbolp it) list-of-plist)))) ;; TODO
(--map (me-plist-focus it keys) list-of-plist)))

(provide 'moldable-emacs)
2 changes: 2 additions & 0 deletions molds/contrib.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ following in your lein project.clj
(let ((table nil) ;; TODO maybe I can use org-table-convert-region to produce a org table, also maybe another mold
(contents (buffer-substring-no-properties (point-min) (point-max))))
(with-current-buffer buffername
(erase-buffer)
(with-temp-file "/tmp/somefile.csv"
(insert contents))
(setq-local self table)
Expand All @@ -83,6 +84,7 @@ following in your lein project.clj
(let ((table nil) ;; TODO maybe I can use org-table-convert-region to produce a org table, also maybe another mold
(contents (buffer-substring-no-properties (point-min) (point-max))))
(with-current-buffer buffername
(erase-buffer)
(with-temp-file "/tmp/somefile.csv"
(insert contents))
(setq-local self table)
Expand Down
4 changes: 4 additions & 0 deletions tests/moldable-emacs-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ some new contents
(string=
(plist-get (car me-available-molds) :key)
"bla"))))

(ert-deftest me-focus-on-consistent-keys_return-only-shared-key-values ()
(should
(equal (me-focus-on-consistent-keys '((:a 1 :b 1 :c 1) (:a 2 :c 2))) '((:a 1 :c 1) (:a 2 :c 2)))))

0 comments on commit 859e553

Please sign in to comment.