Skip to content

Commit

Permalink
add php support closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktasia committed Feb 10, 2016
1 parent 13a2d12 commit acd62d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 18 additions & 3 deletions dumb-jump.el
Expand Up @@ -119,6 +119,14 @@
:regex "class\\s*JJJ\\s*\\\(?"
:tests ("class test(object):"))

;; php
(:type "function" :language "php"
:regex "function\\s*JJJ\\s*\\\("
:tests ("function test()" "function test ()"))
(:type "variable" :language "php"
:regex "JJJ\\s*=\\s*"
:tests ("$test = 1234"))

;; go
(:type "variable" :language "go"
:regex "\\s*\\bJJJ\\s*=\\s*" :tests ("test = 1234"))
Expand Down Expand Up @@ -165,6 +173,8 @@ and type to use for generating the grep command"
(:language "javascript" :ext "js")
(:language "javascript" :ext "jsx")
(:language "javascript" :ext "html")
(:language "php" :ext "php")
(:language "php" :ext "inc")
(:language "python" :ext "py")
(:language "go" :ext "go"))
"Mapping of programming lanaguage(s) to file extensions"
Expand Down Expand Up @@ -561,9 +571,14 @@ denoter file/dir is found or uses dumb-jump-default-profile"
;(dumb-jump-message-prin1 "raw:%s\n ctx-ruls:%s\n rules:%s\n regexes:%s\n" raw-rules ctx-rules rules regexes)
regexes))

(defun dumb-jump-populate-regexes (look-for regexes)
(-map (lambda (x)
(s-replace "JJJ" (regexp-quote look-for) x))
regexes))

(defun dumb-jump-generate-ag-command (look-for cur-file proj regexes lang exclude-paths)
"Generate the grep response based on the needle LOOK-FOR in the directory PROJ"
(let* ((filled-regexes (-map (lambda (x) (s-replace "JJJ" look-for x)) regexes))
(let* ((filled-regexes (dumb-jump-populate-regexes look-for regexes))
(cmd (concat dumb-jump-ag-cmd " --vimgrep" (if (s-ends-with? ".gz" cur-file)
" --search-zip"
"")))
Expand All @@ -575,8 +590,8 @@ denoter file/dir is found or uses dumb-jump-default-profile"

(defun dumb-jump-generate-grep-command (look-for cur-file proj regexes lang exclude-paths)
"Generate the grep response based on the needle LOOK-FOR in the directory PROJ"
(let* ((filled-regexes (-map (lambda (x) (s-replace "JJJ" look-for x))
(-map (lambda (r) (format "'%s'" r)) regexes)))
(let* ((filled-regexes (-map (lambda (r) (format "'%s'" r))
(dumb-jump-populate-regexes look-for regexes)))
(cmd (concat dumb-jump-grep-prefix " " (if (s-ends-with? ".gz" cur-file)
dumb-jump-zgrep-cmd
dumb-jump-grep-cmd)))
Expand Down
6 changes: 5 additions & 1 deletion test/dumb-jump-test.el
Expand Up @@ -322,7 +322,11 @@
(let ((result '(:path "src/file.js" :line 62 :context "var isNow = true" :diff 7 :target "isNow")))
(dumb-jump-result-follow result))))

(ert-deftest dumb-jump-dumb-jump-message-prin1-test ()
(ert-deftest dumb-jump-populate-regexes-test ()
(should (equal (dumb-jump-populate-regexes "testvar" '("JJJ\\s*=\\s*")) '("testvar\\s*=\\s*")))
(should (equal (dumb-jump-populate-regexes "$testvar" '("JJJ\\s*=\\s*")) '("\\$testvar\\s*=\\s*"))))

(ert-deftest dumb-jump-message-prin1-test ()
(noflet ((message (input arg arg2)
(should (string= input "%s %s"))
(should (string= arg "(:path \"test\" :line 24)"))
Expand Down

0 comments on commit acd62d2

Please sign in to comment.