Skip to content

Commit

Permalink
Merge branch 'pr28'
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuyk committed Nov 12, 2016
2 parents b0bb524 + 8f2d328 commit 6b5abd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
32 changes: 12 additions & 20 deletions helm-git-grep.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ If you don't want to search in submodules, \
Set only `helm-git-grep-source' like this:
(setq helm-git-grep-sources '(helm-git-grep-source))"
:group 'helm-gi-grep
:group 'helm-git-grep
:type '(repeat (choice symbol)))

(defcustom helm-git-grep-candidate-number-limit 300
Expand Down Expand Up @@ -250,7 +250,7 @@ newline return an empty string."
"Create arguments of `helm-git-grep-process' in `helm-git-grep'."
(delq nil
(append
(list "--no-pager" "grep" "-n" "--no-color"
(list "--no-pager" "grep" "--null" "-n" "--no-color"
(if helm-git-grep-ignore-case "-i" nil)
(helm-git-grep-showing-leading-and-trailing-lines-option))
(nbutlast
Expand Down Expand Up @@ -398,19 +398,12 @@ Argument SOURCE is not used."
candidates)))

(defun helm-git-grep-filtered-candidate-transformer-display
(filename separator lineno content)
"Propertize FILENAME SEPARATOR LINENO CONTENT and concatenate them."
(let ((colonp (string= separator ":")))
(format "%s%s%s%s%s"
(if colonp
(propertize filename 'face 'helm-git-grep-file)
filename)
separator
(if colonp
(propertize lineno 'face 'helm-git-grep-line)
lineno)
separator
(helm-git-grep-highlight-match content))))
(filename lineno content)
"Propertize FILENAME LINENO CONTENT and concatenate them."
(format "%s:%s:%s"
(propertize filename 'face 'helm-git-grep-file)
(propertize lineno 'face 'helm-git-grep-line)
(helm-git-grep-highlight-match content)))

(defun helm-git-grep-highlight-match (content)
"Highlight matched text with `helm-git-grep-match' face in CONTENT."
Expand All @@ -422,13 +415,12 @@ Argument SOURCE is not used."

(defun helm-git-grep-filtered-candidate-transformer-file-line-1 (candidate)
"Transform CANDIDATE to `helm-git-grep-mode' format."
(when (string-match "^\\(.+?\\)\\([:\\-]\\)\\([0-9]+\\)[:\\-]\\(.*\\)$" candidate)
(when (string-match "^\\(.+\\)\x00\\([0-9]+\\)\x00\\(.*\\)$" candidate)
(let ((filename (match-string 1 candidate))
(separator (match-string 2 candidate))
(lineno (match-string 3 candidate))
(content (match-string 4 candidate)))
(lineno (match-string 2 candidate))
(content (match-string 3 candidate)))
(cons (helm-git-grep-filtered-candidate-transformer-display
filename separator lineno content)
filename lineno content)
(list (string-to-number lineno) content
(expand-file-name
filename
Expand Down
8 changes: 4 additions & 4 deletions test/helm-git-grep-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,25 @@
(helm-pattern "defun helm git")
(helm-git-grep-pathspecs nil))
(should-equal? (helm-git-grep-args)
'("--no-pager" "grep" "-n" "--no-color" "-i"
'("--no-pager" "grep" "--null" "-n" "--no-color" "-i"
"-e" "defun" "--and" "-e" "helm" "--and" "-e" "git")))
(let ((helm-git-grep-ignore-case nil)
(helm-pattern "helm")
(helm-git-grep-pathspecs nil))
(should-equal? (helm-git-grep-args)
'("--no-pager" "grep" "-n" "--no-color" "-e" "helm")))
'("--no-pager" "grep" "--null" "-n" "--no-color" "-e" "helm")))
(let ((helm-git-grep-ignore-case nil)
(helm-pattern "helm")
(helm-git-grep-pathspecs '("./*" ":!test/**")))
(should-equal? (helm-git-grep-args)
'("--no-pager" "grep" "-n" "--no-color" "-e" "helm"
'("--no-pager" "grep" "--null" "-n" "--no-color" "-e" "helm"
"--" "./*" ":!test/**")))
(let ((helm-git-grep-ignore-case nil)
(helm-pattern "helm")
(helm-git-grep-pathspecs '("./*" ":!test/**"))
(helm-git-grep-pathspec-available nil))
(should-equal? (helm-git-grep-args)
'("--no-pager" "grep" "-n" "--no-color" "-e" "helm"))))
'("--no-pager" "grep" "--null" "-n" "--no-color" "-e" "helm"))))

(ert-deftest test/helm-git-grep-highlight-match ()
(let* ((helm-input "defun")
Expand Down

0 comments on commit 6b5abd4

Please sign in to comment.