From efc08126f7119569112b336f0cd73eefdf9737b5 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 18 Jan 2022 17:18:06 -0600 Subject: Um --- lisp/+elfeed.el | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- lisp/+eshell.el | 8 +++--- lisp/+org.el | 8 ++++-- lisp/+straight.el | 41 ++++++++++++++++++++++++++++++ lisp/+tab-bar.el | 55 +++++++++++++++++++--------------------- lisp/acdw.el | 24 ++++++++++++++++++ lisp/fibs.el | 37 +++++++++++++++++++++++++++ 7 files changed, 210 insertions(+), 38 deletions(-) create mode 100644 lisp/+straight.el create mode 100644 lisp/fibs.el (limited to 'lisp') diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index 9e5f787..ef93347 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el @@ -2,8 +2,6 @@ ;;; Code: -(require 'elfeed) - ;; https://karthinks.com/software/lazy-elfeed/ (defun +elfeed-scroll-up-command (&optional arg) "Scroll up or go to next feed item in Elfeed" @@ -31,5 +29,78 @@ (interactive) (elfeed-show-visit t)) +;;; Fetch feeds async +;; https://github.com/skeeto/elfeed/issues/367 + +(defun +elfeed--update-message () + (message "[Elfeed] Update in progress") + 'ignore) + +(defvar +elfeed--update-running nil "Whether an update is currently running.") + +(defun +elfeed-update-command () + (interactive) + (let ((script (expand-file-name "~/.local/bin/elfeed"))) + (message "[Elfeed] Updating in the background.") + (setq +elfeed--update-running t) + (elfeed-db-save) + (advice-add 'elfeed :override #'+elfeed--update-message) + (ignore-errors (kill-buffer "*elfeed-search*")) + (ignore-errors (kill-buffer "*elfeed-log*")) + (elfeed-db-unload) + (unless (file-exists-p script) + (make-directory (file-name-directory script) :parents) + (with-temp-buffer + (insert "(progn\n" + " (load (locate-user-emacs-file \"early-init\"))\n" + " (straight-use-package 'elfeed)\n" + " (require 'elfeed)\n" + " (elfeed)\n" + " (elfeed-update)\n" + " (while (> (elfeed-queue-count-total) 0)\n" + " (sleep-for 5)\n" + " (message \"%s\" (elfeed-queue-count-total))\n" + " (accept-process-output))\n" + " (elfeed-db-save-safe)\n" + " (elfeed-db-gc-safe))") + (write-file script))) + (set-process-sentinel (start-process-shell-command + "Elfeed" nil (concat "emacs --script " script)) + (lambda (a b) + (advice-remove 'elfeed #'+elfeed--update-message) + (setq +elfeed--update-running nil) + (message "[Elfeed] Background update %s." + (string-trim b)))))) + +(defvar +elfeed--update-timer nil "Timer for `elfeed-update-command'.") +(defvar +elfeed--update-first-time 6 "How long to wait for the first time.") +(defvar +elfeed--update-repeat (* 60 15) "How long between updates.") + +(defun +elfeed--cancel-update-timer () + "Cancel `+elfeed--update-timer'." + (unless +elfeed--update-running + (ignore-errors (cancel-timer +elfeed--update-timer)) + (setq +elfeed--update-timer nil))) + +(defun +elfeed--reinstate-update-timer () + "Reinstate `+elfeed--update-timer'." + (setq +elfeed--update-timer + (run-at-time +elfeed--update-first-time + +elfeed--update-repeat + #'+elfeed-update-command))) + +(define-minor-mode +elfeed-update-async-mode + "Minor mode to update elfeed async-style every 15 minutes." + :global t + (if +elfeed-update-async-mode + (progn ; enable + (+elfeed--reinstate-update-timer) + (advice-add 'elfeed :before '+elfeed--cancel-update-timer) + (advice-add 'elfeed-search-quit-window :after '+elfeed--reinstate-update-timer)) + (progn ; disable + (advice-remove 'elfeed '+elfeed--cancel-update-timer) + (advice-remove 'elfeed-search-quit-window '+elfeed--reinstate-update-timer) + (+elfeed--cancel-update-timer)))) + (provide '+elfeed) ;;; +elfeed.el ends here diff --git a/lisp/+eshell.el b/lisp/+eshell.el index 1f8677c..d49358d 100644 --- a/lisp/+eshell.el +++ b/lisp/+eshell.el @@ -91,10 +91,10 @@ something, it's really annoying to work with." ,@forms) (when (featurep 'eshell) `(dolist (buf (buffer-list)) - (with-current-buffer buf - (when (derived-mode-p 'eshell-mode) - (+eshell@setup))))) - '(add-hook 'eshell-mode-hook #'+eshell@setup))) + (with-current-buffer buf + (when (derived-mode-p 'eshell-mode) + (+eshell@setup))))) + (add-hook 'eshell-mode-hook #'+eshell@setup))) (provide '+eshell) ;;; +eshell.el ends here diff --git a/lisp/+org.el b/lisp/+org.el index 5869622..11a816f 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -433,8 +433,12 @@ the deletion might narrow the column." (when (and (memq this-char-type types) (memq prev-char-type types)) (backward-char) (setq type prev-char-type)) ; what the fuckckckckck - (if (memq type types) - (progn (org-open-at-point arg)) + ;; Okay, so this ^ is pretty janky and doesn't /really/ work that well, + ;; especially on DEADLINE (and probably SCHEDULED) lines. However, since + ;; I really just want to open the list of URLs /most of the time/, I'm + ;; fixing it like this instead. + (unless (and (memq type types) + (ignore-errors (org-open-at-point arg))) (while (not (progn (org-back-to-heading) diff --git a/lisp/+straight.el b/lisp/+straight.el new file mode 100644 index 0000000..d00ad9a --- /dev/null +++ b/lisp/+straight.el @@ -0,0 +1,41 @@ +;;; +straight.el --- Straight.el extras -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + +(defun +straight-update-package (package &optional recursive) + "Update PACKAGE using straight. +This pulls, rebuilds, and loads the updated PACKAGE." + (interactive (list (straight--select-package "Update package" + #'straight--installed-p) + current-prefix-arg)) + (+with-message (format "Pulling package `%s'%s" package + (if recursive " and deps" "")) + (funcall (if recursive + #'straight-pull-package-and-deps + #'straight-pull-package) + package + :from-upstream)) + (+with-message (format "Rebuilding package `%s'%s" package + (if recursive " and deps" "")) + (straight-rebuild-package package recursive)) + (+with-message (format "Loading package `%s'%s" package + (if recursive " and deps" "")) + (ignore-errors (load-library (symbol-name package))) + (when recursive + (dolist (dep (straight--get-transitive-dependencies package)) + (ignore-errors (load-library (symbol-name package))))))) + +(defun +straight-update-all (from-upstream) + "Update all installed packages using straight. +This pulls and rebuilds all packages at once. It does not reload +all of them, for reasons that should be obvious. + +With a prefix argument, it also pulls the packages FROM-UPSTREAM." + (interactive "P") + (straight-pull-all from-upstream) + (straight-rebuild-all)) + +(provide '+straight) +;;; +straight.el ends here diff --git a/lisp/+tab-bar.el b/lisp/+tab-bar.el index 2e9198c..b11be2c 100644 --- a/lisp/+tab-bar.el +++ b/lisp/+tab-bar.el @@ -22,7 +22,7 @@ `((global menu-item ,(string-trim-right (format-mode-line mode-line-misc-info)) - ignore))) + ignore :help (discord-date-string)))) (defvar +tab-bar-show-original nil "Original value of `tab-bar-show'.") @@ -129,35 +129,30 @@ Used by `tab-bar-format-menu-bar'." ;;; Tab bar format tabs (require 'el-patch) - -(el-patch-defun tab-bar--format-tab (tab i) - (append - (el-patch-remove - `((,(intern (format "sep-%i" i)) menu-item ,(tab-bar-separator) ignore))) - (cond - ((eq (car tab) 'current-tab) - `((current-tab - menu-item - ,(funcall tab-bar-tab-name-format-function tab i) - ignore - :help "Current tab"))) - (t - `((,(intern (format "tab-%i" i)) - menu-item - ,(funcall tab-bar-tab-name-format-function tab i) - ,(or - (alist-get 'binding tab) - `(lambda () - (interactive) - (tab-bar-select-tab ,i))) - :help "Click to visit tab")))) - `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) - menu-item "" - ,(or - (alist-get 'close-binding tab) - `(lambda () - (interactive) - (tab-bar-close-tab ,i))))))) +(el-patch-feature tab-bar) +(with-eval-after-load 'tab-bar + (el-patch-defun tab-bar--format-tab (tab i) + "Format TAB using its index I and return the result as a keymap." + (append + (el-patch-remove + `((,(intern (format "sep-%i" i)) menu-item ,(tab-bar-separator) ignore))) + (cond + ((eq (car tab) 'current-tab) + `((current-tab + menu-item + ,(funcall tab-bar-tab-name-format-function tab i) + ignore + :help "Current tab"))) + (t + `((,(intern (format "tab-%i" i)) + menu-item + ,(funcall tab-bar-tab-name-format-function tab i) + ,(alist-get 'binding tab) + :help "Click to visit tab")))) + (when (alist-get 'close-binding tab) + `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) + menu-item "" + ,(alist-get 'close-binding tab))))))) ;; Emacs 27 diff --git a/lisp/acdw.el b/lisp/acdw.el index 17741ab..a96e6a7 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -248,5 +248,29 @@ With optional ARG (\\[universal-argument]), just split." (interactive "P") (+split-window-then :below arg)) +(defun +bytes (number unit) + "Convert NUMBER UNITs to bytes. +UNIT can be one of :kb, :mb, :gb, :tb, :pb, :eb, :zb, :yb; :kib, :mib, :gib, +:tib, :pib, :eib, :zib, :yib." + (* number (pcase unit + ;; Base 10 units + (:kb 1000) + (:mb (* 1000 1000)) + (:gb (* 1000 1000 1000)) + (:tb (* 1000 1000 1000 1000)) + (:pb (* 1000 1000 1000 1000 1000)) + (:eb (* 1000 1000 1000 1000 1000 1000)) + (:zb (* 1000 1000 1000 1000 1000 1000 1000)) + (:yb (* 1000 1000 1000 1000 1000 1000 1000 1000)) + ;; Base 2 units + (:kib 1024) + (:mib (* 1024 1024)) + (:gib (* 1024 1024 1024)) + (:tib (* 1024 1024 1024 1024)) + (:pib (* 1024 1024 1024 1024 1024)) + (:eib (* 1024 1024 1024 1024 1024 1024)) + (:zib (* 1024 1024 1024 1024 1024 1024 1024)) + (:yib (* 1024 1024 1024 1024 1024 1024 1024 1024))))) + (provide 'acdw) ;;; acdw.el ends here diff --git a/lisp/fibs.el b/lisp/fibs.el new file mode 100644 index 0000000..545c2a7 --- /dev/null +++ b/lisp/fibs.el @@ -0,0 +1,37 @@ +;;; fibs.el --- Play backgammon with FIBS -*- lexical-binding: t; -*- + +;;; Commentary: + +;; fibs.com is one of the oldest backgammon servers out there, and it's +;; accessible via telnet. This package provides a wrapper to enable you to play +;; backgammon on fibs.com more easily than just opening a telnet session +;; yourself. + +;;; TODO: + +;; - Automatically log in. +;; - Add a `fibs-quit' function to kill the telnet server and buffer. + +;;; Code: + +(require 'telnet) + +(defgroup fibs nil + "Customizations for FIBS, the First Internet Backgammon Server." + :group 'games) + +(defcustom fibs-server "fibs.com" + "The server to connect to FIBS with." + :type 'string) + +(defcustom fibs-port 4321 + "The port to connect to FIBS with." + :type 'number) + +;;;###autoload +(defun fibs () + (interactive) + (telnet fibs-server fibs-port)) + +(provide 'fibs) +;;; fibs.el ends here -- cgit 1.4.1-21-gabe81