Skip to content

Commit

Permalink
detective: parse macros
Browse files Browse the repository at this point in the history
  • Loading branch information
vindarel committed Nov 22, 2024
1 parent ff01fec commit b779161
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions extensions/lisp-mode/ext/detective.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
(defmethod capture-reference ((position lem:point) (class (eql :package-reference)))
(%default-capture 'lem/detective:package-reference position))

(defmethod capture-reference ((position lem:point) (class (eql :macro-reference)))
(%default-capture 'lem/detective:macro-reference position))

(defmethod capture-reference ((position lem:point) (class (eql :misc-reference)))
(ppcre:register-groups-bind (type name)
("^\\s*\\(\\s*(\\w+)\\s+(.*)\\s*" (line-string position))
Expand Down
4 changes: 4 additions & 0 deletions extensions/lisp-mode/lisp-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
(lem/detective:make-capture-regex
:regex "^(?:\\(defvar |\\(defparameter )"
:function #'lem-lisp-mode/detective:capture-reference)
:macro-regex
(lem/detective:make-capture-regex
:regex "^\\(defmacro "
:function #'lem-lisp-mode/detective:capture-reference)
:misc-regex
(lem/detective:make-capture-regex
:regex "^\\(deftest "
Expand Down
18 changes: 18 additions & 0 deletions src/ext/detective.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
:variable-reference
:variable-reference-value

:macro-reference
:macro-reference-value

:misc-reference
:misc-custom-type

Expand Down Expand Up @@ -100,6 +103,9 @@
((value :initarg :variable-reference-value
:reader variable-reference-value)))

(defclass macro-reference (reference)
((value :initarg :macro-reference-value
:reader macro-reference-value)))

(defclass misc-reference (reference)
((custom-type :initarg :misc-custom-type
Expand Down Expand Up @@ -131,6 +137,10 @@
:initarg :variable-regex
:writer set-variable-regex
:reader search-variable-regex )
(macro-regex :type (or capture-regex null)
:initform nil
:initarg :macro-regex
:reader search-macro-regex)
(misc-regex :type (or capture-regex null)
:initform nil
:initarg :misc-regex
Expand Down Expand Up @@ -174,6 +184,7 @@
(with-accessors ((function-regex search-function-regex)
(package-regex search-package-regex)
(class-regex search-class-regex)
(macro-regex search-macro-regex)
(variable-regex search-variable-regex)
(misc-regex search-misc-regex))
search
Expand All @@ -182,6 +193,7 @@
(cons (cons "classes" class-regex) :class-reference)
(cons (cons "packages" package-regex) :package-reference)
(cons (cons "variables" variable-regex) :variable-reference)
(cons (cons "macros" macro-regex) :macro-reference)
(cons (cons "misc" misc-regex) :misc-reference))))

(setf (buffer-references (current-buffer))
Expand Down Expand Up @@ -289,6 +301,12 @@
(let ((reference (navigate-reference "functions")))
(move-to-reference reference)))

(define-command detective-macro () ()
"Prompt for a macro defined in this buffer and move to it."
(check-change)
(let ((reference (navigate-reference "macros")))
(move-to-reference reference)))

(define-command detective-class () ()
"Prompt for a class defined in this buffer and move to it."
(check-change)
Expand Down

0 comments on commit b779161

Please sign in to comment.