Avoid code duplication among interactive functions
This commit is contained in:
parent
fdcde7d425
commit
1c97377a27
1 changed files with 15 additions and 16 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue