Mon Jan 4 01:07:02 UTC 2010 pix@kepibu.org * subject-p makes more sense as (selector, element) For future reference, I used the following code to do this automatically, plus a few minor manual edits (e.g., swapping rcurry and curry): (defun seek-forward (term) (let ((p (search-forward term nil t))) (when p (goto-char p)))) (defun swap-args () (interactive) (save-excursion (while (seek-forward "defmethod subject-p (") (forward-sexp) (transpose-sexps 1))) (save-excursion (while (seek-forward "(subject-p") (forward-sexp) (transpose-sexps 1)))) diff -rN -u old-Oh, Ducks!/selectors.lisp new-Oh, Ducks!/selectors.lisp --- old-Oh, Ducks!/selectors.lisp 2015-09-07 07:52:42.000000000 +0000 +++ new-Oh, Ducks!/selectors.lisp 2015-09-07 07:52:42.000000000 +0000 @@ -109,15 +109,15 @@ (when (subject-p element selector) (list element)) (subjects-in-list selector (element-children element)))) -(defgeneric subject-p (element selector)) +(defgeneric subject-p (selector element)) -(defmethod subject-p (element (selector type-selector)) +(defmethod subject-p ((selector type-selector) element) (element-type-equal element (selector-arg selector))) -(defmethod subject-p (element (selector id-selector)) +(defmethod subject-p ((selector id-selector) element) (string= (element-id element) (selector-arg selector))) -(defmethod subject-p (element (selector nth-child-selector)) +(defmethod subject-p ((selector nth-child-selector) element) (when-let* ((parent (element-parent element)) (pos (position element (funcall (typecase selector (nth-last-child-selector #'reverse) @@ -134,42 +134,42 @@ (t (and (zerop (mod (- pos b) a)) (not (minusp (/ (- pos b) a))))))))) -(defmethod subject-p (element (selector class-selector)) +(defmethod subject-p ((selector class-selector) element) (member (selector-arg selector) (element-classes element) :test #'string=)) -(defmethod subject-p (element (selector universal-selector)) +(defmethod subject-p ((selector universal-selector) element) (declare (ignore element selector)) t) -(defmethod subject-p (element (selector %implicit-element-selector)) +(defmethod subject-p ((selector %implicit-element-selector) element) (eq element *implicit-element*)) -(defmethod subject-p (element (selector list)) - (every (curry #'subject-p element) selector)) +(defmethod subject-p ((selector list) element) + (every (rcurry #'subject-p element) selector)) -(defmethod subject-p (element (selector child-combinator)) - (subject-p (element-parent element) (matcher selector))) +(defmethod subject-p ((selector child-combinator) element) + (subject-p (matcher selector) (element-parent element))) -(defmethod subject-p (element (selector descendant-combinator)) - (some (rcurry #'subject-p (matcher selector)) (element-ancestors element))) +(defmethod subject-p ((selector descendant-combinator) element) + (some (curry #'subject-p (matcher selector)) (element-ancestors element))) -(defmethod subject-p (element (selector adjacent-combinator)) +(defmethod subject-p ((selector adjacent-combinator) element) (let* ((parent (element-parent element)) (siblings (element-children parent)) (ourpos (position element siblings :test #'eq))) (and ourpos (> ourpos 0) - (subject-p (elt siblings (1- ourpos)) (matcher selector))))) + (subject-p (matcher selector) (elt siblings (1- ourpos)))))) -(defmethod subject-p (element (selector sibling-combinator)) +(defmethod subject-p ((selector sibling-combinator) element) (let* ((parent (element-parent element)) (siblings (element-children parent)) (ourpos (position element siblings :test #'eq))) (and ourpos (> ourpos 0) - (find-if (rcurry #'subject-p (matcher selector)) siblings :end ourpos)))) + (find-if (curry #'subject-p (matcher selector)) siblings :end ourpos)))) ;; Hello excessively long name (defun terminating-implicit-sibling-combinator-p (selector)