1
0
Fork 0

Avoid code duplication among interactive functions

This commit is contained in:
Bram Schoenmakers 2024-08-06 06:38:52 +02:00
parent fdcde7d425
commit 1c97377a27
Signed by: bram
GPG key ID: 0CCD19DFDC63258F

View file

@ -161,23 +161,22 @@ the entry should be exported."
entries
"\n"))))
;;;###autoload
(defun elfeed-export-to-json-file (path)
"Write the JSON string to a file at PATH."
(defmacro elfeed-export--to (format)
"Define an interactive command to export the elfeed database to FORMAT."
(let* ((function-name (intern (format "elfeed-export-to-%s-file" format)))
(payload-function (intern (format "elfeed-export-to-%s" format)))
(upcased-format (upcase (format "%s" format)))
(docstring (format "Export the elfeed database as %s to PATH." upcased-format)))
`(progn
(defun ,function-name (path)
,docstring
(interactive "F")
(write-region (elfeed-export-to-json) nil path nil nil nil t))
(write-region (,payload-function) nil path nil nil nil t))
(autoload ',function-name "elfeed-export" ,docstring t))))
;;;###autoload
(defun elfeed-export-to-lisp-file (path)
"Write the JSON string to a file at PATH."
(interactive "F")
(write-region (elfeed-export-to-lisp) nil path nil nil nil t))
;;;###autoload
(defun elfeed-export-to-csv-file (path)
"Write the CSV string to a file at PATH."
(interactive "F")
(write-region (elfeed-export-to-csv) nil path nil nil nil t))
(elfeed-export--to csv)
(elfeed-export--to lisp)
(elfeed-export--to json)
(provide 'elfeed-export)