Skip to content

Instantly share code, notes, and snippets.

@hirofumi
Last active August 29, 2015 14:16
Show Gist options
  • Save hirofumi/6d74e57b5b089d5efffd to your computer and use it in GitHub Desktop.
Save hirofumi/6d74e57b5b089d5efffd to your computer and use it in GitHub Desktop.
;; based on https://github.com/emacs-jp/migemo
(defun ag-migemo (regexp directory)
"Search using ag in a given DIRECTORY for a given migemo-ized REGEXP."
(interactive (list (read-from-minibuffer "[MIGEMO] Search regexp: " "")
(read-directory-name "Directory: ")))
(let* ((ag-highlight-search nil)
(ag-arguments (list "--line-number" "--ignore-case" "--nogroup" "--column" "--"))
(buffer (get-buffer-create " *ag-migemo*"))
(process (start-process "ag-migemo" buffer migemo-command "-q" "-d" migemo-dictionary))
(pattern (with-current-buffer (process-buffer process)
(set-process-query-on-exit-flag process nil)
(delete-region (point-min) (point-max))
(process-send-string process (concat regexp "\n"))
(while (not (and (> (point-max) 1)
(eq (char-after (1- (point-max))) ?\n)))
(accept-process-output process 0 migemo-accept-process-output-timeout-msec))
(buffer-substring (point-min) (1- (point-max))))))
(ag/search pattern directory :regexp t)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment