Created
January 7, 2016 21:32
-
-
Save PythonNut/b800d3e4dad022658c1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my/helm-elscreen-find-file-or-marked (candidate) | |
"Open file CANDIDATE or open helm marked files with elscreen. | |
Called with a prefix arg open files in background without selecting them." | |
(let ((marked (helm-marked-candidates :with-wildcard t)) | |
(url-p (and ffap-url-regexp ; we should have only one candidate. | |
(string-match ffap-url-regexp candidate))) | |
(ffap-newfile-prompt helm-ff-newfile-prompt-p) | |
(find-file-wildcards nil) | |
(make-dir-fn | |
(lambda (dir &optional helm-ff) | |
(when (or (not confirm-nonexistent-file-or-buffer) | |
(y-or-n-p (format "Create directory `%s'? " dir))) | |
(let ((dirfname (directory-file-name dir))) | |
(if (file-exists-p dirfname) | |
(error | |
"Mkdir: Unable to create directory `%s': file exists." | |
(helm-basename dirfname)) | |
(make-directory dir 'parent))) | |
(when helm-ff | |
;; Allow having this new dir in history | |
;; to be able to retrieve it immediately | |
;; if we want to e.g copy a file from somewhere in it. | |
(setq helm-ff-default-directory | |
(file-name-as-directory dir)) | |
(push helm-ff-default-directory helm-ff-history)) | |
(or (and helm-ff (helm-find-files-1 dir)) t)))) | |
(helm--reading-passwd-or-string t)) | |
(if (cdr marked) | |
(if helm-current-prefix-arg | |
(dired-simultaneous-find-file marked nil) | |
(mapc 'elscreen-find-file (cdr marked)) | |
(elscreen-find-file (car marked))) | |
(if (and (not (file-exists-p candidate)) | |
(not url-p) | |
(string-match "/$" candidate)) | |
;; A a non--existing filename ending with / | |
;; Create a directory and jump to it. | |
(funcall make-dir-fn candidate 'helm-ff) | |
;; A non--existing filename NOT ending with / or | |
;; an existing filename, create or jump to it. | |
;; If the basedir of candidate doesn't exists, | |
;; ask for creating it. | |
(let ((dir (and (not url-p) (helm-basedir candidate)))) | |
(elscreen-find-file | |
(cond ((and dir (file-directory-p dir)) | |
(substitute-in-file-name candidate)) | |
(url-p candidate) | |
((funcall make-dir-fn dir) candidate)))))))) | |
(defvar my/helm-source-projectile-elscreen-files-list | |
(helm-build-in-buffer-source "Projectile files" | |
:data (lambda () | |
(condition-case nil | |
(projectile-current-project-files) | |
(error nil))) | |
:fuzzy-match helm-projectile-fuzzy-match | |
:coerce 'helm-projectile-coerce-file | |
:keymap helm-projectile-find-file-map | |
:help-message 'helm-ff-help-message | |
:mode-line helm-read-file-name-mode-line-string | |
:action (cons my/helm-elscreen-find-file-or-marked | |
helm-projectile-file-actions)) | |
"Helm source definition for Projectile files.") | |
(helm-projectile-command "elscreen-find-file" 'my/helm-source-projectile-elscreen-files-list "Find file in projects (elscreen): " t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment