 (use-package highlight-thing :ensure t)
 (global-highlight-thing-mode)
 
-(defun ar/grep (pattern filename-pattern search-paths)
+(defun ar/spc-join (strings)
+  "Join strings in STRINGS with spaces."
+  (mapconcat 'identity strings " "))
+
+(defun ar/grep (regexp filename-pattern &rest search-paths)
   "Grep for PATTERN and narrow to FILENAME-PATTERN and SEARCH-PATHS."
-  (let* ((search-paths-string (mapconcat 'identity search-paths " "))
-         (command (format (concat "grep "
-                                  "--binary-file=without-match "
-                                  "--recursive "
-                                  "--no-filename "
-                                  "--regexp=%s "
-                                  "--include %s "
-                                  " %s")
-                          pattern
+  (let* ((grep-command (format (ar/spc-join '("grep"
+                                              "--binary-file=without-match"
+                                              "--recursive"
+                                              "--no-filename"
+                                              "--regexp=%s"
+                                              "--include %s"
+                                              "%s"))
+                          regexp
                           filename-pattern
-                          search-paths-string)))
-    (split-string (shell-command-to-string command) "\n")))
-
-(defun ar/find (filename-pattern search-paths)
+                          (ar/spc-join search-paths))))
+    (split-string (shell-command-to-string grep-command) "\n")))
+
+(defun ar/find (filename-pattern &rest search-paths)
   "Find file with FILENAME-PATTERN and SEARCH-PATHS."
   (let* ((search-paths-string (mapconcat 'identity search-paths " "))
          (find-command (format "find %s -iname %s"

;;         'string<)
;;   (lambda (selection)
;;     (insert selection)))

;; (defc ar/insert-objc-import
;;   "My ObjC imports"
;;   (sort (delete-dups (ar/find-instances "^import"
;;                                         "\\*.java"
;;                                         '("root/to/objc/source")))
;;         'string<)
;;   (lambda (selection)
;;     (insert selection)))

                               filename-pattern)))
    (split-string (shell-command-to-string find-command) "\n")))

(defun ar/helm (title candidates on-select-function)
  (helm :sources `((name . ,title)
                   (candidates . ,candidates)
                   (action . ,on-select-function))
        :buffer "*helm-exec*"
        :candidate-number-limit 10000))

(defun ar/helm-sample-command ()
  "Dummy helm sample command."
  (interactive)
  (ar/helm "My Options"
           '("option 1"
             "option 2"
             "option 3")
           (lambda (selection)
             (message "selected: %s" selection))))

(defmacro defhelm (name title candidates on-select-function)
  "Create a helm command with NAME, source TITLE, CANDIDATES list and
ON-SELECT-FUNCTION."
  `(defun ,name ()
     (interactive)
     (ar/helm ,title
              ,candidates
              ,(lambda (selection)
                 (message "selected: %s" selection)))))

;; defhelm examples:
;;
;; (defhelm ar/insert-java-import
;;   "My Java imports"
;;   (sort (delete-dups (ar/grep "^import"
;;                               "\\*.java"
