Created
June 8, 2012 05:26
-
-
Save yalab/2893762 to your computer and use it in GitHub Desktop.
anything-bzr-grep.el
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
(eval-when-compile (require 'cl)) | |
(require 'vc-bzr) | |
(provide 'anything-bzr-grep) | |
(defvar anything-c-source-bzr-grep-cache nil "path") | |
(setq bzr-command "/usr/local/bin/bzr") | |
(defun anything-bzr-grep-init () | |
(setq anything-c-source-bzr-grep-cache | |
(vc-bzr-root (if (buffer-file-name) | |
(file-name-directory (buffer-file-name)) | |
default-directory)))) | |
(defun anything-bzr-grep-process () | |
(if anything-c-source-bzr-grep-cache | |
(let ((default-directory anything-c-source-bzr-grep-cache)) | |
(apply 'start-process "bzr-grep-process" nil | |
bzr-command "grep" "-n" "--color=never" | |
(append | |
(split-string anything-pattern "[ \t]" t)))) | |
'())) | |
(defun anything-bzr-grep-transformer (cds source) | |
(mapcar (lambda (candidate) | |
(let ((list (split-string candidate ":"))) | |
(if (not (>= (length list) 3)) | |
candidate | |
(let ((file-name (first list)) | |
(line-number (second list)) | |
(line (apply 'concat (cddr list)))) | |
(cons (format "%s:%s:\n %s" file-name line-number line) | |
candidate))))) | |
cds)) | |
(defun anything-bzr-grep-goto (candidate) | |
(let ((list (split-string candidate ":"))) | |
(when (>= (length list) 3) | |
(let ((top-dir anything-c-source-bzr-grep-cache) | |
(file-name (first list)) | |
(line-number (second list))) | |
(find-file (file-truename (expand-file-name file-name top-dir)) top-dir) | |
(goto-line (string-to-number line-number)))))) | |
(defvar anything-c-source-bzr-grep | |
'((name . "Bzr Grep") | |
(multiline) | |
(init . anything-bzr-grep-init) | |
(candidates . anything-bzr-grep-process) | |
(filtered-candidate-transformer anything-bzr-grep-transformer) | |
(action . (("Bzr Grep Goto " . anything-bzr-grep-goto))) | |
(candidate-number-limit . 300) | |
(requires-pattern . 3) | |
(volatile) | |
(delayed))) | |
(defun anything-bzr-grep () | |
"Anything Bzr Grep" | |
(interactive) | |
(anything-other-buffer 'anything-c-source-bzr-grep "*anything bzr grep*")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment