Skip to content

Commit 737267a

Browse files
authored
Improved Common Lisp support (#457)
- Fixes #414
1 parent f657254 commit 737267a

File tree

1 file changed

+81
-12
lines changed

1 file changed

+81
-12
lines changed

dumb-jump.el

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,61 @@ or most optimal searcher."
291291

292292
;; common lisp
293293
(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
294-
:regex "\\\(defun\\s+JJJ\\j"
294+
:regex "\\\(def(un|macro|generic|method|setf)\\s+JJJ\\j"
295295
;; \\j usage see `dumb-jump-ag-word-boundary`
296-
:tests ("(defun test (blah)" "(defun test\n")
296+
:tests ("(defun test (blah)" "(defun test\n"
297+
"(defmacro test (blah)" "(defmacro test\n"
298+
"(defgeneric test (blah)" "(defgeneric test\n"
299+
"(defmethod test (blah)" "(defmethod test\n"
300+
"(defsetf test (blah)" "(defsetf test\n")
297301
:not ("(defun test-asdf (blah)" "(defun test-blah\n"
298-
"(defun tester (blah)" "(defun test? (blah)" "(defun test- (blah)"))
302+
"(defun tester (blah)" "(defun test? (blah)" "(defun test- (blah)"
303+
"(defmacro test-asdf (blah)" "(defmacro test-blah\n"
304+
"(defmacro tester (blah)" "(defmacro test? (blah)" "(defmacro test- (blah)"
305+
"(defgeneric test-asdf (blah)" "(defgeneric test-blah\n"
306+
"(defgeneric tester (blah)" "(defgeneric test? (blah)" "(defun test- (blah)"
307+
"(defmethod test-asdf (blah)" "(defmethod test-blah\n"
308+
"(defmethod tester (blah)" "(defmethod test? (blah)" "(defun test- (blah)"
309+
"(defsetf test-asdf (blah)" "(defsetf test-blah\n"
310+
"(defsetf tester (blah)" "(defsetf test? (blah)" "(defun test- (blah)"))
311+
312+
(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
313+
:regex "\\\(define-(modify-macro|compiler-macro|setf-expander)\\s+JJJ\\j"
314+
;; \\j usage see `dumb-jump-ag-word-boundary`
315+
:tests ("(define-modify-macro test (blah)" "(define-modify-macro test\n"
316+
"(define-compiler-macro test (blah)" "(define-compiler-macro test\n")
317+
:not ("(define-modify-macro test-asdf (blah)" "(define-modify-macro test-blah\n"
318+
"(define-modify-macro tester (blah)" "(define-modify-macro test? (blah)" "(define-modify-macro test- (blah)"
319+
"(define-compiler-macro test-asdf (blah)" "(define-compiler-macro test-blah\n"
320+
"(define-compiler-macro tester (blah)" "(define-compiler-macro test? (blah)" "(define-compiler-macro test- (blah)"))
321+
322+
(:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
323+
:regex "\\\(def(var|parameter|constant)\\b\\s*JJJ\\j"
324+
:tests ("(defvar test " "(defvar test\n"
325+
"(defparameter test " "(defparameter test\n"
326+
"(defconstant test " "(defconstant test\n")
327+
:not ("(defvar tester" "(defvar test?" "(defvar test-"
328+
"(defparameter tester" "(defparameter test?" "(defparameter test-"
329+
"(defconstant tester" "(defconstant test?" "(defconstant test-"))
299330

