Commit dcb41e22 authored by Troels Henriksen's avatar Troels Henriksen
Browse files

More work on arglist intelligence. I think it works now. Please report

any breakage.
parent 062b206a
...@@ -3551,18 +3551,21 @@ Returns NIL if an arglist cannot be displayed." ...@@ -3551,18 +3551,21 @@ Returns NIL if an arglist cannot be displayed."
(worker (parent operand-form))))))))) (worker (parent operand-form)))))))))
(nreverse (worker operand-form t))))) (nreverse (worker operand-form t)))))
(defun find-operand-info (mark syntax operator-form) (defun find-operand-info (mark-or-offset syntax operator-form)
"Returns two values: The operand preceding `mark' and the path "Returns two values: The operand preceding `mark-or-offset' and
from `operator-form' to the operand." the path from `operator-form' to the operand."
(let* ((preceding-arg-token (form-before syntax (offset mark))) (let* ((offset (if (numberp mark-or-offset)
mark-or-offset
(offset mark-or-offset)))
(preceding-arg-token (form-before syntax offset))
(indexing-start-arg (indexing-start-arg
(let* ((candidate-before preceding-arg-token) (let* ((candidate-before preceding-arg-token)
(candidate-after (when (null candidate-before) (candidate-after (when (null candidate-before)
(let ((after (form-after syntax (offset mark)))) (let ((after (form-after syntax offset)))
(when after (when after
(parent after))))) (parent after)))))
(candidate-around (when (null candidate-after) (candidate-around (when (null candidate-after)
(form-around syntax (offset mark)))) (form-around syntax offset)))
(candidate (or candidate-before (candidate (or candidate-before
candidate-after candidate-after
candidate-around))) candidate-around)))
...@@ -3617,6 +3620,32 @@ Returns NIL if an arglist cannot be displayed." ...@@ -3617,6 +3620,32 @@ Returns NIL if an arglist cannot be displayed."
(indices-match-arglist arg (rest arg-indices)) (indices-match-arglist arg (rest arg-indices))
(null (rest arg-indices))))) (null (rest arg-indices)))))
(defun direct-arg-p (form syntax)
"Check whether `form' is a direct argument to one of its
parents."
(labels ((recurse (parent)
(let ((operator (form-operator
parent
syntax)))
(or (and
;; An operator is not an argument to itself...
(not (= (start-offset form)
(start-offset (first-form (children parent)))))
(valid-operator-p operator)
(indices-match-arglist
(arglist (image syntax)
operator)
(second
(multiple-value-list
(find-operand-info
(start-offset form)
syntax
parent)))))
(when (parent parent)
(recurse (parent parent)))))))
(when (parent form)
(recurse (parent form)))))
(defmacro with-code-insight (mark syntax (&key operator preceding-operand (defmacro with-code-insight (mark syntax (&key operator preceding-operand
form preceding-operand-indices form preceding-operand-indices
operands) operands)
...@@ -3645,21 +3674,25 @@ Returns NIL if an arglist cannot be displayed." ...@@ -3645,21 +3674,25 @@ Returns NIL if an arglist cannot be displayed."
;; regard to the structure of the lambda list. If we ;; regard to the structure of the lambda list. If we
;; cannot find a form with a valid operator, just ;; cannot find a form with a valid operator, just
;; return the form `mark' is in. ;; return the form `mark' is in.
(labels ((recurse (form) (unless (null immediate-form)
(if (and (valid-operator-p (form-operator (labels ((recurse (form)
form (unless (null form)
,syntax-value-sym)) (if (and (valid-operator-p (form-operator
(indices-match-arglist form
(arglist (image syntax) ,syntax-value-sym))
(form-operator (indices-match-arglist
form (arglist (image ,syntax-value-sym)
,syntax-value-sym)) (form-operator
(second (multiple-value-list (find-operand-info ,mark-value-sym ,syntax-value-sym form))))) form
(or (when (and form (parent form)) ,syntax-value-sym))
(recurse (parent form))) (second
form)))) (multiple-value-list
(or (recurse (when immediate-form (parent immediate-form))) (find-operand-info ,mark-value-sym ,syntax-value-sym form)))))
(when immediate-form (parent immediate-form)))))) (or (recurse (parent form))
(unless (direct-arg-p form ,syntax-value-sym)
form))))))
(or (recurse (parent immediate-form))
immediate-form)))))
;; If we cannot find a form, there's no point in looking ;; If we cannot find a form, there's no point in looking
;; up any of this stuff. ;; up any of this stuff.
(,operator-sym (when ,form-sym (form-operator ,form-sym ,syntax-value-sym))) (,operator-sym (when ,form-sym (form-operator ,form-sym ,syntax-value-sym)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment