{"schemaVersion":1,"contentVersion":"3.4.0","id":"intermediate.3","languages":{"javascript":{"id":"intermediate.3","title":"Match nested delimiters","moduleName":"Boundaries and reusable text","tips":"","concept":"<p class=\"lead\">Jump to a bracket's real partner instead of the next bracket that looks the same.</p><p><strong>Before this lesson:</strong> Choose the whole pair.</p><p>On a bracket, % moves to its partner, even through nested pairs. Anywhere else on the line, it uses the next bracket after the cursor. d% deletes from the cursor to that partner, brackets and all. A character search like f) just finds the next ), so it can stop at the wrong one.</p><h3>Example</h3><p>On the first opening bracket in outer(inner(value)), % jumps to the very last closing bracket and skips the inner one.</p><p>Use Start over to try again.</p>","teaches":["bracket-match"],"introduces":["%"],"constraints":[],"drills":[{"task":"The search fires on every key. Wait <code>300</code> milliseconds: add it as the second argument of <code>setTimeout</code>.","hint":"On a bracket, % jumps to its partner, however many lines away it is.","mode":"jsx","start":"import { searchProducts } from \"../api/search\";\n\n// Searches as the customer types, but waits until they pause.\nexport function onQueryChange(input, render) {\n  clearTimeout(input.timer);\n  input.timer = setTimeout(() => {\n    searchProducts(input.value).then(render);\n  });\n}","startCursor":{"line":5,"ch":26},"paths":[{"keys":["%","i",", 300","<Esc>"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match"],"note":"% lands on the closing bracket that belongs to setTimeout, three lines down."}],"target":"import { searchProducts } from \"../api/search\";\n\n// Searches as the customer types, but waits until they pause.\nexport function onQueryChange(input, render) {\n  clearTimeout(input.timer);\n  input.timer = setTimeout(() => {\n    searchProducts(input.value).then(render);\n  }, 300);\n}","language":"javascript","evidence":"guided","canonicalKey":"intermediate.3#0","canonicalFingerprint":"1xkmlp6"},{"task":"The store loads the cart itself now. Remove the <code>.then(…)</code> call, so <code>.catch</code> comes straight after <code>getCart()</code>.","hint":"d% deletes from the cursor to the partner of the next bracket on the line, nested brackets and all.","mode":"jsx","start":"import { api } from \"../api\";\n\n// Loads the cart when the drawer opens. Errors show in the drawer itself.\nexport function openDrawer(store) {\n  store.setOpen(true);\n  return api.getCart().then((cart) => store.setCart(cart)).catch(store.setError);\n}","startCursor":{"line":4,"ch":2},"paths":[{"keys":["j","2","f",".","d","%"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match","operator-motion"],"note":"From the full stop, % finds the next opening bracket and its real partner, so d% takes the whole call."}],"target":"import { api } from \"../api\";\n\n// Loads the cart when the drawer opens. Errors show in the drawer itself.\nexport function openDrawer(store) {\n  store.setOpen(true);\n  return api.getCart().catch(store.setError);\n}","language":"javascript","evidence":"guided","canonicalKey":"intermediate.3#1","canonicalFingerprint":"t3ef2h"}]},"python":{"id":"intermediate.3","title":"Match nested delimiters","moduleName":"Boundaries and reusable text","tips":"","concept":"<p class=\"lead\">Jump to a bracket's real partner instead of the next bracket that looks the same.</p><p><strong>Before this lesson:</strong> Choose the whole pair.</p><p>On a bracket, % moves to its partner, even through nested pairs. Anywhere else on the line, it uses the next bracket after the cursor. d% deletes from the cursor to that partner, brackets and all. A character search like f) just finds the next ), so it can stop at the wrong one.</p><h3>Example</h3><p>On the first opening bracket in outer(inner(value)), % jumps to the very last closing bracket and skips the inner one.</p><p>Use Start over to try again.</p>","teaches":["bracket-match"],"introduces":["%"],"constraints":[],"drills":[{"task":"The client expects <code>201</code> for a new order. Add <code>status=201</code> as the last argument of <code>Response</code>.","hint":"On a bracket, % jumps to its partner, however many lines away it is.","mode":"python","start":"from rest_framework.response import Response\n\nfrom .serializers import OrderSerializer\n\n\ndef created_response(order, checkout_url):\n    \"\"\"What the API answers once an order is placed.\"\"\"\n    serializer = OrderSerializer(order)\n    return Response({\n        \"order\": serializer.data,\n        \"next\": checkout_url,\n    })","startCursor":{"line":8,"ch":19},"paths":[{"keys":["%","i",", status=201","<Esc>"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match"],"note":"% lands on the closing bracket that belongs to Response, three lines down."}],"target":"from rest_framework.response import Response\n\nfrom .serializers import OrderSerializer\n\n\ndef created_response(order, checkout_url):\n    \"\"\"What the API answers once an order is placed.\"\"\"\n    serializer = OrderSerializer(order)\n    return Response({\n        \"order\": serializer.data,\n        \"next\": checkout_url,\n    }, status=201)","language":"python","evidence":"guided","canonicalKey":"intermediate.3#0","canonicalFingerprint":"1xkmlp6"},{"task":"Cancelled and refunded orders should show up too. Remove the <code>.exclude(…)</code> call.","hint":"d% deletes from the cursor to the partner of the next bracket on the line, nested brackets and all.","mode":"python","start":"from shop.orders import models\n\n\ndef recent_orders(user):\n    \"\"\"The orders on the account page, newest first.\"\"\"\n    orders = models.Order.objects.filter(customer=user).exclude(status__in=[\"cancelled\", \"refunded\"]).order_by(\"-placed_at\")\n    return orders[:20]","startCursor":{"line":4,"ch":4},"paths":[{"keys":["j","f",")","l","d","%"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match","operator-motion"],"note":"From the full stop, % finds the next opening bracket and its real partner, so d% takes the whole call."}],"target":"from shop.orders import models\n\n\ndef recent_orders(user):\n    \"\"\"The orders on the account page, newest first.\"\"\"\n    orders = models.Order.objects.filter(customer=user).order_by(\"-placed_at\")\n    return orders[:20]","language":"python","evidence":"guided","canonicalKey":"intermediate.3#1","canonicalFingerprint":"t3ef2h"}]},"text":{"id":"intermediate.3","title":"Match nested delimiters","moduleName":"Boundaries and reusable text","tips":"","concept":"<p class=\"lead\">Jump to a bracket's real partner instead of the next bracket that looks the same.</p><p><strong>Before this lesson:</strong> Choose the whole pair.</p><p>On a bracket, % moves to its partner, even through nested pairs. Anywhere else on the line, it uses the next bracket after the cursor. d% deletes from the cursor to that partner, brackets and all. A character search like f) just finds the next ), so it can stop at the wrong one.</p><h3>Example</h3><p>On the first opening bracket in outer(inner(value)), % jumps to the very last closing bracket and skips the inner one.</p><p>Use Start over to try again.</p>","teaches":["bracket-match"],"introduces":["%"],"constraints":[],"drills":[{"task":"Belgian orders don't get free shipping. Add <code> AND country &lt;&gt; 'BE'</code> after the closing bracket.","hint":"On a bracket, % jumps to its partner, however many lines away it is.","mode":"text/plain","start":"-- Paid orders that qualify for free shipping.\nSELECT id, total_cents\nFROM orders\nWHERE status = 'paid'\n  AND (\n    total_cents >= 5000\n    OR coupon_code IN ('FREESHIP', 'WELCOME')\n  )\nORDER BY placed_at DESC;","startCursor":{"line":4,"ch":6},"paths":[{"keys":["%","a"," AND country <> 'BE'","<Esc>"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match"],"note":"% lands on the bracket that closes the condition, three lines down."}],"target":"-- Paid orders that qualify for free shipping.\nSELECT id, total_cents\nFROM orders\nWHERE status = 'paid'\n  AND (\n    total_cents >= 5000\n    OR coupon_code IN ('FREESHIP', 'WELCOME')\n  ) AND country <> 'BE'\nORDER BY placed_at DESC;","language":"text","evidence":"guided","canonicalKey":"intermediate.3#0","canonicalFingerprint":"1xkmlp6"},{"task":"Final sale items can be returned now. Remove the whole bracketed note.","hint":"d% deletes from the cursor to the partner of the next bracket on the line, nested brackets and all.","mode":"text/plain","start":"# Returns policy\n\nReturns are free within 30 days (unless the item is marked as final sale (see below)).\nWe refund the full price, shipping included.\n\nSend the parcel back with the label from your account.","startCursor":{"line":0,"ch":0},"paths":[{"keys":["2","j","t","(","d","%"],"tier":"idiomatic","technique":"bracket-match","core":["bracket-match","operator-motion"],"note":"From the space, % finds the next opening bracket and its real partner, so d% takes the note and the space before it."}],"target":"# Returns policy\n\nReturns are free within 30 days.\nWe refund the full price, shipping included.\n\nSend the parcel back with the label from your account.","language":"text","evidence":"guided","canonicalKey":"intermediate.3#1","canonicalFingerprint":"t3ef2h"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Choose the whole pair.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Jump to a bracket's real partner instead of the next bracket that looks the same.</p><p>On a bracket, % moves to its partner, even through nested pairs. Anywhere else on the line, it uses the next bracket after the cursor. d% deletes from the cursor to that partner, brackets and all. A character search like f) just finds the next ), so it can stop at the wrong one.</p><h2 class=\"prose-subhead\">Example</h2><p>On the first opening bracket in outer(inner(value)), % jumps to the very last closing bracket and skips the inner one.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Choose the whole pair.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Jump to a bracket's real partner instead of the next bracket that looks the same.</p><p>On a bracket, % moves to its partner, even through nested pairs. Anywhere else on the line, it uses the next bracket after the cursor. d% deletes from the cursor to that partner, brackets and all. A character search like f) just finds the next ), so it can stop at the wrong one.</p><h2 class=\"prose-subhead\">Example</h2><p>On the first opening bracket in outer(inner(value)), % jumps to the very last closing bracket and skips the inner one.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Choose the whole pair.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Jump to a bracket's real partner instead of the next bracket that looks the same.</p><p>On a bracket, % moves to its partner, even through nested pairs. Anywhere else on the line, it uses the next bracket after the cursor. d% deletes from the cursor to that partner, brackets and all. A character search like f) just finds the next ), so it can stop at the wrong one.</p><h2 class=\"prose-subhead\">Example</h2><p>On the first opening bracket in outer(inner(value)), % jumps to the very last closing bracket and skips the inner one.</p><p>Use Start over to try again.</p></div></details>"}}}