300331
(:type "variable" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
301-
:regex "\\\(defparameter\\b\\s*JJJ\\j"
302-
:tests ("(defparameter test " "(defparameter test\n")
303-
:not ("(defparameter tester" "(defparameter test?" "(defparameter test-"))
332+
:regex "\\\(define-symbol-macro\\b\\s*JJJ\\j"
333+
:tests ("(define-symbol-macro test " "(define-symbol-macro test\n")
334+
:not ("(define-symbol-macro tester" "(define-symbol-macro test?" "(define-symbol-macro test-"))
335+
336+
(:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
337+
:regex "\\\(def(class|struct|type)\\b\\s*JJJ\\j"
338+
:tests ("(defclass test " "(defclass test\n"
339+
"(defstruct test " "(defstruct test\n"
340+
"(deftype test " "(deftype test\n")
341+
:not ("(defclass tester" "(defclass test?" "(defclass test-"
342+
"(defstruct tester" "(defstruct test?" "(defstruct test-"
343+
"(deftype tester" "(deftype test?" "(deftype test-"))
344+
345+
(:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "commonlisp"
346+
:regex "\\\(define-condition\\b\\s*JJJ\\j"
347+
:tests ("(define-condition test " "(define-condition test\n")
348+
:not ("(define-condition tester" "(define-condition test?" "(define-condition test-"))
304349

305350
;; racket
306351
(:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "racket"
@@ -2169,6 +2214,8 @@ to keep looking for another root."
21692214
(defun dumb-jump-process-symbol-by-lang (lang look-for)
21702215
"Process LANG's LOOK-FOR. For instance, clojure needs namespace part removed."
21712216
(cond
2217+
((and (string= lang "commonlisp") (s-contains? ":" look-for) (not (s-starts-with? ":" look-for)))
2218+
(nth 1 (s-split ":" look-for 'omit-nulls)))
21722219
((and (string= lang "clojure") (s-contains? "/" look-for))
21732220
(nth 1 (s-split "/" look-for)))
21742221
((and (string= lang "fennel") (s-contains? "." look-for))
@@ -2722,6 +2769,9 @@ searcher symbol."
27222769
(t
27232770
shell-command-switch))))
27242771

2772+
(defconst dumb-jump--case-insensitive-languages
2773+
'("commonlisp"))
2774+
27252775
;; TODO: rename dumb-jump-run-definition-command
27262776
(defun dumb-jump-run-command
27272777
(look-for proj regexes lang exclude-args cur-file line-num parse-fn generate-fn)
@@ -2741,8 +2791,9 @@ searcher symbol."
27412791
(setq rawresults (shell-command-to-string cmd))
27422792
(dumb-jump-debug-message cmd rawresults))
27432793
(unless (s-blank? cmd)
2744-
(let ((results (funcall parse-fn rawresults cur-file line-num)))
2745-
(--filter (s-contains? look-for (plist-get it :context)) results)))))
2794+
(let ((results (funcall parse-fn rawresults cur-file line-num))
2795+
(ignore-case (member lang dumb-jump--case-insensitive-languages)))
2796+
(--filter (s-contains? look-for (plist-get it :context) ignore-case) results)))))
27462797

