Skip to content

Instantly share code, notes, and snippets.

@alterakey
Created September 9, 2011 17:31
Show Gist options
  • Save alterakey/1206826 to your computer and use it in GitHub Desktop.
Save alterakey/1206826 to your computer and use it in GitHub Desktop.
grepper.el: named grep
;; grepper: grep + named location + per-name pattern.
;;
;; Configuration:
;; (setq grepper-command-line-alist '(("pil" . "grep -niEHR '_re_' ~/ve/proj/lib/python2*/site-packages/PIL*")))
(defun grepper-grep-by-name (&optional query place)
(interactive)
(if (not place)
(setq place (completing-read "grep on: " grepper-command-line-alist nil t)))
(if (not query)
(setq query (read-from-minibuffer (replace-regexp-in-string "_place_" place "query on _place_: ") nil nil nil nil (current-word))))
(if (string= "" query)
(error "Cowardly refusing to execute an empty query"))
(let ((command-line (cdr (assoc place grepper-command-line-alist)))
(buffer-path (format "`dirname '%s'`" (buffer-file-name (current-buffer)))))
(setq command-line
(replace-regexp-in-string "_buffer_path_" buffer-path command-line t t))
(setq command-line
(replace-regexp-in-string "_re_" query command-line t t))
(grep command-line)))
(provide 'grepper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment