Created
February 13, 2015 14:44
-
-
Save david-christiansen/2ba5e03910666ae27203 to your computer and use it in GitHub Desktop.
Helm datasource for my stuff, inspired by http://kitchingroup.cheme.cmu.edu/blog/2015/02/04/Helm-at-the-Emacs/
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
;;; Helm support for finding my stuff | |
(defvar helm-david-christiansen-git-repo-list nil | |
"The Git repos found for my Helm launcher.") | |
(defvar helm-david-christiansen-git-repo-finder-process nil | |
"The process finding Git repos for my Helm launcher.") | |
(defun helm-david-christiansen-git-repo-finder-output-filter (proc string) | |
(when (buffer-live-p (process-buffer proc)) | |
(with-current-buffer (process-buffer proc) | |
(let ((moving (= (point) (process-mark proc)))) | |
(save-excursion | |
;; Insert the text, advancing the process marker. | |
(goto-char (process-mark proc)) | |
(insert string) | |
(set-marker (process-mark proc) (point))) | |
(if moving (goto-char (process-mark proc)))) | |
;; Move all *complete* lines to the list | |
(save-excursion | |
(goto-char (point-min)) | |
(while (search-forward ".git\n" nil t) | |
(let ((line (buffer-substring-no-properties (point-min) (- (point) 5)))) | |
(add-to-list 'helm-david-christiansen-git-repo-list line t) | |
(delete-region (point-min) (point)) | |
(goto-char (point-min)))))))) | |
(defun helm-david-christiansen-git-repos () | |
(cond (helm-david-christiansen-git-repo-list | |
helm-david-christiansen-git-repo-list) | |
;; Attempt to construct a list of Git repos | |
((null helm-david-christiansen-git-repo-finder-process) | |
(kill-buffer "*helm-david-christiansen-git-repo-finder-process*") | |
(let ((proc (start-process-shell-command | |
"helm-david-christiansen-git-repo-finder-process" | |
"*helm-david-christiansen-git-repo-finder-process*" | |
"find ~ -name .git"))) | |
(set-process-filter proc | |
#'helm-david-christiansen-git-repo-finder-output-filter) | |
(setq helm-david-christiansen-git-repo-finder-process proc) | |
(accept-process-output nil nil 200) | |
helm-david-christiansen-git-repo-list)) | |
(t ;; Process is running: return nil so far | |
nil))) | |
(defun helm-david-christiansen () | |
"Helm interface to David's stuff." | |
(interactive) | |
(helm :sources `(((name . "Handy") | |
(candidates . (("init.el" . "~/.emacs.d/init.el"))) | |
(action . (("Open" . find-file)))) | |
helm-source-recentf | |
((name . "Git repos") | |
(candidates . ,(helm-david-christiansen-git-repos)) | |
(action . (("Magit" . magit-status) | |
("Dired" . dired)))) | |
helm-source-bookmarks | |
helm-source-bookmark-set))) | |
(global-set-key (kbd "C-c d") #'helm-david-christiansen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment