aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
authorYuchen Pei <id@ypei.org>2025-08-03 22:58:48 +1000
committerYuchen Pei <id@ypei.org>2025-08-03 22:58:48 +1000
commit9f2b6aae90a3d8eaf78a20c10baf9f2358a35a16 (patch)
tree44a1d7ec90226460da40be5eb7803244af3b8745 /emacs/.emacs.d
parent55b2056ea20c4c605c4f7ff6b381764e7b5ccc36 (diff)
[emacs] initial commit of iarcHEADmaster
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/lisp/my/iarc.el75
1 files changed, 75 insertions, 0 deletions
diff --git a/emacs/.emacs.d/lisp/my/iarc.el b/emacs/.emacs.d/lisp/my/iarc.el
new file mode 100644
index 0000000..a412aa3
--- /dev/null
+++ b/emacs/.emacs.d/lisp/my/iarc.el
@@ -0,0 +1,75 @@
+;;; iarc.el -- internet archive client -*- lexical-binding: t -*-
+
+;; Copyright (C) 2025 Free Software Foundation, Inc.
+
+;; Author: Yuchen Pei <id@ypei.org>
+;; Package-Requires: ((emacs "30.1"))
+
+;; This file is part of dotted.
+
+;; dotted is free software: you can redistribute it and/or modify it under
+;; the terms of the GNU Affero General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; dotted 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 Affero General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU Affero General Public
+;; License along with dotted. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; internet archive client.
+
+;;; Code:
+
+(define-derived-mode iarc-mode tabulated-list-mode "IArc"
+ (hl-line-mode 1)
+ (setq tabulated-list-format
+ [("★ " 3 iarc-compare-favourites :right-align t)
+ ("Title" 60 t)])
+ (setq tabulated-list-padding 2)
+ (tabulated-list-init-header)
+ (setq revert-buffer-function #'iarc-list-refresh))
+
+(defvar iarc-search-dataset nil)
+
+(defun iarc-compare-favourites (x y)
+ (> (let-alist (car x) (or .fields.num_favorites 0))
+ (let-alist (car y) (or .fields.num_favorites 0))))
+
+(defun iarc-list-print-entry (info)
+ (let-alist (alist-get 'fields info)
+ (list info (vector (format "%d" (or .num_favorites 0))
+ .title))))
+
+(defun iarc-list-refresh (&rest _)
+ (interactive)
+ (setq tabulated-list-entries
+ (seq-map 'iarc-list-print-entry iarc-search-dataset))
+ (tabulated-list-print))
+
+(defun iarc ()
+ (let ((buf (get-buffer-create "*IArc*")))
+ (with-current-buffer buf
+ (iarc-mode)
+ (iarc-list-refresh))
+ (pop-to-buffer-same-window buf)))
+
+(defvar iarc-host "https://archive.org")
+
+(defun iarc-api-search (query)
+ (my-url-fetch-json
+ (format "%s/services/search/beta/page_production/?user_query=title:(%s)&hits_per_page=100&page=1&aggregations=false"
+ iarc-host query)))
+
+(defun iarc-search (query)
+ (setq iarc-search-dataset (let-alist (iarc-api-search query)
+ .response.body.hits.hits))
+ (iarc))
+
+(provide 'iarc)
+;;; iarc.el ends here