From b7791618acfda28f6dbfaf993c07d8bd0d81e357 Mon Sep 17 00:00:00 2001 From: vindarel Date: Thu, 21 Nov 2024 19:20:11 +0100 Subject: [PATCH] detective: parse macros --- extensions/lisp-mode/ext/detective.lisp | 3 +++ extensions/lisp-mode/lisp-mode.lisp | 4 ++++ src/ext/detective.lisp | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/extensions/lisp-mode/ext/detective.lisp b/extensions/lisp-mode/ext/detective.lisp index 59b276065..3deab2bff 100644 --- a/extensions/lisp-mode/ext/detective.lisp +++ b/extensions/lisp-mode/ext/detective.lisp @@ -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)) diff --git a/extensions/lisp-mode/lisp-mode.lisp b/extensions/lisp-mode/lisp-mode.lisp index e56c48ab8..2efc4a418 100644 --- a/extensions/lisp-mode/lisp-mode.lisp +++ b/extensions/lisp-mode/lisp-mode.lisp @@ -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 " diff --git a/src/ext/detective.lisp b/src/ext/detective.lisp index d9439f17c..c513ee819 100644 --- a/src/ext/detective.lisp +++ b/src/ext/detective.lisp @@ -20,6 +20,9 @@ :variable-reference :variable-reference-value + :macro-reference + :macro-reference-value + :misc-reference :misc-custom-type @@ -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 @@ -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 @@ -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 @@ -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)) @@ -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)