commit | author | age
|
5cb5f7
|
1 |
;;; helm-x-files.el --- helm auxiliary functions and sources. -*- lexical-binding: t -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2012 ~ 2018 Thierry Volpiatto <thierry.volpiatto@gmail.com> |
|
4 |
|
|
5 |
;; This program is free software; you can redistribute it and/or modify |
|
6 |
;; it under the terms of the GNU General Public License as published by |
|
7 |
;; the Free Software Foundation, either version 3 of the License, or |
|
8 |
;; (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 this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
|
|
18 |
;;; Code: |
|
19 |
|
|
20 |
(require 'helm-for-files) |
|
21 |
|
|
22 |
|
|
23 |
;;; List of files gleaned from every dired buffer |
|
24 |
;; |
|
25 |
;; |
|
26 |
(defun helm-files-in-all-dired-candidates () |
|
27 |
(save-excursion |
|
28 |
(cl-loop for (f . b) in dired-buffers |
|
29 |
when (buffer-live-p b) |
|
30 |
append (let ((dir (with-current-buffer b dired-directory))) |
|
31 |
(if (listp dir) (cdr dir) |
|
32 |
(directory-files f t dired-re-no-dot)))))) |
|
33 |
|
|
34 |
;; (dired '("~/" "~/.emacs.d/.emacs-custom.el" "~/.emacs.d/.emacs.bmk")) |
|
35 |
|
|
36 |
(defclass helm-files-dired-source (helm-source-sync helm-type-file) |
|
37 |
((candidates :initform #'helm-files-in-all-dired-candidates))) |
|
38 |
|
|
39 |
(defvar helm-source-files-in-all-dired |
|
40 |
(helm-make-source "Files in all dired buffer." 'helm-files-dired-source)) |
|
41 |
|
|
42 |
;;; session.el files |
|
43 |
;; |
|
44 |
;; session (http://emacs-session.sourceforge.net/) is an alternative to |
|
45 |
;; recentf that saves recent file history and much more. |
|
46 |
(defvar session-file-alist) |
|
47 |
(defclass helm-source-session-class (helm-source-sync) |
|
48 |
((candidates :initform (lambda () |
|
49 |
(cl-delete-if-not |
|
50 |
(lambda (f) |
|
51 |
(or (string-match helm-tramp-file-name-regexp f) |
|
52 |
(file-exists-p f))) |
|
53 |
(mapcar 'car session-file-alist)))) |
|
54 |
(keymap :initform helm-generic-files-map) |
|
55 |
(help-message :initform helm-generic-file-help-message) |
|
56 |
(action :initform 'helm-type-file-actions))) |
|
57 |
|
|
58 |
(defvar helm-source-session nil |
|
59 |
"File list from emacs-session.") |
|
60 |
|
|
61 |
(defcustom helm-session-fuzzy-match nil |
|
62 |
"Enable fuzzy matching in `helm-source-session' when non--nil." |
|
63 |
:group 'helm-files |
|
64 |
:type 'boolean |
|
65 |
:set (lambda (var val) |
|
66 |
(set var val) |
|
67 |
(setq helm-source-session |
|
68 |
(helm-make-source "Session" 'helm-source-session-class |
|
69 |
:fuzzy-match val)))) |
|
70 |
|
|
71 |
|
|
72 |
;;; External searching file tools. |
|
73 |
;; |
|
74 |
;; Tracker desktop search |
|
75 |
|
|
76 |
(defun helm-source-tracker-transformer (candidates _source) |
|
77 |
;; loop through tracker candidates selecting out file:// lines |
|
78 |
;; then select part after file:// and url decode to get straight filenames |
|
79 |
(cl-loop for cand in candidates |
|
80 |
when (and (stringp cand) |
|
81 |
(string-match "\\`[[:space:]]*file://\\(.*\\)" cand)) |
|
82 |
collect (url-unhex-string (match-string 1 cand)))) |
|
83 |
|
|
84 |
(defvar helm-source-tracker-search |
|
85 |
(helm-build-async-source "Tracker Search" |
|
86 |
:candidates-process |
|
87 |
(lambda () |
|
88 |
;; the tracker-search command has been deprecated, now invoke via tracker |
|
89 |
;; also, disable the contextual snippets which we don't currently use |
|
90 |
(start-process "tracker-search-process" nil |
|
91 |
"tracker" "search" |
|
92 |
"--disable-snippets" |
|
93 |
"--disable-color" |
|
94 |
"--limit=512" |
|
95 |
helm-pattern)) |
|
96 |
;; new simplified transformer of tracker search results |
|
97 |
:filtered-candidate-transformer #'helm-source-tracker-transformer |
|
98 |
;;(multiline) ; https://github.com/emacs-helm/helm/issues/529 |
|
99 |
:keymap helm-generic-files-map |
|
100 |
:action 'helm-type-file-actions |
|
101 |
:action-transformer '(helm-transform-file-load-el |
|
102 |
helm-transform-file-browse-url) |
|
103 |
:requires-pattern 3) |
|
104 |
"Source for retrieving files matching the current input pattern |
|
105 |
with the tracker desktop search.") |
|
106 |
|
|
107 |
;; Spotlight (MacOS X desktop search) |
|
108 |
(defclass helm-mac-spotlight-source (helm-source-async helm-type-file) |
|
109 |
((candidates-process :initform |
|
110 |
(lambda () |
|
111 |
(start-process |
|
112 |
"mdfind-process" nil "mdfind" helm-pattern))) |
|
113 |
(requires-pattern :initform 3))) |
|
114 |
|
|
115 |
(defvar helm-source-mac-spotlight |
|
116 |
(helm-make-source "mdfind" 'helm-mac-spotlight-source) |
|
117 |
"Source for retrieving files via Spotlight's command line |
|
118 |
utility mdfind.") |
|
119 |
|
|
120 |
(provide 'helm-x-files) |
|
121 |
|
|
122 |
;; Local Variables: |
|
123 |
;; byte-compile-warnings: (not obsolete) |
|
124 |
;; coding: utf-8 |
|
125 |
;; indent-tabs-mode: nil |
|
126 |
;; End: |
|
127 |
|
|
128 |
;;; helm-x-files.el ends here |