From b7295426c95bf968288bb6ead2db416a71ec4d3e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 9 Jan 2022 20:52:07 -0600 Subject: Weekend, babee --- lisp/+apheleia.el | 3 +- lisp/+casing.el | 25 +++++----- lisp/+circe.el | 130 +++++++++++++++++++++++++++++++++++++++++---------- lisp/+elfeed.el | 7 --- lisp/+embark.el | 4 +- lisp/+lookup.el | 26 ----------- lisp/+org-capture.el | 16 +++++++ lisp/+vertico.el | 8 ++++ lisp/acdw.el | 10 ++-- 9 files changed, 151 insertions(+), 78 deletions(-) delete mode 100644 lisp/+lookup.el (limited to 'lisp') diff --git a/lisp/+apheleia.el b/lisp/+apheleia.el index f3b16e4..469232a 100644 --- a/lisp/+apheleia.el +++ b/lisp/+apheleia.el @@ -8,9 +8,8 @@ (setq-local indent-line-function (buffer-local-value 'indent-line-function orig)) (indent-region (point-min) -(point-max)) + (point-max)) (funcall callback))) (provide '+apheleia) ;;; +apheleia.el ends here - \ No newline at end of file diff --git a/lisp/+casing.el b/lisp/+casing.el index 5f39b2e..c8e9e4d 100644 --- a/lisp/+casing.el +++ b/lisp/+casing.el @@ -3,7 +3,6 @@ ;;; Code: (require 'thingatpt) -(require '+key) ;;;###autoload (defun +upcase-dwim (arg) @@ -61,21 +60,23 @@ Otherwise, it calls `capitalize-word' on the word at point (using ;; Later on, I'll add repeat maps and stuff in here... +(defvar +casing-map (let ((map (make-sparse-keymap))) + (define-key map "u" #'+upcase-dwim) + (define-key map (kbd "M-u") #'+upcase-dwim) + (define-key map "l" #'+downcase-dwim) + (define-key map (kbd "M-l") #'+downcase-dwim) + (define-key map "c" #'+capitalize-dwim) + (define-key map (kbd "M-c") #'+capitalize-dwim) + map) + "Keymap for case-related twiddling.") + (define-minor-mode +casing-mode "Enable easy case-twiddling commands." :lighter " cC" + :global t :keymap (let ((map (make-sparse-keymap))) - (define-key map "u" #'+upcase-dwim) - (define-key map (kbd "M-u") #'+upcase-dwim) - (define-key map "l" #'+downcase-dwim) - (define-key map (kbd "M-l") #'+downcase-dwim) - (define-key map "c" #'+capitalize-dwim) - (define-key map (kbd "M-c") #'+capitalize-dwim) - map) - (define-key +key-mode-map (kbd "M-c") (when +casing-mode - +casing-mode-map))) - -(defvaralias '+casing-map '+casing-mode-map) + (define-key map (kbd "M-c") +casing-map) + map)) (provide '+casing) ;;; +casing.el ends here diff --git a/lisp/+circe.el b/lisp/+circe.el index c29cea6..3d6ea60 100644 --- a/lisp/+circe.el +++ b/lisp/+circe.el @@ -101,9 +101,11 @@ For entry into `lui-formatting-list'." (defun +circe-kill-buffer (&rest _) "Kill a circe buffer without confirmation, and after a delay." - (let ((circe-channel-killed-confirmation nil) - (circe-server-killed-confirmation nil)) - (run-with-timer 0.25 nil 'kill-buffer))) + (let ((circe-channel-killed-confirmation) + (circe-server-killed-confirmation)) + (when (derived-mode-p 'lui-mode) ; don't spuriously kill + (ignore-errors + (kill-buffer))))) (defun +circe-quit@kill-buffer (&rest _) "ADVICE: kill all buffers of a server after `circe-command-QUIT'." @@ -115,9 +117,11 @@ For entry into `lui-formatting-list'." (defun +circe-gquit@kill-buffer (&rest _) "ADVICE: kill all Circe buffers after `circe-command-GQUIT'." - (dolist (buf (circe-server-buffers)) - (with-current-buffer buf - (+circe-quit@kill-buffer)))) + (let ((circe-channel-killed-confirmation) + (circe-server-killed-confirmation)) + (dolist (buf (circe-server-buffers)) + (with-current-buffer buf + (+circe-quit@kill-buffer))))) (defun +circe-quit-all@kill-emacs () "Quit all circe buffers when killing Emacs." @@ -165,28 +169,104 @@ See `circe-network-options' for a list of common options." (funcall +circe-server-buffer-action buffer)))) ;;; Chat commands -;; TODO: Actually ... write these~!?!?! - -(defun circe-command-SHORTEN (url) - "Shorten URL using `0x0-shorten-uri'.") (defun circe-command-SLAP (nick) - "Slap NICK around a bit with a large trout.") - -(defun circe-command-POKE (nick) - "Poke NICK like in the old Facebook days.") - -;;; Pure idiocy - -(define-minor-mode circe-cappy-hour-mode + "Slap NICK around a bit with a large trout." + (interactive (list (completing-read "Nick to slap: " + (circe-channel-nicks) + nil t nil))) + (circe-command-ME (format "slaps %s about a bit with a large trout" nick))) + +;;; Filtering functions +;; Set `lui-input-function' to `+lui-filter', then add the filters you want to +;; `circe-channel-mode-hook'. + +(require 'dash) + +(defvar +lui-filters nil + "Stack of input functions to apply. +This is an alist with cells of the structure (TAG . FN), so we +can easily remove elements.") +(make-variable-buffer-local '+lui-filters) + +(defun +lui-filter (text &optional fn-alist) + (let ((fs (nreverse (purecopy (or fn-alist +lui-filters))))) + (while fs + (setq text (funcall (cdr (pop fs)) text))) + (circe--input text))) + +(defmacro +circe-define-filter (name docstring &rest body) + "Define a filter for circe-inputted text." + (declare (doc-string 2) + (indent 1)) + (let (plist) + (while (keywordp (car-safe body)) + (push (pop body) plist) + (push (pop body) plist)) + ;; Return value + `(define-minor-mode ,name + ,docstring + ,@(nreverse plist) + (when (derived-mode-p 'circe-chat-mode) + (if ,name + (push '(,name . (lambda (it) ,@body)) +lui-filters) + (setq +lui-filters + (assoc-delete-all ',name +lui-filters))))))) + +;; CAPPY HOUR! (Pure idiocy) + +(+circe-define-filter +circe-cappy-hour-mode "ENABLE CAPPY HOUR IN CIRCE!" - :lighter "CAPPY HOUR" - (when (derived-mode-p 'circe-chat-mode) - (if circe-cappy-hour-mode - (setq-local lui-input-function - (lambda (input) (circe--input (upcase input)))) - ;; XXX: It'd be better if this were more general, but whatever. - (setq-local lui-input-function #'circe--input)))) + :lighter " CAPPY HOUR" + (upcase it)) + +;; URL Shortener + +(+circe-define-filter +circe-shorten-url-mode + "Shorten long urls when chatting." + :lighter " c0x0" + (+circe-0x0-shorten-urls it)) + +(defvar +circe-0x0-max-length 20 + "Maximum length of URLs before using a shortener.") + +(defun +circe-0x0-shorten-urls (text) + "Find urls in TEXT and shorten them using `0x0'." + (require '0x0) + (require 'browse-url) + (let ((case-fold-search t)) + (replace-regexp-in-string + browse-url-button-regexp + (lambda (match) + (if (> (length match) +circe-0x0-max-length) + (+with-message (format "Shortening URL: %s" match) + (0x0-shorten-uri (0x0--choose-server) + (substring-no-properties match))) + match)) + text))) + +;; Temperature conversion + +(+circe-define-filter +circe-F/C-mode + "Convert degF to degF/degC for international chats." + :lighter " F/C" + (str-F/C it)) + +(defun fahrenheit-to-celsius (degf) + "Convert DEGF to Celsius." + (round (* (/ 5.0 9.0) (- degf 32)))) + +(defun celsius-to-fahrenheit (degc) + "Convert DEGC to Fahrenheit." + (round (+ 32 (* (/ 9.0 5.0) degc)))) + +(defun str-F/C (text) + (replace-regexp-in-string "[0-9.]+[Ff]" + (lambda (match) + (format "%s/%dC" match + (fahrenheit-to-celsius + (string-to-number match)))) + text)) (provide '+circe) ;;; +circe.el ends here diff --git a/lisp/+elfeed.el b/lisp/+elfeed.el index c26bfab..4ee7581 100644 --- a/lisp/+elfeed.el +++ b/lisp/+elfeed.el @@ -21,12 +21,5 @@ (scroll-down-command arg) (error (elfeed-show-prev))))) -;; https://babbagefiles.blogspot.com/2017/03/take-elfeed-everywhere-mobile-rss.html -(defun +elfeed () - "Wrapper to load the elfeed db from disk before opening." - (interactive) - (elfeed-db-load) - (elfeed)) - (provide '+elfeed) ;;; +elfeed.el ends here diff --git a/lisp/+embark.el b/lisp/+embark.el index 3900492..e66d4b3 100644 --- a/lisp/+embark.el +++ b/lisp/+embark.el @@ -7,7 +7,6 @@ ;;; Code: (require 'embark) -(require 'marginalia) (embark-define-keymap embark-straight-map ("u" straight-visit-package-website) @@ -22,7 +21,8 @@ (add-to-list 'embark-keymap-alist '(straight . embark-straight-map)) -(add-to-list 'marginalia-prompt-categories '("recipe\\|package" . straight)) +(with-eval-after-load 'marginalia + (add-to-list 'marginalia-prompt-categories '("recipe\\|package" . straight))) (provide '+embark) ;;; +embark.el ends here diff --git a/lisp/+lookup.el b/lisp/+lookup.el deleted file mode 100644 index 755f84e..0000000 --- a/lisp/+lookup.el +++ /dev/null @@ -1,26 +0,0 @@ -;;; +lookup.el -*- lexical-binding: t; -*- - -;;; Commentary: - -;; I look up a lot of things in Emacs. Let's bind them all to an easy-to-use -;; keymap. - -;;; Code: - -(require '+key) - -(define-minor-mode +lookup-mode - "A mode for easily looking things up." - :lighter " l^" - :keymap (let ((map (make-sparse-keymap))) - (define-key map "f" #'find-function) - (define-key map "l" #'find-library) - (define-key map "v" #'find-variable) - map) - (define-key +key-mode-map (kbd "C-c l") (when +lookup-mode - +lookup-mode-map))) - -(defvaralias '+lookup-map '+lookup-mode-map) - -(provide '+lookup) -;;; +lookup.el ends here diff --git a/lisp/+org-capture.el b/lisp/+org-capture.el index ba036bd..6c59b98 100644 --- a/lisp/+org-capture.el +++ b/lisp/+org-capture.el @@ -85,5 +85,21 @@ properly process the variable." ;; Sort after, maybe (when sort-after (+org-capture-sort list)))) +(defun +org-template--ensure-path (keys &optional list) + "Ensure path of keys exists in `org-capture-templates'." + (unless list (setq list 'org-capture-templates)) + (when (> (length key) 1) + ;; Check for existence of groups. + (let ((expected (cl-loop for i from 1 to (1- (length key)) + collect (substring key 0 i) into keys + finally return keys))) + (cl-loop for ek in expected + if (not (+org-capture--get ek (symbol-value list))) do + (setf (+org-capture--get ek (symbol-value list)) + (list (format "(Group %s)" ek))))))) + +(defun +org-define-capture-template (keys title &rest args) + ) + (provide '+org-capture) ;;; +org-capture.el ends here diff --git a/lisp/+vertico.el b/lisp/+vertico.el index 4adde3d..d4fb3a3 100644 --- a/lisp/+vertico.el +++ b/lisp/+vertico.el @@ -12,5 +12,13 @@ (unless (eq 1 (abs (- beg-index vertico--index))) (ding)))) +(defun +vertico-widen-or-complete () + (interactive) + (if (or vertico-unobtrusive-mode + vertico-flat-mode) + (progn (vertico-unobtrusive-mode -1) + (vertico-flat-mode -1)) + (call-interactively #'vertico-insert))) + (provide '+vertico) ;;; +vertico.el ends here diff --git a/lisp/acdw.el b/lisp/acdw.el index 262c15e..603f46f 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -128,10 +128,12 @@ I keep forgetting how they differ." (defmacro +with-message (message &rest body) "Execute BODY, with MESSAGE. If body executes without errors, MESSAGE...Done will be displayed." - ;; ^ TODO - `(prog1 (progn (message ,(concat message "...")) - ,@body) - (message ,(concat message "...Done.")))) + (declare (indent 1)) + (let ((msg (gensym))) + `(let ((,msg ,message)) + (unwind-protect (progn (message "%s..." ,msg) + ,@body) + (message "%s... Done." ,msg))))) (defun +mapc-some-buffers (func &optional predicate) "Perform FUNC on all buffers satisfied by PREDICATE. -- cgit 1.4.1-21-gabe81