Search code examples
searchemacsemacs-helm

Search in current folder with helm-do-grep


I have so small problem about in Emacs. I bind helm-do-grep command for Emacs. It's really useful.

I want to search something in current folder. I searched some codes about that both of them are working but I don't have ability to fix them like what I want.

If you fix them for me I'll be happy thank you.

(defvar my/book-notes-directory "~/Dropbox/books")
(defun my/helm-do-grep-book-notes ()
"Search my book notes."
(interactive)
(helm-do-grep-1 (list my/book-notes-directory)))


(defun my-dir-locals-dir ()
"Return the directory local variables directory.
Code taken from `hack-dir-local-variables'."
(let ((variables-file (dir-locals-find-file (or (buffer-file-name) default-directory)))
    (dir-name nil))
(cond,
 ((stringp variables-file)
  (setq dir-name (file-name-directory variables-file)))
 ((consp variables-file)
  (setq dir-name (nth 0 variables-file))))
dir-name))

Solution

  • How about something like this?

    (defun my/helm-do-grep-current-directory-tree ()
      "Recursively search current directory.
    If a parent directory has a `dir-locals-file', use that as the
    root instead."
      (interactive)
      (let ((variables-file (dir-locals-find-file
                             (or (buffer-file-name) default-directory))))
        (helm-do-grep-1
         (list
          (cond
           ((stringp variables-file)
            (file-name-directory variables-file))
           ((consp variables-file)
            (nth 0 variables-file))
           (t default-directory)))
         t nil '("*"))))
    

    By the way, if you ask on http://emacs.stackexchange.com , you might get better answers. (And faster, too!) =)