27472798
(defun dumb-jump-parse-response-line (resp-line cur-file)
27482799
"Parse a search program's single RESP-LINE for CUR-FILE into a list of (path line context)."
@@ -2890,6 +2941,9 @@ searcher symbol."
28902941
;; TODO: --search-zip always? in case the include is the in gz area like emacs lisp code.
28912942
(cmd (concat dumb-jump-ag-cmd
28922943
" --nocolor --nogroup"
2944+
(if (member lang dumb-jump--case-insensitive-languages)
2945+
" --ignore-case"
2946+
"")
28932947
(if (s-ends-with? ".gz" cur-file)
28942948
" --search-zip"
28952949
"")
@@ -2929,14 +2983,17 @@ searcher symbol."
29292983
proj-root))
29302984

29312985
;; git-grep plus ag only recommended for huge repos like the linux kernel
2932-
(defun dumb-jump-generate-git-grep-plus-ag-command (look-for cur-file proj regexes _lang exclude-paths)
2986+
(defun dumb-jump-generate-git-grep-plus-ag-command (look-for cur-file proj regexes lang exclude-paths)
29332987
"Generate the ag response based on the needle LOOK-FOR in the directory PROJ.
29342988
Using ag to search only the files found via git-grep literal symbol search."
29352989
(let* ((filled-regexes (dumb-jump-populate-regexes look-for regexes 'ag))
29362990
(proj-dir (file-name-as-directory proj))
29372991
(ag-files-arg (dumb-jump-get-git-grep-files-matching-symbol-as-ag-arg look-for proj-dir))
29382992
(cmd (concat dumb-jump-ag-cmd
29392993
" --nocolor --nogroup"
2994+
(if (member lang dumb-jump--case-insensitive-languages)
2995+
" --ignore-case"
2996+
"")
29402997
(if (s-ends-with? ".gz" cur-file)
29412998
" --search-zip"
29422999
"")
@@ -2956,6 +3013,9 @@ Using ag to search only the files found via git-grep literal symbol search."
29563013
(proj-dir (file-name-as-directory proj))
29573014
(cmd (concat dumb-jump-rg-cmd
29583015
" --color never --no-heading --line-number -U"
3016+
(if (member lang dumb-jump--case-insensitive-languages)
3017+
" --ignore-case"
3018+
"")
29593019
(when (not (s-blank? dumb-jump-rg-search-args))
29603020
(concat " " dumb-jump-rg-search-args))
29613021
(s-join "" (--map (format " --type %s" it) rgtypes))))
@@ -2972,6 +3032,9 @@ Using ag to search only the files found via git-grep literal symbol search."
29723032
(ggtypes (when (file-name-extension cur-file) (dumb-jump-get-git-grep-type-by-language lang)))
29733033
(cmd (concat dumb-jump-git-grep-cmd
29743034
" --color=never --line-number"
3035+
(if (member lang dumb-jump--case-insensitive-languages)
3036+
" --ignore-case"
3037+
"")
29753038
(when dumb-jump-git-grep-search-untracked
29763039
" --untracked")
29773040
(when (not (s-blank? dumb-jump-git-grep-search-args))
@@ -2994,28 +3057,34 @@ Using ag to search only the files found via git-grep literal symbol search."
29943057
(if (s-ends-with? ".gz" cur-file)
29953058
dumb-jump-zgrep-cmd
29963059
dumb-jump-grep-cmd)))
3060+
(case-args (if (member lang dumb-jump--case-insensitive-languages)
3061+
" --ignore-case"
3062+
""))
29973063
(exclude-args (dumb-jump-arg-joiner "--exclude-dir" exclude-paths))
29983064
(include-args (dumb-jump-get-ext-includes lang))
29993065
(regex-args (dumb-jump-arg-joiner "-e" filled-regexes)))
30003066
(if (= (length regexes) 0)
30013067
""
3002-
(dumb-jump-concat-command cmd dumb-jump-grep-args exclude-args include-args regex-args proj))))
3068+
(dumb-jump-concat-command cmd dumb-jump-grep-args case-args exclude-args include-args regex-args proj))))
30033069

3004-
(defun dumb-jump-generate-gnu-grep-command (look-for cur-file proj regexes _lang _exclude-paths)
3070+
(defun dumb-jump-generate-gnu-grep-command (look-for cur-file proj regexes lang _exclude-paths)
30053071
"Find LOOK-FOR's CUR-FILE in the PROJ with REGEXES for the LANG but not in EXCLUDE-PATHS."
30063072
(let* ((filled-regexes (--map (shell-quote-argument it)
30073073
(dumb-jump-populate-regexes look-for regexes 'gnu-grep)))
30083074
(cmd (concat (if (eq system-type 'windows-nt) "" (concat dumb-jump-grep-prefix " "))
30093075
(if (s-ends-with? ".gz" cur-file)
30103076
dumb-jump-zgrep-cmd
30113077
dumb-jump-grep-cmd)))
3078+
(case-args (if (member lang dumb-jump--case-insensitive-languages)
3079+
" --ignore-case"
3080+
""))
30123081
;; TODO: GNU grep doesn't support these, so skip them
30133082
(exclude-args "")
30143083
(include-args "")
30153084
(regex-args (dumb-jump-arg-joiner "-e" filled-regexes)))
30163085
(if (= (length regexes) 0)
30173086
""
3018-
(dumb-jump-concat-command cmd dumb-jump-gnu-grep-args exclude-args include-args regex-args proj))))
3087+
(dumb-jump-concat-command cmd dumb-jump-gnu-grep-args case-args exclude-args include-args regex-args proj))))
30193088

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

0 commit comments

Comments
 (0)