Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Common Lisp support #457

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 79 additions & 10 deletions dumb-jump.el
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,61 @@ or most optimal searcher."

;; common lisp
(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
:regex "\\\(defun\\s+JJJ\\j"
:regex "\\\(def(un|macro|generic|method|setf)\\s+JJJ\\j"
;; \\j usage see `dumb-jump-ag-word-boundary`
:tests ("(defun test (blah)" "(defun test\n")
:tests ("(defun test (blah)" "(defun test\n"
"(defmacro test (blah)" "(defmacro test\n"
"(defgeneric test (blah)" "(defgeneric test\n"
"(defmethod test (blah)" "(defmethod test\n"
"(defsetf test (blah)" "(defsetf test\n")
:not ("(defun test-asdf (blah)" "(defun test-blah\n"
"(defun tester (blah)" "(defun test? (blah)" "(defun test- (blah)"))
"(defun tester (blah)" "(defun test? (blah)" "(defun test- (blah)"
"(defmacro test-asdf (blah)" "(defmacro test-blah\n"
"(defmacro tester (blah)" "(defmacro test? (blah)" "(defmacro test- (blah)"
"(defgeneric test-asdf (blah)" "(defgeneric test-blah\n"
"(defgeneric tester (blah)" "(defgeneric test? (blah)" "(defun test- (blah)"
"(defmethod test-asdf (blah)" "(defmethod test-blah\n"
"(defmethod tester (blah)" "(defmethod test? (blah)" "(defun test- (blah)"
"(defsetf test-asdf (blah)" "(defsetf test-blah\n"
"(defsetf tester (blah)" "(defsetf test? (blah)" "(defun test- (blah)"))

(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
:regex "\\\(define-(modify-macro|compiler-macro|setf-expander)\\s+JJJ\\j"
;; \\j usage see `dumb-jump-ag-word-boundary`
:tests ("(define-modify-macro test (blah)" "(define-modify-macro test\n"
"(define-compiler-macro test (blah)" "(define-compiler-macro test\n")
:not ("(define-modify-macro test-asdf (blah)" "(define-modify-macro test-blah\n"
"(define-modify-macro tester (blah)" "(define-modify-macro test? (blah)" "(define-modify-macro test- (blah)"
"(define-compiler-macro test-asdf (blah)" "(define-compiler-macro test-blah\n"
"(define-compiler-macro tester (blah)" "(define-compiler-macro test? (blah)" "(define-compiler-macro test- (blah)"))

(:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
:regex "\\\(def(var|parameter|constant)\\b\\s*JJJ\\j"
:tests ("(defvar test " "(defvar test\n"
"(defparameter test " "(defparameter test\n"
"(defconstant test " "(defconstant test\n")
:not ("(defvar tester" "(defvar test?" "(defvar test-"
"(defparameter tester" "(defparameter test?" "(defparameter test-"
"(defconstant tester" "(defconstant test?" "(defconstant test-"))

(:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
:regex "\\\(defparameter\\b\\s*JJJ\\j"
:tests ("(defparameter test " "(defparameter test\n")
:not ("(defparameter tester" "(defparameter test?" "(defparameter test-"))
:regex "\\\(define-symbol-macro\\b\\s*JJJ\\j"
:tests ("(define-symbol-macro test " "(define-symbol-macro test\n")
:not ("(define-symbol-macro tester" "(define-symbol-macro test?" "(define-symbol-macro test-"))

(:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
:regex "\\\(def(class|struct|type)\\b\\s*JJJ\\j"
:tests ("(defclass test " "(defclass test\n"
"(defstruct test " "(defstruct test\n"
"(deftype test " "(deftype test\n")
:not ("(defclass tester" "(defclass test?" "(defclass test-"
"(defstruct tester" "(defstruct test?" "(defstruct test-"
"(deftype tester" "(deftype test?" "(deftype test-"))

(:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
:regex "\\\(define-condition\\b\\s*JJJ\\j"
:tests ("(define-condition test " "(deftype test\n")
:not ("(define-condition tester" "(deftype test?" "(deftype test-"))

;; racket
(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
Expand Down Expand Up @@ -2147,6 +2192,8 @@ to keep looking for another root."
(defun dumb-jump-process-symbol-by-lang (lang look-for)
"Process LANG's LOOK-FOR. For instance, clojure needs namespace part removed."
(cond
((and (string= lang "commonlisp") (s-contains? ":" look-for) (not (s-starts-with? ":" look-for)))
(nth 1 (s-split ":" look-for 'omit-nulls)))
((and (string= lang "clojure") (s-contains? "/" look-for))
(nth 1 (s-split "/" look-for)))
((and (string= lang "fennel") (s-contains? "." look-for))
Expand Down Expand Up @@ -2700,6 +2747,9 @@ searcher symbol."
(t
shell-command-switch))))

(defconst dumb-jump--case-insensitive-languages
'("commonlisp"))

;; TODO: rename dumb-jump-run-definition-command
(defun dumb-jump-run-command
(look-for proj regexes lang exclude-args cur-file line-num parse-fn generate-fn)
Expand All @@ -2719,8 +2769,9 @@ searcher symbol."
(setq rawresults (shell-command-to-string cmd))
(dumb-jump-debug-message cmd rawresults))
(unless (s-blank? cmd)
(let ((results (funcall parse-fn rawresults cur-file line-num)))
(--filter (s-contains? look-for (plist-get it :context)) results)))))
(let ((results (funcall parse-fn rawresults cur-file line-num))
(ignore-case (member lang dumb-jump--case-insensitive-languages)))
(--filter (s-contains? look-for (plist-get it :context) ignore-case) results)))))

