branch: externals/lin
commit e5a0da969ebd0d3e3d04f80222aa0846559a5f88
Author: Damien Cassou <dam...@cassou.me>
Commit: Damien Cassou <dam...@cassou.me>

    Add function lin-add-to-many-modes and option lin-foreign-hooks (#3)
---
 README.org |  9 +++++----
 lin.el     | 27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index dfce823560..ad27641531 100644
--- a/README.org
+++ b/README.org
@@ -129,15 +129,16 @@ Everything is in place to set up the package.
 (add-hook 'elfeed-search-mode-hook #'lin-mode)
 #+end_src
 
-Or for more mode hooks:
+To activate ~lin-mode~ on all modes where it makes sense:
 
 #+begin_src emacs-lisp
 (require 'lin)
-
-(dolist (hook '(elfeed-search-mode-hook notmuch-search-mode-hook))
-  (add-hook hook #'lin-mode))
+(lin-add-to-many-modes)
 #+end_src
 
+The customization option ~lin-foreign-hooks~ lets you configure the
+list of hooks affected by ~lin-add-to-many-modes~.
+
 Else invoke ~lin-mode~ interactively.
 
 #+vindex: lin-override-foreground
diff --git a/lin.el b/lin.el
index 56b5a070db..95d6ca228e 100644
--- a/lin.el
+++ b/lin.el
@@ -60,6 +60,21 @@
 
 (require 'face-remap)
 
+(defconst lin--default-foreign-hooks
+  ;; please keep the list sorted:
+  '(elfeed-search-mode-hook
+    git-rebase-mode-hook
+    ibuffer-mode-hook
+    ledger-report-mode-hook
+    log-view-mode-hook
+    magit-log-mode-hook
+    notmuch-search-mode-hook
+    notmuch-tree-mode-hook
+    org-agenda-mode-hook
+    tabulated-list-mode-hook)
+  "List of default hooks in which to use `lin-mode'.
+See also the user option `lin-override-foreground'.")
+
 (defgroup lin ()
   "Locally remap `hl-line' face for greater flexility."
   :group 'convenience)
@@ -77,6 +92,13 @@ the `lin-hl-override-fg' is applied."
   :type 'boolean
   :group 'lin)
 
+(defcustom lin-foreign-hooks lin--default-foreign-hooks
+  "List of hook variable names in which to use `lin-mode'.
+
+Call `lin-add-to-many-modes' to start `lin-mode' for all these
+hooks."
+  :type '(repeat variable))
+
 (defface lin-hl
   '((default :foreground unspecified :underline nil :extend t)
     (((class color) (min-colors 88) (background light))
@@ -131,6 +153,11 @@ The overall style is controlled by 
`lin-override-foreground'."
             (face-remap-add-relative (lin--source-face) (lin--dest-face)))
     (face-remap-remove-relative lin--cookie)))
 
+(defun lin-add-to-many-modes ()
+  "Turn on `lin-mode' on every mode of `lin-foreign-hooks'."
+  (dolist (hook lin-foreign-hooks)
+    (add-hook hook #'lin-mode)))
+
 (provide 'lin)
 
 ;;; lin.el ends here

Reply via email to