forked from emacs-helm/helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helm-plugin.el
137 lines (107 loc) · 4.35 KB
/
helm-plugin.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;;; helm-plugin.el --- Helm plugins -*- lexical-binding: t -*-
;; Copyright (C) 2012 ~ 2015 Thierry Volpiatto <[email protected]>
;; 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 <http://www.gnu.org/licenses/>.
;;; Code:
(require 'cl-lib)
(require 'helm)
(require 'helm-utils)
;;; Plug-in: `info-index'
;;
;;
(defun helm-make-info-source (source file)
`(,@source
(name . ,(concat "Info Index: " file))
(info-file . ,file)
(init . helm-info-init)
(display-to-real . helm-info-display-to-real)
(get-line . buffer-substring)
(candidates-in-buffer)
(action ("Goto node" . helm-info-goto))))
(defun helm-compile-source--info-index (source)
(helm-aif (helm-interpret-value (assoc-default 'info-index source))
(helm-make-info-source source it)
source))
(add-to-list 'helm-compile-source-functions 'helm-compile-source--info-index)
(helm-document-attribute 'info-index "info-index plugin"
" Create a source of info index very easily.
Example:
(defvar helm-source-info-wget '((info-index . \"wget\"))")
;;; Plug-in: `candidates-file'
;;
;; List all lines in a file.
(defun helm-compile-source--candidates-file (source)
(if (assoc-default 'candidates-file source)
`((init helm-p-candidates-file-init
,@(let ((orig-init (assoc-default 'init source)))
(cond ((null orig-init) nil)
((functionp orig-init) (list orig-init))
(t orig-init))))
(candidates-in-buffer)
,@source)
source))
(add-to-list 'helm-compile-source-functions 'helm-compile-source--candidates-file)
(defun helm-p-candidates-file-init ()
(cl-destructuring-bind (file &optional updating)
(helm-mklist (helm-attr 'candidates-file))
(setq file (helm-interpret-value file))
(with-current-buffer (helm-candidate-buffer 'global)
(insert-file-contents file)
(when updating
(buffer-disable-undo)
(font-lock-mode -1)
(auto-revert-mode 1)))))
(helm-document-attribute 'candidates-file "candidates-file plugin"
" Use a file as the candidates buffer.
1st argument is a filename, string or function name or variable
name. If optional 2nd argument is non-nil, the file is opened with
`auto-revert-mode' enabled.
Example:
\(defvar helm-source-test-file
'((name . \"test1\")
(candidates-file \"~/.emacs.el\" t)))
Will list all lines in .emacs.el.")
;;; Plug-in: `persistent-help'
;;
;; Add help about persistent action in `helm-buffer' header.
(defun helm-compile-source--persistent-help (source)
(if (assoc 'header-line source)
source
(append source '((header-line . helm-persistent-help-string)))))
(add-to-list 'helm-compile-source-functions 'helm-compile-source--persistent-help)
(defun helm-persistent-help-string ()
(substitute-command-keys
(concat "\\<helm-map>\\[helm-execute-persistent-action]: "
(or (helm-interpret-value (helm-attr 'persistent-help))
(helm-aif (or (assoc-default
'persistent-action
(helm-get-current-source))
(assoc-default
'action (helm-get-current-source)))
(cond ((symbolp it)
(symbol-name it))
((listp it)
(or (ignore-errors (caar it)) ""))))
"")
" (keeping session)")))
;;; Document new attributes
;;
;;
(helm-document-attribute 'persistent-help "persistent-help plug-in"
" A string to explain persistent-action of this source. It also
accepts a function or a variable name.")
(provide 'helm-plugin)
;; Local Variables:
;; byte-compile-warnings: (not cl-functions obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:
;;; helm-plugin ends here