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
;; 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:
(defvar enotify-buffer "*enotify*"
"Name of the enotify process buffer")
"Name of the `enotify' process buffer.")
(defvar enotify-proc "enotify-process"
"Name of the enotify socket process")
"Name of the `enotify' socket process.")
(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)
(process-send-string proc (concat string "\r\n")))

View file

@ -28,7 +28,7 @@
;;; Commentary:
;; This is a modified version of erc-highlight-nicknames.el from
;; <https://emacswiki.org/emacs/erc-highlight-nicknames.el>. It has been
;; <https://emacswiki.org/emacs/erc-highlight-nicknames.el>. It has been
;; extended to use the configured ERC colour palette, using the faces
;; with names beginning with `fg:erc-color-face'.
;;
@ -36,7 +36,7 @@
;; for a list of these faces.
;; Originally authored by André Riemann in 2007 and updated from 2008-2014
;; by Andy Stewart. ERC face support was added by Jeremy Baxter in 2023.
;; by Andy Stewart. ERC face support was added by Jeremy Baxter in 2023.
;; To use erc-highlight-nicknames.el, put this in your init file:
;;
@ -108,8 +108,7 @@
(defface erc-highlight-nick-base-face
'((t nil))
"Base face used for highlighting nicknames in ERC before the
color is added."
"Face used for highlighting nicknames before color is added."
:group 'erc-faces)
(defvar erc-highlight-face-table
@ -117,7 +116,7 @@ color is added."
"Hash table containing unique ERC nickname faces.")
(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
value of 0.299 red + 0.587 green + 0.114 blue and is always
between 0 and 255."
@ -128,7 +127,7 @@ between 0 and 255."
(floor (+ (* 0.299 r) (* 0.587 g) (* 0.114 b)) 256)))
(defun invert-color (color)
"Returns the inverted color of COLOR."
"Return the inverted color of COLOR."
(let* ((values (x-color-values color))
(r (car values))
(g (car (cdr values)))

57
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
@ -41,24 +41,23 @@
(defcustom esv-close-existing-buffers nil
"Whether to close an existing `esv' buffer if one already exists."
:type 'boolean
:group 'esv)
:type 'boolean)
(defcustom esv-columns 72
"Length of each line output by `esv'."
:type 'natnum
:group 'esv)
:type 'natnum)
(defcustom esv-mode-hook nil
"Hook run after entering `esv-mode'."
:type 'hook
:group 'esv)
:type 'hook)
(defcustom esv-process "esv"
"Name of the process created by `esv'."
:type 'string
:group 'esv)
:type 'string)
(defcustom esv-program "esv"
"Path to or name of the program started by `esv'."
:type 'string
:group 'esv)
:type 'string)
(defvar esv-arguments '()
"List of additional arguments passed to `esv-program'.")
@ -69,31 +68,35 @@
(read-only-mode))
(defun esv (book verses)
"Fetch the Bible passage identified by BOOK and VERSES.
The result will be redirected to a buffer named after the passage.
(defun esv (passage)
"Fetch the Bible passage identified by 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.
esv can be acquired at <https://sr.ht/~jeremy/esv>."
(interactive "MBook: \nMVerses: ")
(let
((buffer (concat book " " verses))
(interactive "MPassage: ")
(let*
((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
(list (format "-l%d" esv-columns)))))
(list (format "-l%d" esv-columns))
(list book) (list verses))))
(catch 'buffer-exists
(when (get-buffer buffer)
(unless esv-close-existing-buffers
(message "Buffer `%s' already exists" buffer)
(throw 'buffer-exists nil))
(kill-buffer buffer))
(apply #'call-process esv-program nil buffer t
(append arg-list (list book) (list verses)))
(display-buffer buffer)
(with-current-buffer buffer
(esv-mode)
(goto-char (point-min)))
(set-window-start (get-buffer-window buffer) (point-min))
t)))
(kill-buffer buffer)))
(apply #'call-process esv-program nil buffer t arg-list)
(display-buffer buffer)
(with-current-buffer buffer
(esv-mode)
(goto-char (point-min)))
(set-window-start (get-buffer-window buffer) (point-min)))
t)
(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
@ -25,7 +25,7 @@
;;; Commentary:
;; phobos.el provides several functions for viewing Phobos documentation
;; and documentation for other D libraries. These functions open the
;; and documentation for other D libraries. These functions open the
;; documentation in a web browser, calling the process `phobos-browser'.
;; These functions are provided:
@ -43,22 +43,19 @@
(defcustom phobos-browser "xdg-open"
"Web browser to use when opening documentation with `phobos'."
:group 'phobos
:type 'string)
(defcustom phobos-root "https://dlang.org/library"
"Root URL to use when viewing documentation with `phobos'."
:group 'phobos
:type 'string)
(defcustom phobos-dpldocs-domain "dpldocs.info"
"Root domain to use when viewing documentation on dub packages with `dub-doc'."
:group 'phobos
:type 'string)
(defcustom phobos-registry-root "https://code.dlang.org"
"Root URL of the D package registry used with `describe-dub-package'."
:group 'phobos
:type 'string)
(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)))
(shell-command (concat phobos-browser " " url))
(message url)))
@ -71,7 +68,7 @@ SYMBOL can be a module (e.g. std.sumtype), a submodule (e.g.
std.algorithm.searching), a function or type (e.g. std.stdio.File)
or any other symbol part of a standard module, such as object.Exception.
Phobos is the standard library for the D programming language. For more
Phobos is the standard library for the D programming language. For more
information on Phobos and the D programming language, see <https://dlang.org>."
(interactive "MModule or symbol: ")
(phobos--visit "%s/%s.html" phobos-root (string-replace "." "/" symbol)))
@ -81,7 +78,7 @@ information on Phobos and the D programming language, see <https://dlang.org>."
"View the documentation on SYMBOL from the dub package PACKAGE.
PACKAGE is the name of a package listed on the code.dlang.org registry.
For more information on SYMBOL, see the documentation for `phobos'. If
For more information on SYMBOL, see the documentation for `phobos'. If
SYMBOL is not provided, the contents of PACKAGE is displayed instead.
Support for dub package documentation is provided by Adam Ruppe's