Compare commits

...

10 commits

6 changed files with 211 additions and 44 deletions

106
catchup.el Normal file
View file

@ -0,0 +1,106 @@
;;; catchup.el --- catch up with system stats -*- lexical-binding:t -*-
;; Copyright (C) 2024 Jeremy Baxter
;; Author: Jeremy Baxter <jeremy@baxters.nz>
;; Maintainer: Jeremy Baxter <jeremy@baxters.nz>
;; Created: July 2024
;; This file is not part of GNU Emacs.
;; catchup.el 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.
;;
;; catchup.el 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 catchup.el. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; catchup.el provides `catchup', a command for fetching system
;; stats or other information. Custom shell commands can be run
;; or a file can be read, and that information is then formatted
;; and displayed in the minibuffer. The output style and look can
;; be customized with `catchup-spec' and `catchup-separator'.
;; TODO: add a memory statistic using `memory-info'
;;; Code:
(defvar catchup-buffer "*Catchup*"
"Temporary buffer used by `catchup' types.")
(defvar catchup-separator "\t"
"Separator between `catchup' data.")
(defvar catchup-spec '((format-time-string "%Y/%m/%d\n%T"))
"List representing data to show in `catchup'.
Each element is a list: the car of each sublist being a symbol representing
the function to call, and the cdr being the rest of the arguments to pass
to said function.
catchup.el provides some helper functions you can use; `catchup-file' and
`catchup-shell', which are primitives, and `catchup-battery', a helper
function built from the primitives.
The default value represents a call to `format-time-string', which shows
the current date and time.")
(defun catchup--strip (str)
(string-match "\\`\\s-*\\(.*?\\)\\s-*\n?\\'" str)
(match-string 1 str))
(defun catchup-file (file-name)
"Return the contents of the file FILE-NAME."
(let*
((result nil)
(exists (get-file-buffer file-name))
(buffer (if exists exists (find-file-noselect file-name))))
(with-current-buffer buffer
(setq result (buffer-string))
(unless exists
(kill-this-buffer)))
(catchup--strip result)))
(defun catchup-battery (&optional battery-format)
"Return the battery capacity formatted according to BATTERY-FORMAT."
(format (or battery-format "%s")
(catchup-file "/sys/class/power_supply/BAT0/capacity")))
(defun catchup-shell (command)
"Return the output of running COMMAND in the shell."
(let ((result nil))
(shell-command command catchup-buffer)
(with-current-buffer catchup-buffer
(setq result (buffer-string))
(kill-this-buffer))
result))
(defun catchup ()
"Display system statistics.
Only information in `catchup-spec' is displayed; see its documentation for
more information on configuring it.
A separator or divider to divide information can be provided with
`catchup-separator'. This string is placed between every result."
(interactive)
(let
((final ""))
(dolist (sublist catchup-spec)
(setq final
(concat final (catchup--strip
(apply (car sublist) (cdr sublist)))
catchup-separator)))
(message "%s" (catchup--strip final))))
(provide 'catchup)
;;; catchup.el ends here

View file

@ -22,14 +22,19 @@
;; You should have received a copy of the GNU General Public License ;; You should have received a copy of the GNU General Public License
;; along with enotify.el. If not, see <https://www.gnu.org/licenses/>. ;; along with enotify.el. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; enotify.el provides `enotify', a command for connecting to an IRC
;; server, joining a channel, sending a message, and then leaving.
;;; Code: ;;; Code:
(defvar enotify-buffer "*enotify*" (defvar enotify-buffer "*enotify*"
"Name of the enotify process buffer") "Name of the `enotify' process buffer.")
(defvar enotify-proc "enotify-process" (defvar enotify-proc "enotify-process"
"Name of the enotify socket process") "Name of the `enotify' socket process.")
(defvar enotify-realname "enotify-client" (defvar enotify-realname "enotify-client"
"enotify's IRC realname that shows up in /whois") "IRC realname for `enotify' that shows up in /whois.")
(defun enotify-send-string (proc string) (defun enotify-send-string (proc string)
(process-send-string proc (concat string "\r\n"))) (process-send-string proc (concat string "\r\n")))

View file

@ -108,8 +108,7 @@
(defface erc-highlight-nick-base-face (defface erc-highlight-nick-base-face
'((t nil)) '((t nil))
"Base face used for highlighting nicknames in ERC before the "Face used for highlighting nicknames before color is added."
color is added."
:group 'erc-faces) :group 'erc-faces)
(defvar erc-highlight-face-table (defvar erc-highlight-face-table
@ -117,7 +116,7 @@ color is added."
"Hash table containing unique ERC nickname faces.") "Hash table containing unique ERC nickname faces.")
(defun hexcolor-luminance (color) (defun hexcolor-luminance (color)
"Returns the luminance of color COLOR. COLOR is a string \(e.g. "Return the luminance of color COLOR. COLOR is a string \(e.g.
\"#ffaa00\", \"blue\"\) `color-values' accepts. Luminance is a \"#ffaa00\", \"blue\"\) `color-values' accepts. Luminance is a
value of 0.299 red + 0.587 green + 0.114 blue and is always value of 0.299 red + 0.587 green + 0.114 blue and is always
between 0 and 255." between 0 and 255."
@ -128,7 +127,7 @@ between 0 and 255."
(floor (+ (* 0.299 r) (* 0.587 g) (* 0.114 b)) 256))) (floor (+ (* 0.299 r) (* 0.587 g) (* 0.114 b)) 256)))
(defun invert-color (color) (defun invert-color (color)
"Returns the inverted color of COLOR." "Return the inverted color of COLOR."
(let* ((values (x-color-values color)) (let* ((values (x-color-values color))
(r (car values)) (r (car values))
(g (car (cdr values))) (g (car (cdr values)))

49
esv.el
View file

@ -1,4 +1,4 @@
;;; esv.el --- read the Bible from Emacs -*- lexical-binding:t -*- ;;; esv.el --- read the Bible -*- lexical-binding:t -*-
;; Copyright (C) 2024 Jeremy Baxter ;; Copyright (C) 2024 Jeremy Baxter
@ -41,24 +41,23 @@
(defcustom esv-close-existing-buffers nil (defcustom esv-close-existing-buffers nil
"Whether to close an existing `esv' buffer if one already exists." "Whether to close an existing `esv' buffer if one already exists."
:type 'boolean :type 'boolean)
:group 'esv)
(defcustom esv-columns 72 (defcustom esv-columns 72
"Length of each line output by `esv'." "Length of each line output by `esv'."
:type 'natnum :type 'natnum)
:group 'esv)
(defcustom esv-mode-hook nil (defcustom esv-mode-hook nil
"Hook run after entering `esv-mode'." "Hook run after entering `esv-mode'."
:type 'hook :type 'hook)
:group 'esv)
(defcustom esv-process "esv" (defcustom esv-process "esv"
"Name of the process created by `esv'." "Name of the process created by `esv'."
:type 'string :type 'string)
:group 'esv)
(defcustom esv-program "esv" (defcustom esv-program "esv"
"Path to or name of the program started by `esv'." "Path to or name of the program started by `esv'."
:type 'string :type 'string)
:group 'esv)
(defvar esv-arguments '() (defvar esv-arguments '()
"List of additional arguments passed to `esv-program'.") "List of additional arguments passed to `esv-program'.")
@ -69,31 +68,35 @@
(read-only-mode)) (read-only-mode))
(defun esv (book verses) (defun esv (passage)
"Fetch the Bible passage identified by BOOK and VERSES. "Fetch the Bible passage identified by PASSAGE.
The result will be redirected to a buffer named after the passage. The result will be redirected to a buffer named after PASSAGE.
Requires the esv command line tool to be in the system's PATH. Requires the esv command line tool to be in the system's PATH.
esv can be acquired at <https://sr.ht/~jeremy/esv>." esv can be acquired at <https://sr.ht/~jeremy/esv>."
(interactive "MBook: \nMVerses: ") (interactive "MPassage: ")
(let (let*
((buffer (concat book " " verses)) ((slices (split-string passage))
(verses (car (last slices)))
(book (mapconcat #'(lambda (e) e)
(take (1- (length slices)) slices) " "))
(buffer (concat book " " verses))
(arg-list (append esv-arguments (arg-list (append esv-arguments
(list (format "-l%d" esv-columns))))) (list (format "-l%d" esv-columns))
(list book) (list verses))))
(catch 'buffer-exists (catch 'buffer-exists
(when (get-buffer buffer) (when (get-buffer buffer)
(unless esv-close-existing-buffers (unless esv-close-existing-buffers
(message "Buffer `%s' already exists" buffer) (message "Buffer `%s' already exists" buffer)
(throw 'buffer-exists nil)) (throw 'buffer-exists nil))
(kill-buffer buffer)) (kill-buffer buffer)))
(apply #'call-process esv-program nil buffer t (apply #'call-process esv-program nil buffer t arg-list)
(append arg-list (list book) (list verses)))
(display-buffer buffer) (display-buffer buffer)
(with-current-buffer buffer (with-current-buffer buffer
(esv-mode) (esv-mode)
(goto-char (point-min))) (goto-char (point-min)))
(set-window-start (get-buffer-window buffer) (point-min)) (set-window-start (get-buffer-window buffer) (point-min)))
t))) t)
(provide 'esv) (provide 'esv)

57
ini-mode.el Normal file
View file

@ -0,0 +1,57 @@
;;; ini-mode.el --- major mode for INI -*- lexical-binding:t -*-
;; Copyright (C) 2024 Jeremy Baxter
;; Author: Jeremy Baxter <jeremy@baxters.nz>
;; Maintainer: Jeremy Baxter <jeremy@baxters.nz>
;; Created: July 2024
;; Keywords: ini
;; This file is not part of GNU Emacs.
;; ini-mode.el 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.
;;
;; ini-mode.el 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 ini-mode.el. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; ini-mode.el provides `ini-mode', an implementation of a simple
;; font-locking major mode for INI.
;;; Code:
(require 'font-lock)
(defvar ini-mode-font-lock-keywords
'(("\\([#;].*$\\)" . font-lock-comment-face)
("\\[\\(.+\\)\\]" 1 'font-lock-type-face)
("\\(^.+\\)=" 1 'font-lock-variable-name-face)
("=\\(.+$\\)" 1 'font-lock-string-face)
("\\(\\$?{\\)\\(.+\\)\\(}\\)"
(1 'font-lock-bracket-face t)
(2 'font-lock-variable-use-face t)
(3 'font-lock-bracket-face t))
("\\(%\\)\\(.+\\)\\(%\\)"
(1 'font-lock-bracket-face t)
(2 'font-lock-variable-use-face t)
(3 'font-lock-bracket-face t)))
"Keywords for font locking in `ini-mode'.")
(define-derived-mode ini-mode nil "INI"
"Major mode for editing INI."
(font-lock-mode)
(font-lock-add-keywords nil ini-mode-font-lock-keywords))
(provide 'ini-mode)
;;; ini-mode.el ends here

View file

@ -1,4 +1,4 @@
;;; phobos.el --- view Phobos documentation from within Emacs -*- lexical-binding:t -*- ;;; phobos.el --- view Phobos documentation -*- lexical-binding:t -*-
;; Copyright (C) 2024 Jeremy Baxter ;; Copyright (C) 2024 Jeremy Baxter
@ -43,22 +43,19 @@
(defcustom phobos-browser "xdg-open" (defcustom phobos-browser "xdg-open"
"Web browser to use when opening documentation with `phobos'." "Web browser to use when opening documentation with `phobos'."
:group 'phobos
:type 'string) :type 'string)
(defcustom phobos-root "https://dlang.org/library" (defcustom phobos-root "https://dlang.org/library"
"Root URL to use when viewing documentation with `phobos'." "Root URL to use when viewing documentation with `phobos'."
:group 'phobos
:type 'string) :type 'string)
(defcustom phobos-dpldocs-domain "dpldocs.info" (defcustom phobos-dpldocs-domain "dpldocs.info"
"Root domain to use when viewing documentation on dub packages with `dub-doc'." "Root domain to use when viewing documentation on dub packages with `dub-doc'."
:group 'phobos
:type 'string) :type 'string)
(defcustom phobos-registry-root "https://code.dlang.org" (defcustom phobos-registry-root "https://code.dlang.org"
"Root URL of the D package registry used with `describe-dub-package'." "Root URL of the D package registry used with `describe-dub-package'."
:group 'phobos
:type 'string) :type 'string)
(defun phobos--visit (&rest format-args) (defun phobos--visit (&rest format-args)
"Call `format' with FORMAT-ARGS and pass the result to a web browser."
(let ((url (apply #'format format-args))) (let ((url (apply #'format format-args)))
(shell-command (concat phobos-browser " " url)) (shell-command (concat phobos-browser " " url))
(message url))) (message url)))