(defun dumb-jump-parse-response-line (resp-line cur-file)
"Parse a search program's single RESP-LINE for CUR-FILE into a list of (path line context)."
Expand Down Expand Up @@ -2868,6 +2919,9 @@ searcher symbol."
;; TODO: --search-zip always? in case the include is the in gz area like emacs lisp code.
(cmd (concat dumb-jump-ag-cmd
" --nocolor --nogroup"
(if (member lang dumb-jump--case-insensitive-languages)
" --ignore-case"
"")
(if (s-ends-with? ".gz" cur-file)
" --search-zip"
"")
Expand Down Expand Up @@ -2915,6 +2969,9 @@ Using ag to search only the files found via git-grep literal symbol search."
(ag-files-arg (dumb-jump-get-git-grep-files-matching-symbol-as-ag-arg look-for proj-dir))
(cmd (concat dumb-jump-ag-cmd
" --nocolor --nogroup"
(if (member lang dumb-jump--case-insensitive-languages)
" --ignore-case"
"")
(if (s-ends-with? ".gz" cur-file)
" --search-zip"
"")
Expand All @@ -2934,6 +2991,9 @@ Using ag to search only the files found via git-grep literal symbol search."
(proj-dir (file-name-as-directory proj))
(cmd (concat dumb-jump-rg-cmd
" --color never --no-heading --line-number -U"
(if (member lang dumb-jump--case-insensitive-languages)
" --ignore-case"
"")
(when (not (s-blank? dumb-jump-rg-search-args))
(concat " " dumb-jump-rg-search-args))
(s-join "" (--map (format " --type %s" it) rgtypes))))
Expand All @@ -2950,6 +3010,9 @@ Using ag to search only the files found via git-grep literal symbol search."
(ggtypes (when (file-name-extension cur-file) (dumb-jump-get-git-grep-type-by-language lang)))
(cmd (concat dumb-jump-git-grep-cmd
" --color=never --line-number"
(if (member lang dumb-jump--case-insensitive-languages)
" --ignore-case"
"")
(when dumb-jump-git-grep-search-untracked
" --untracked")
(when (not (s-blank? dumb-jump-git-grep-search-args))
Expand All @@ -2972,12 +3035,15 @@ Using ag to search only the files found via git-grep literal symbol search."
(if (s-ends-with? ".gz" cur-file)
dumb-jump-zgrep-cmd
dumb-jump-grep-cmd)))
(case-args (if (member lang dumb-jump--case-insensitive-languages)
" --ignore-case"
""))
(exclude-args (dumb-jump-arg-joiner "--exclude-dir" exclude-paths))
(include-args (dumb-jump-get-ext-includes lang))
(regex-args (dumb-jump-arg-joiner "-e" filled-regexes)))
(if (= (length regexes) 0)
""
(dumb-jump-concat-command cmd dumb-jump-grep-args exclude-args include-args regex-args proj))))
(dumb-jump-concat-command cmd dumb-jump-grep-args case-args exclude-args include-args regex-args proj))))

(defun dumb-jump-generate-gnu-grep-command (look-for cur-file proj regexes _lang _exclude-paths)
"Find LOOK-FOR's CUR-FILE in the PROJ with REGEXES for the LANG but not in EXCLUDE-PATHS."
Expand All @@ -2987,13 +3053,16 @@ Using ag to search only the files found via git-grep literal symbol search."
(if (s-ends-with? ".gz" cur-file)
dumb-jump-zgrep-cmd
dumb-jump-grep-cmd)))
(case-args (if (member lang dumb-jump--case-insensitive-languages)
" --ignore-case"
""))
;; TODO: GNU grep doesn't support these, so skip them
(exclude-args "")
(include-args "")
(regex-args (dumb-jump-arg-joiner "-e" filled-regexes)))
(if (= (length regexes) 0)
""
(dumb-jump-concat-command cmd dumb-jump-gnu-grep-args exclude-args include-args regex-args proj))))
(dumb-jump-concat-command cmd dumb-jump-gnu-grep-args case-args exclude-args include-args regex-args proj))))

(defun dumb-jump-concat-command (&rest parts)
"Concat the PARTS of a command if each part has a length."
Expand Down