-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelm-fzf.el
68 lines (54 loc) · 1.85 KB
/
helm-fzf.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
;;; helm-fzf.el --- helm binding for FZF
;; Copyright (C) 2011 Free Software Foundation, Inc.
;; Author: Ivan Buda Mandura (ivan.mandura93@gmail.com)
;; Version: 0.1
;; Package-Requires: ((emacs "24.4"))
;; Keywords: helm fzf
;;; Commentary:
;;; Code:
(require 'helm)
(require 'helm-files)
(require 's)
(require 'dash)
(defcustom helm-fzf-executable "fzf"
"Default executable for fzf"
:type 'stringp
:group 'helm-fzf)
(defun helm-fzf--project-root ()
(cl-loop for dir in '(".git/" ".hg/" ".svn/" ".git")
when (locate-dominating-file default-directory dir)
return it))
(defvar helm-fzf-source
(helm-build-async-source "fzf"
:candidates-process 'helm-fzf--do-candidate-process
:filter-one-by-one 'identity
:requires-pattern 3
:action 'helm-find-file-or-marked
:candidate-number-limit 9999))
(defun helm-fzf--do-candidate-process ()
(let* ((cmd-args (-filter 'identity (list helm-fzf-executable
"--no-sort"
"-f"
helm-pattern)))
(proc (apply 'start-file-process "helm-fzf" helm-buffer cmd-args)))
(prog1 proc
(set-process-sentinel
(get-buffer-process helm-buffer)
#'(lambda (process event)
(helm-process-deferred-sentinel-hook
process event (helm-default-directory)))))))
;;;###autoload
(defun helm-fzf (directory)
(interactive "D")
(let ((default-directory directory))
(helm :sources '(helm-fzf-source)
:buffer "*helm-fzf*")))
(defun helm-fzf-project-root ()
(interactive)
(let ((default-directory (helm-fzf--project-root)))
(unless default-directory
(error "Could not find the project root."))
(helm :sources '(helm-fzf-source)
:buffer "*helm-fzf*")))
(provide 'helm-fzf)
;;; helm-fzf.el ends here