From 56304658779dae0bd720f56f49f1b296110653f8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 08:55:43 -0600 Subject: Add find-variable to +lookup-map --- lisp/+lookup.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp') diff --git a/lisp/+lookup.el b/lisp/+lookup.el index f13f535..8fa8795 100644 --- a/lisp/+lookup.el +++ b/lisp/+lookup.el @@ -15,6 +15,7 @@ :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))) -- cgit 1.4.1-21-gabe81 From 81152ca24289d2b08fcfe64b19164894c048524e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:46:50 -0600 Subject: Add +flyspell-correct-buffer --- init.el | 4 +++- lisp/+flyspell-correct.el | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lisp/+flyspell-correct.el (limited to 'lisp') diff --git a/init.el b/init.el index 07679e7..67528fd 100644 --- a/init.el +++ b/init.el @@ -948,9 +948,11 @@ See also `crux-reopen-as-root-mode'." (:+key "M-q" #'filldent-dwim)) (setup (:straight flyspell-correct) + (:+also-load +flyspell-correct ) (:option flyspell-correct--cr-key ";") (:bind-into flyspell - "C-;" #'flyspell-correct-wrapper)) + "C-;" #'flyspell-correct-wrapper + "" #'+flyspell-correct-buffer)) (setup (:straight-when (forge :host github :repo "magit/forge") diff --git a/lisp/+flyspell-correct.el b/lisp/+flyspell-correct.el new file mode 100644 index 0000000..473b054 --- /dev/null +++ b/lisp/+flyspell-correct.el @@ -0,0 +1,12 @@ +;;; +flyspell-correct.el --- -*- lexical-binding: t; -*- + +;;; Code: + +(defun +flyspell-correct-buffer (&rest _) ; Enables this to be run as a hook + "Run `flyspell-correct-wrapper' on all misspelled words in the buffer." + (interactive) + (+with-message "Checking spelling" + (flyspell-correct-move (point-min) :forward :rapid))) + +(provide '+flyspell-correct) +;;; +flyspell-correct.el ends here -- cgit 1.4.1-21-gabe81 From 84139db9a8869b31f831fb154bdc209e06db5ab3 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:47:09 -0600 Subject: Add user-save-mode --- init.el | 5 ++++- lisp/user-save.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 lisp/user-save.el (limited to 'lisp') diff --git a/init.el b/init.el index 67528fd..5bf4dee 100644 --- a/init.el +++ b/init.el @@ -104,6 +104,9 @@ (setup (:require reading) (:global "C-c C-r" #'reading-mode)) +(setup (:require user-save) + (user-save-mode +1)) + (setup +key (+ensure-after-init #'+key-global-mode)) @@ -450,7 +453,7 @@ "C-c C-l" #'+org-insert-link-dwim "C-c C-n" #'+org-next-heading-widen "C-c C-p" #'+org-previous-heading-widen) - (:local-hook before-save-hook #'+org-before-save@prettify-buffer) + (:local-hook user-save-hook #'+org-before-save@prettify-buffer) (advice-add #'org-delete-backward-char :override #'+org-delete-backward-char) (with-eval-after-load 'org (org-clock-persistence-insinuate) diff --git a/lisp/user-save.el b/lisp/user-save.el new file mode 100644 index 0000000..01adc22 --- /dev/null +++ b/lisp/user-save.el @@ -0,0 +1,45 @@ +;;; user-save.el -*- lexical-binding: t; -*- + +;; Because `super-save-mode' automatically saves every time we move away from a +;; buffer, it tends to run a lot of `before-save-hook's that don't need to be +;; run that often. For that reason, I'm writing a mode where C-x C-s saves +;; /and/ runs all the "real" before-save-hooks, so that super-save won't +;; automatically do things like format the buffer all the time. + +;;; Code: + +(defvar user-save-hook nil + "Hook to run when the user, not Emacs, saves the buffer.") + +(defvar user-save-mode-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-x C-s") #'user-save-buffer) + map) + "Keymap for `user-save-mode'. +This map shadows the default map for `save-buffer'.") + +(defun user-save-buffer (&optional arg) + "Save current buffer in visited file if modified. +This function is precisely the same as `save-buffer', but with +one modification: it also runs functions in `user-save-hook'. +This means that if you have some functionality in Emacs to +automatically save buffers periodically, but have hooks you want +to automatically run when the buffer saves that are +computationally expensive or just aren't something you want to +run all the time, put them in `user-save-hook'. + +ARG is passed directly to `save-buffer'." + (interactive '(called-interactively)) + (message "Saving the buffer...") + (with-demoted-errors (run-hooks 'user-save-hook)) + (save-buffer arg) + (message "Saving the buffer...Done.")) + +;;;###autoload +(define-minor-mode user-save-mode + "Mode to enable an an extra user-save hook." + :lighter " US" + :global t + :keymap 'user-save-mode-map) + +(provide 'user-save) +;;; user-save.el ends here -- cgit 1.4.1-21-gabe81 From 4dee486f1f1d39ebc523e03f61705656d8e9c326 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:47:42 -0600 Subject: Add +kill-word-backward-or-region --- init.el | 11 +++++++++-- lisp/+emacs.el | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'lisp') diff --git a/init.el b/init.el index 5bf4dee..a822cb8 100644 --- a/init.el +++ b/init.el @@ -34,10 +34,15 @@ "C-x 4 n" #'clone-buffer "C-c v" #'visible-mode "C-M-;" #'+lisp-comment-or-uncomment-sexp - "M-j" nil) + "M-j" nil + "C-x o" (lambda () (interactive) (switch-to-buffer nil)) + "C-x C-o" #'+open-paragraph + "C-w" #'+kill-word-backward-or-region) ;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults (global-set-key (kbd "C-h") 'delete-backward-char) (keyboard-translate ?\C-h ?\C-?) + ;; Hooks + ;; Advice ;; https://old.reddit.com/r/emacs/comments/rlli0u/whats_your_favorite_defadvice/hph14un/ (define-advice keyboard-escape-quit (:around (fn &rest r)) "Don't close splits on `keyboard-escape-quit'." @@ -1141,7 +1146,9 @@ See also `crux-reopen-as-root-mode'." (setup (:straight paredit) (:bind "DEL" #'paredit-backward-delete - "C-" #'paredit-backward-kill-word) + "C-" #'paredit-backward-kill-word + "C-w" (lambda (r) (interactive "P") + (+kill-word-backward-or-region r #'paredit-backward-kill-word))) (dolist (hook '(emacs-lisp-mode-hook eval-expression-minibuffer-setup-hook ielm-mode-hook diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 7453913..ecdfeaa 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -220,6 +220,15 @@ kill without asking." (save-buffers-kill-emacs)) (delete-frame nil :force))) +(defun +kill-word-backward-or-region (&optional arg backward-kill-word-fn) + "Kill active region or ARG words backward. +BACKWARD-KILL-WORD-FN is the function to call to kill a word +backward. It defaults to `backward-kill-word'." + (interactive "P") + (call-interactively (if (region-active-p) + #'kill-region + (or backward-kill-word-fn #'backward-kill-word)))) + ;; ... and advice ;; Indent the region after a yank. -- cgit 1.4.1-21-gabe81 From 75e03850c0ba098208c4999518b1b164c63a5eff Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:48:19 -0600 Subject: Fix naming bug I also added aliases just in case I forget the proper names for these maps again. --- init.el | 2 +- lisp/+casing.el | 2 ++ lisp/+lookup.el | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/init.el b/init.el index a822cb8..432ded7 100644 --- a/init.el +++ b/init.el @@ -1237,7 +1237,7 @@ See also `crux-reopen-as-root-mode'." :host github :repo "duckwork/titlecase.el" :files ("*"))) - (:with-map +casing-map + (:with-map +casing-mode-map (:bind "t" #'titlecase-dwim))) (setup (:straight topsy) diff --git a/lisp/+casing.el b/lisp/+casing.el index a21e710..5f39b2e 100644 --- a/lisp/+casing.el +++ b/lisp/+casing.el @@ -75,5 +75,7 @@ Otherwise, it calls `capitalize-word' on the word at point (using (define-key +key-mode-map (kbd "M-c") (when +casing-mode +casing-mode-map))) +(defvaralias '+casing-map '+casing-mode-map) + (provide '+casing) ;;; +casing.el ends here diff --git a/lisp/+lookup.el b/lisp/+lookup.el index 8fa8795..755f84e 100644 --- a/lisp/+lookup.el +++ b/lisp/+lookup.el @@ -20,5 +20,7 @@ (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 -- cgit 1.4.1-21-gabe81 From be15049058ae955e04e1181abb9ce0f9bebf94a1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:49:32 -0600 Subject: Add some extra functions --- lisp/acdw.el | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/acdw.el b/lisp/acdw.el index fcab61b..ca0a9fa 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -44,7 +44,6 @@ the filesystem, unless INHIBIT-MKDIR is non-nil." (make-directory (file-name-directory file-name) :parents)) file-name)))) - (defun +suppress-messages (oldfn &rest args) ; from pkal "Advice wrapper for suppressing `message'. OLDFN is the wrapped function, that is passed the arguments @@ -125,5 +124,65 @@ I keep forgetting how they differ." "Quick way to `setq' a variable from a `defvar' form." `(setq ,var ,value)) +(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.")))) + +(defun +mapc-some-buffers (func &optional predicate) + "Perform FUNC on all buffers satisfied by PREDICATE. +By default, act on all buffers. + +PREDICATE is a function called with one argument, the current +buffer. FUNC is called with no arguments. Both are called +within a `with-current-buffer' form." + (let ((pred (or predicate t))) + (dolist (buf (buffer-list)) + (with-current-buffer buf + (when (funcall pred buf) + (funcall func)))))) + +;; https://github.com/cstby/emacs.d/blob/main/init.el#L67 +(defun +clean-empty-lines (&optional begin end) + "Remove duplicate empty lines from BEGIN to END. +Called interactively, this function acts on the region, if +active, or else the entire buffer." + (interactive "*r") + (unless (region-active-p) + (setq begin (point-min) + end (save-excursion + (goto-char (point-max)) + (skip-chars-backward "\n[:space:]") + (point)))) + (save-excursion + (save-restriction + (narrow-to-region begin end) + (goto-char (point-min)) + (while (re-search-forward "\n\n\n+" nil :move) + (replace-match "\n\n")) + ;; Insert a newline at the end. + (goto-char (point-max)) + (unless (= (line-beginning-position) (line-end-position)) + (insert "\n"))))) + +(defun +open-paragraph () + "Open a paragraph after paragraph at point. +A paragraph is defined as continguous non-empty lines of text +surrounded by empty lines, so opening a paragraph means to make +three blank lines, then place the point on the second one." + (interactive "*") + (unless (derived-mode-p 'special-mode 'lui-mode 'comint-mode) + ;; Go to next blank line. This /isn't/ `end-of-paragraph-text' because + ;; that's weird with org, and I'm guessing other modes too. + (while (not (looking-at "^$")) + (forward-line 1)) + (newline) + (delete-blank-lines) + (newline 2) + (previous-line))) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81 From 13cbd6644a1798ef643d63dbb2784602a5fff4b5 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 16:43:16 -0600 Subject: Add option to user-save buffers when quitting Emacs --- lisp/user-save.el | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'lisp') diff --git a/lisp/user-save.el b/lisp/user-save.el index 01adc22..63fe424 100644 --- a/lisp/user-save.el +++ b/lisp/user-save.el @@ -8,6 +8,17 @@ ;;; Code: +(defgroup user-save nil + "Group for `user-save-mode' customizations." + :group 'emacs + :prefix "user-save-") + +(defcustom user-save-hook-into-kill-emacs nil + "Add a hook to perform `user-save' to `kill-emacs-hook'. +This option is only useful is `user-save-mode' is active when +Emacs is killed." + :type 'boolean) + (defvar user-save-hook nil "Hook to run when the user, not Emacs, saves the buffer.") @@ -34,12 +45,34 @@ ARG is passed directly to `save-buffer'." (save-buffer arg) (message "Saving the buffer...Done.")) +(defun user-save-some-buffers (&optional pred) + "Save some buffers as though the user saved them. +This function does not ask the user about each buffer, but PRED +is used in almost the same way as `save-some-buffers': if it's +nil or t, it will save all file-visiting modified buffers; if +it's a zero-argument function, that will be called to determine +whether the buffer needs to be saved." + ;; This could maybe be much better. + (interactive "P") + (unless pred (setq pred save-some-buffers-default-predicate)) + (dolist (buf (buffer-list)) + (with-current-buffer buf + (when (and (buffer-modified-p) + (buffer-file-name) + (or (null pred) + (if (functionp pred) (funcall pred) pred))) + (user-save-buffer))))) + ;;;###autoload (define-minor-mode user-save-mode "Mode to enable an an extra user-save hook." :lighter " US" :global t - :keymap 'user-save-mode-map) + :keymap 'user-save-mode-map + (if user-save-mode + (when user-save-hook-into-kill-emacs + (add-hook 'kill-emacs-hook #'user-save-some-buffers)) + (remove-hook 'kill-emacs-hook #'user-save-some-buffers))) (provide 'user-save) ;;; user-save.el ends here -- cgit 1.4.1-21-gabe81 From e4ce00f4d5c3cb91ca20e764d5a1c6a129181377 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 16:43:31 -0600 Subject: Add /POKE stub command TODO : I've got to write these commands!!! --- lisp/+circe.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lisp') diff --git a/lisp/+circe.el b/lisp/+circe.el index 501bd21..c29cea6 100644 --- a/lisp/+circe.el +++ b/lisp/+circe.el @@ -165,6 +165,7 @@ 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'.") @@ -172,6 +173,9 @@ See `circe-network-options' for a list of common options." (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 -- cgit 1.4.1-21-gabe81