From b649a257550f37ff7b0f96d417d4b80613141977 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 2 Apr 2021 13:07:24 -0500 Subject: Add `defun-with-hooks' --- init.el | 17 +++++++++++++++-- lisp/acdw.el | 10 ++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/init.el b/init.el index 3756690..5d900ce 100644 --- a/init.el +++ b/init.el @@ -101,10 +101,15 @@ word-wrap t truncate-lines nil) (add-hook 'text-mode-hook #'turn-on-auto-fill) -(add-hook 'prog-mode-hook #'turn-on-auto-fill) (global-display-fill-column-indicator-mode +1) (global-so-long-mode +1) +;; Only fill comments in prog-mode. +(defun-with-hooks '(prog-mode) + (defun hook--auto-fill-prog-mode () + (setq-local comment-auto-fill-only-comments t) + (turn-on-auto-fill))) + ;;;; Whitespace (setc whitespace-style '(empty indentation space-before-tab space-after-tab) @@ -118,7 +123,6 @@ show-paren-style 'mixed show-paren-when-point-inside-paren t show-paren-when-point-in-periphery t) -(show-paren-mode +1) (add-hook 'prog-mode-hook #'electric-pair-local-mode) ;;;; Killing and yanking @@ -371,6 +375,15 @@ w32-pass-apps-to-system nil w32-apps-modifier 'hyper)) +;;;; Set up non-special modes +;; Great idea from brause.cc +(defun-with-hooks '(text-mode-hook prog-mode-hook diff-mode-hook) + (defun hook--setup-regular-modes () + (setq indicate-empty-lines t + indicate-buffer-boundaries '((top . right) (bottom . right))) + (goto-address-mode +1) + (show-paren-mode +1))) + ;;;; Etc. good defaults (setc custom-file (acdw/in-dir "custom.el") inhibit-startup-screen t diff --git a/lisp/acdw.el b/lisp/acdw.el index 0203f3b..b127827 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -58,6 +58,16 @@ Ready for use with `after-focus-change-function'." (run-at-time sunset-time (* 60 60 24) sunset-command) (run-at-time "12:00am" (* 60 60 24) sunset-command))) +;;;; Define a function and add it to hooks +(defun defun-with-hooks (hooks function-def) + "Add FUNCTION-DEF to HOOKS. + +FUNCTION-DEF should be a `defun' form. This function is just to + put functions that only exist for hooks closer to the hooks + they bind to." + (let ((func function-def)) + (dolist (hook hooks) + (add-hook hook func)))) ;;; Garbage collection hacks (defconst acdw/gc-cons-threshold-basis (* 800 1024) -- cgit 1.4.1-21-gabe81