Skip to content

Instantly share code, notes, and snippets.

@syohex
Created December 3, 2012 14:05
Show Gist options
  • Select an option

  • Save syohex/4195240 to your computer and use it in GitHub Desktop.

Select an option

Save syohex/4195240 to your computer and use it in GitHub Desktop.
initial implementation helm-silver-searcher
;;; helm-silver-searcher.el ---
;; Copyright (C) 2012 by Syohei YOSHIDA
;; Author: Syohei YOSHIDA <[email protected]>
;; URL:
;; Version: 0.01
;; 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:
(eval-when-compile
(require 'cl))
(require 'helm)
(defgroup helm-silver-searcher nil
"Ag(Silver Searcher) command with helm interface"
:group 'helm)
(defcustom helm-c-silver-searcher:command "ag"
"Base command of `ag'"
:type 'string
:group 'helm-silver-searcher)
(defcustom helm-c-silver-searcher:option "--nocolor --nogroup "
"Base option with `ag' command"
:type 'string
:group 'helm-silver-searcher)
(defun helm-c-silver-searcher:init-command ()
(format "%s %s "
helm-c-silver-searcher:command
helm-c-silver-searcher:option))
(defun helm-c-silver-searcher-init ()
(let ((cmd (read-string "Command: " (helm-c-silver-searcher:init-command))))
(helm-attrset 'recenter t)
(with-current-buffer (helm-candidate-buffer 'global)
(setq tmstms cmd)
(let ((ret (call-process-shell-command cmd nil t nil)))
(cond ((= ret 1) (error "no match"))
((not (= ret 0)) (error "Failed 'ag' command")))))))
(defvar helm-c-silver-searcher-source
'((name . "helm silver searcher")
(init . helm-c-silver-searcher-init)
(candidates-in-buffer)
(type . file-line)
(candidate-number-limit . 9999)))
;;;###autoload
(defun helm-silver-searcher ()
(interactive)
(let ((buf (get-buffer-create "*helm ag*")))
(helm :sources '(helm-c-silver-searcher-source) :buffer buf)))
(provide 'helm-silver-searcher)
;;; helm-silver-searcher.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment