                           (anything-kill-buffers)
                           )))))
    nil nil))
+
+;;; Regexp
+(defun anything-query-replace-regexp (&rest args)
+  "Drop-in replacement of `query-replace-regexp' with building regexp visually."
+  (interactive
+   (or (anything-c-regexp-base "Query Replace Regexp: "
+                               '((name . "Lines matching Regexp")
+                                 (action . anything-c-query-replace-args)))
+       (keyboard-quit)))
+  (apply 'query-replace-regexp args))
+
+(defun anything-regexp ()
+  "It is like `re-builder'. It helps buliding regexp and replacement."
+  (interactive)
+  (anything-c-regexp-base
+   "Regexp: "
+   '((name . "Regexp Builder")
+     (action
+      ("Kill Regexp as sexp" .
+       (lambda (x) (anything-c-regexp-kill-new (prin1-to-string anything-input))))
+      ("Query Replace Regexp" .
+       (lambda (x) (apply 'query-replace-regexp (anything-c-query-replace-args))))
+      ("Kill Regexp" .
+       (lambda (x) (anything-c-regexp-kill-new anything-input)))))))
+
+(defun anything-c-query-replace-args (start-point)
+  ;; create arguments of `query-replace-regexp'.
+  (let ((region-only (and transient-mark-mode mark-active)))
+    (list
+     anything-input
+     (read-string (format "Query replace regexp %s%s%s with: "
+                          (if region-only "in region " "")
+                          anything-input
+                          (if current-prefix-arg "(word) " "")))
+     current-prefix-arg
+     (if region-only
+         (region-beginning)
+       start-point)
+     (if region-only
+         (region-end)
+       (point-max)))))
+
+(defun anything-c-regexp-get-line (s e)
+  (propertize
+   (apply 'concat
+          ;; Line contents
+          (format "%5d: %s" (line-number-at-pos s) (buffer-substring s e))
+          ;; subexps
+          (loop for i from 0 to (1- (/ (length (match-data)) 2))
+                unless (zerop i)
+                collect (format "\n         $%d = %s"
+                                i (match-string i))))
+   ;; match beginning
+   'anything-realvalue s))
+
+(defun anything-c-regexp-persistent-action (txt)
+  (goto-line (anything-aif (string-match "^ *\\([0-9]+\\)" txt)
+                 (string-to-number (match-string 1 txt)))))
+
+(defun anything-c-regexp-base (prompt attributes)
+  (save-restriction
+    (let ((anything-compile-source-functions
+           ;; rule out anything-match-plugin because the input is one regexp.
+           (delq 'anything-compile-source--match-plugin
+                 (copy-sequence anything-compile-source-functions))))
+      (if (and transient-mark-mode mark-active)
+          (narrow-to-region (region-beginning) (region-end)))
+      (anything
+       (list
+        (append
+         '((init . (lambda () (anything-candidate-buffer anything-current-buffer)))
+           (candidates-in-buffer)
+           (get-line . anything-c-regexp-get-line)
+           (persistent-action . anything-c-regexp-persistent-action)
+           (multiline)
+           (delayed))
+         attributes))
+       nil prompt nil nil "*anything regexp*"))))
+
+(defun anything-c-regexp-kill-new (input)
+  (kill-new input)
+  (message "Killed: %s" input))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 

  (interactive)
  (anything 'anything-c-source-minibuffer-history nil nil nil nil
            "*anything minibuffer-history*"))
;; (define-key minibuffer-local-map "\C-r" 'anything-minibuffer-history)
;; (define-key minibuffer-local-completion-map "\C-r" 'anything-minibuffer-history)

(defun anything-gentoo ()
  "Start anything with only gentoo sources."

;; Minibuffer History
(defvar anything-c-source-minibuffer-history
  '((name . "Minibuffer History")
    (header-name . (lambda (name) (format "%s (%s)" name minibuffer-history-variable)))
    (candidates . (lambda () (symbol-value minibuffer-history-variable)))
    (migemo)
    (action . insert)))

