Skip to content

Commit c88a359

Browse files
committed
Add :meow-state keyword for use-package declarations
1 parent d180d47 commit c88a359

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

CUSTOMIZATIONS.org

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,18 @@ change the variable =meow-cursor-type-insert=.
358358

359359
Association list of symbols to their corresponding keymaps. Used
360360
to generate =meow-*-define-key= helpers.
361+
362+
* Integration to other packages
363+
** :meow-state use-package keyword
364+
365+
Simple keyword ~:meow-state~ added to [[https://github.com/jwiegley/use-package][use-package]] declarations. Used to help
366+
populate ~meow-mode-state-list~, as follows:
367+
368+
#+begin_src emacs-lisp
369+
(use-package sly
370+
:meow-state ((sly-inspector-mode . motion)
371+
(sly-db-mode . motion)))
372+
#+end_src
373+
374+
The above would make the ~sly-inspector~ and ~sly-db~ modes start in Meow's
375+
~motion~ state.

meow-use-package.el

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;;; meow-use-package.el --- use-package keywords for Meow -*- lexical-binding: t; -*-
2+
3+
;; This file is not part of GNU Emacs.
4+
5+
;; This program is free software; you can redistribute it and/or
6+
;; modify it under the terms of the GNU General Public License
7+
;; as published by the Free Software Foundation; either version 3
8+
;; of the License, or (at your option) any later version.
9+
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with GNU Emacs; see the file COPYING. If not, write to the
17+
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18+
;; Boston, MA 02110-1301, USA.
19+
20+
;;; Commentary:
21+
;; Add keywords to be used in `use-package' declarations.
22+
;; - :meow-state
23+
;; Can be used to populate `meow-mode-state-list' in the same manner as
24+
;; setting up hooks with the :hook keyword. For example:
25+
26+
;; (use-package sly
27+
;; :meow-state ((sly-inspector-mode . motion)
28+
;; (sly-db-mode . motion)))
29+
30+
;; The above would make the `sly-inspector' and `sly-db' modes start in Meow's
31+
;; motion state.
32+
33+
;;; Code:
34+
35+
(require 'cl)
36+
(require 'use-package)
37+
38+
;;;; :meow-state keyword
39+
40+
(add-to-list 'use-package-keywords ':meow-state 'append)
41+
42+
;; We re-use the normalize method from :hook. This way we get the parsing of
43+
;; both a single cons, and a list of several.
44+
(defalias 'use-package-normalize/:meow-state #'use-package-normalize/:hook)
45+
46+
(defun use-package-handler/:meow-state (name-symbol keyword args rest state)
47+
(use-package-concat
48+
(use-package-process-keywords name-symbol rest state)
49+
`(,@(cl-loop for arg in args
50+
collect `(add-to-list 'meow-mode-state-list (quote ,arg))))))
51+
52+
(provide 'meow-use-package)
53+
;;; meow-use-package.el ends here

meow.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
(require 'meow-core)
4242
(require 'meow-cheatsheet)
4343
(require 'meow-tutor)
44+
(when (fboundp #'use-package)
45+
(require 'meow-use-package))
4446

4547
(provide 'meow)
4648
;;; meow.el ends here

0 commit comments

Comments
 (0)