-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathivy-describe-modes.el
108 lines (89 loc) · 3.56 KB
/
ivy-describe-modes.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;;; ivy-describe-modes.el --- Ivy interface to `describe-mode` -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2024 Shen, Jen-Chieh
;; Created date 2020-07-02 19:56:29
;; Author: Shen, Jen-Chieh <jcs090218@gmail.com>
;; Description: Ivy interface to `describe-mode`.
;; Keyword: modes
;; Version: 0.2.0
;; Package-Requires: ((emacs "24.4") (ivy "0.13.0"))
;; URL: https://github.com/jcs-elpa/ivy-describe-modes
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Ivy interface to `describe-mode`.
;;
;;; Code:
(require 'ivy)
(defgroup ivy-describe-modes nil
"Ivy interface to `describe-mode`."
:prefix "ivy-describe-modes-"
:group 'tool
:link '(url-link :tag "Repository" "https://github.com/jcs-elpa/ivy-describe-modes"))
(defconst ivy-describe-modes--prompt "[Describe Modes]: "
"Prompt string when using `ivy-describe-modes'.")
(defun ivy-describe-modes--is-contain-list-string (in-list in-str)
"Check if IN-STR contain in any string in the IN-LIST."
(cl-some (lambda (lb-sub-str) (string-match-p (regexp-quote lb-sub-str) in-str)) in-list))
(defun ivy-describe-modes--minor-mode-list ()
"Get a list of minor modes."
(let ($list)
(mapc (lambda ($mode)
(condition-case nil
(when (symbolp $mode)
(setq $list (cons (format "%s" $mode) $list)))
(error nil)))
minor-mode-list)
(sort $list 'string<)))
(defun ivy-describe-modes--predicate (ob)
"Predciate to filter OB to major/minor mode list."
(and (functionp ob)
(string-suffix-p "-mode" (format "%s" ob))))
(defun ivy-describe-modes--do-action (cand)
"Do action after ivy done with CAND."
(describe-function (intern cand)))
;;;###autoload
(defun ivy-describe-modes-minor ()
"Describe modes with only minor modes."
(interactive)
(ivy-read ivy-describe-modes--prompt
(ivy-describe-modes--minor-mode-list)
:require-match t
:sort t
:predicate #'ivy-describe-modes--predicate
:action #'ivy-describe-modes--do-action))
;;;###autoload
(defun ivy-describe-modes-major ()
"Describe modes with only major modes."
(interactive)
(let ((min-lst (ivy-describe-modes--minor-mode-list)))
(ivy-read ivy-describe-modes--prompt
obarray
:require-match t
:sort t
:predicate
(lambda (ob)
(and (ivy-describe-modes--predicate ob)
(not (ivy-describe-modes--is-contain-list-string min-lst (format "%s" ob)))))
:action #'ivy-describe-modes--do-action)))
;;;###autoload
(defun ivy-describe-modes ()
"A convenient Ivy version of `describe-mode'."
(interactive)
(ivy-read ivy-describe-modes--prompt
obarray
:require-match t
:sort t
:predicate #'ivy-describe-modes--predicate
:action #'ivy-describe-modes--do-action))
(provide 'ivy-describe-modes)
;;; ivy-describe-modes.el ends here