summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshoshin <shoshin@cicadas.surf>2023-11-19 21:39:21 -0600
committershoshin <shoshin@cicadas.surf>2023-11-19 21:39:21 -0600
commit28f438941f536ddb0c58da38d12b859e73738d5c (patch)
treeaf4692bd2a78ec23aac2453e61a469ea0e85e666
Add: initial async wrapper functions around iaHEADmain
-rw-r--r--eia.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/eia.el b/eia.el
new file mode 100644
index 0000000..38c1105
--- /dev/null
+++ b/eia.el
@@ -0,0 +1,50 @@
+;;; eia.el --- Emacs interface for the Internet Archive CLI -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Grant Shangreaux
+
+;; Author: <shoshin@cicadas.surf>
+;; Keywords: unix
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Requires the Internet Archive's CLI program in your path.
+;; https://archive.org/developers/internetarchive/cli.html
+
+;;; Code:
+
+(defun eia-command (command &rest args)
+ "Execute COMMAND asynchronusly; display output."
+ (eia-start-process command args))
+
+(defun eia-start-process (command args)
+ (with-current-buffer "*EIA*" (erase-buffer))
+ (let ((process (apply #'start-process "eia-process" "*EIA*" "ia" command args)))
+ (set-process-sentinel process #'eia-process-sentinel)))
+
+(defun eia-process-sentinel (process event)
+ "Default sentinel used by `magit-start-process'."
+ (when (memq (process-status process) '(exit signal))
+ (setq event (substring event 0 -1))
+ (when (string-match "^finished" event)
+ (message (concat (capitalize (process-name process)) " finished")))
+ (eia-process-buffer)))
+
+(defun eia-process-buffer ()
+ (interactive)
+ (display-buffer "*EIA*"))
+
+(provide 'eia)
+;;; eia.el ends here