Implement my own simple helm-find-files

f:id:syohex:20150715144102p:plain

helm-find-files is useful command for opening files in current directory. However I have some complaints for it. - I want to see only files, not directories(., .. etc). - I don't want to open binary files - I use only some actions(open file, open file in other window, insert file)

Here is code. To collect files is following step - Collect all files/directory in current directory by glob('* .*') - filter them by -T file flag - -T file flag returns true if argument is text file.

(defun my/helm-find-files-init ()
  (with-current-buffer (helm-candidate-buffer 'global)
    (unless (zerop (process-file "perl" nil t nil "-wE" "say for grep {-T $_} glob('* .*')"))
      (error "Failed: collect files"))))

(defvar my/helm-source-find-files
  (helm-build-in-buffer-source "Find Files"
    :init 'my/helm-find-files-init
    :action '(("Find File" . find-file)
              ("Find File other window" . find-file-other-window)
              ("Insert File" . insert-file))))

(defun my/helm-find-files ()
  (interactive)
  (helm :sources '(my/helm-source-find-files) :buffer "*Helm Find Files*"))

This is a little slow because Perl is not so fast language :-(