summaryrefslogtreecommitdiff
path: root/helm-x-files.el
blob: b613ad2e068e29f2c3f3782dfa1bac27730404a3 (plain)
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
;;; helm-x-files.el --- helm auxiliary functions and sources. -*- lexical-binding: t -*-

;; Copyright (C) 2012 ~ 2019 Thierry Volpiatto <thierry.volpiatto@gmail.com>

;; 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/>.

;;; Commentary:

;;; Code:

(require 'helm-for-files)


;;; List of files gleaned from every dired buffer
;;
;;
(defvar dired-buffers)
(defvar dired-re-no-dot)
(defun helm-files-in-all-dired-candidates ()
  "Return a list of files from live `dired' buffers."
  (save-excursion
    (cl-loop for (f . b) in dired-buffers
          when (buffer-live-p b)
          append (let ((dir (with-current-buffer b dired-directory)))
                   (if (listp dir) (cdr dir)
                     (directory-files f t dired-re-no-dot))))))

;; (dired '("~/" "~/.emacs.d/.emacs-custom.el" "~/.emacs.d/.emacs.bmk"))

(defclass helm-files-dired-source (helm-source-sync helm-type-file)
  ((candidates :initform #'helm-files-in-all-dired-candidates)))

(defvar helm-source-files-in-all-dired
  (helm-make-source "Files in all dired buffer." 'helm-files-dired-source))

;;; session.el files
;;
;;  session (http://emacs-session.sourceforge.net/) is an alternative to
;;  recentf that saves recent file history and much more.
(defvar session-file-alist)
(defclass helm-source-session-class (helm-source-sync)
  ((candidates :initform (lambda ()
                           (cl-delete-if-not
                            (lambda (f)
                              (or (string-match helm-tramp-file-name-regexp f)
                                  (file-exists-p f)))
                            (mapcar 'car session-file-alist))))
   (keymap       :initform helm-generic-files-map)
   (help-message :initform helm-generic-file-help-message)
   (action       :initform 'helm-type-file-actions)))

(defvar helm-source-session nil
  "File list from emacs-session.")

(defcustom helm-session-fuzzy-match nil
  "Enable fuzzy matching in `helm-source-session' when non--nil."
  :group 'helm-files
  :type 'boolean
  :set (lambda (var val)
         (set var val)
         (setq helm-source-session
               (helm-make-source "Session" 'helm-source-session-class
                 :fuzzy-match val))))


;;; External searching file tools.
;;
;; Tracker desktop search

(defun helm-source-tracker-transformer (candidates _source)
  "Return file names from tracker CANDIDATES."
  ;; loop through tracker candidates selecting out file:// lines
  ;; then select part after file:// and url decode to get straight filenames
  (cl-loop for cand in candidates
           when (and (stringp cand)
                     (string-match "\\`[[:space:]]*file://\\(.*\\)" cand))
           collect (url-unhex-string (match-string 1 cand))))

(defvar helm-source-tracker-search
  (helm-build-async-source "Tracker Search"
    :candidates-process
     (lambda ()
       ;; the tracker-search command has been deprecated, now invoke via tracker
       ;; also, disable the contextual snippets which we don't currently use
       (start-process "tracker-search-process" nil
                      "tracker" "search"
                      "--disable-snippets"
                      "--disable-color"
                      "--limit=512"
                      helm-pattern))
    ;; new simplified transformer of tracker search results
    :filtered-candidate-transformer #'helm-source-tracker-transformer
    ;;(multiline) ; https://github.com/emacs-helm/helm/issues/529
    :keymap helm-generic-files-map
    :action 'helm-type-file-actions
    :action-transformer '(helm-transform-file-load-el
                          helm-transform-file-browse-url)
    :requires-pattern 3)
  "Source for retrieving files matching the current input pattern \
with the tracker desktop search.")

;; Spotlight (MacOS X desktop search)
(defclass helm-mac-spotlight-source (helm-source-async helm-type-file)
  ((candidates-process :initform
                       (lambda ()
                         (start-process
                          "mdfind-process" nil "mdfind" helm-pattern)))
   (requires-pattern :initform 3)))

(defvar helm-source-mac-spotlight
  (helm-make-source "mdfind" 'helm-mac-spotlight-source)
  "Source for retrieving files via Spotlight's command line utility mdfind.")

(provide 'helm-x-files)

;; Local Variables:
;; byte-compile-warnings: (not obsolete)
;; coding: utf-8
;; indent-tabs-mode: nil
;; End:

;;; helm-x-files.el ends here