{"schemaVersion":1,"contentVersion":"3.4.0","id":"foundation.11","languages":{"javascript":{"id":"foundation.11","title":"Inspect and reuse a search","moduleName":"Search and apply","tips":"","concept":"<p class=\"lead\">Repeat a search, reverse it, and search for whole words only.</p><p><strong>Before this lesson:</strong> Search for a destination.</p><p>n repeats your last search in the same direction and N goes the other way. After ?, n still searches backward. * searches forward for the whole word under the cursor and # searches backward. /cat can match catalog, but * on cat skips it. Check each match before you edit, in case it's one to leave alone.</p><div class=\"pkeys\"><kbd>n</kbd> <kbd>N</kbd> <kbd>*</kbd> <kbd>#</kbd></div><h3>Example</h3><p>With three “ready” lines, /ready then Enter reaches the next one and n the one after that. N goes back to the previous match. Searching only moves the cursor.</p><h4>Worked text</h4><pre class=\"lesson-example\">const first = \"ready\";\nconst second = \"ready\";\nconst third = \"ready\";</pre><p>Use Start over to try again.</p>","teaches":["search:n","search:*"],"introduces":["n","N","*","#"],"constraints":[],"drills":[{"task":"Put the cursor on the <code>subtotal</code> call in <code>total</code>.","hint":"* searches for the word under the cursor, and n goes on to the next match.","mode":"jsx","start":"export const VAT_RATE = 0.2;\n\nexport function subtotal(lines) {\n  return lines.reduce((sum, line) => sum + line.price * line.quantity, 0);\n}\n\nexport function vat(lines) {\n  return Math.round(subtotal(lines) * VAT_RATE);\n}\n\nexport function total(lines, shipping = 0) {\n  return subtotal(lines) + vat(lines) + shipping;\n}\n\nexport const shipsFree = (lines) => subtotal(lines) >= 5000;","startCursor":{"line":2,"ch":16},"paths":[{"keys":["*","n"],"tier":"idiomatic","technique":"search:n","core":["search:n"],"note":"* searches for the word under the cursor, and n goes to the next match."}],"kind":"navigate","land":{"line":11,"ch":9},"language":"javascript","evidence":"guided","canonicalKey":"foundation.11#0","canonicalFingerprint":"r62y7q"},{"task":"Put the cursor on the <code>open</code> that the button flips, the one before this.","hint":"# searches back for the word under the cursor.","mode":"jsx","start":"import { useState } from \"react\";\n\nexport function Disclosure({ title, children }) {\n  const [open, setOpen] = useState(false);\n  return (\n    <section className=\"disclosure\">\n      <button aria-expanded={open} onClick={() => setOpen(!open)}>\n        {title}\n      </button>\n      {open && <div className=\"panel\">{children}</div>}\n    </section>\n  );\n}","startCursor":{"line":9,"ch":8},"paths":[{"keys":["#"],"tier":"idiomatic","technique":"search:#","core":["search:#"],"note":"# searches back for the word under the cursor."}],"kind":"navigate","land":{"line":6,"ch":59},"language":"javascript","evidence":"guided","canonicalKey":"foundation.11#1","canonicalFingerprint":"1517t27"},{"task":"Go to <code>Retry-After</code>, then back to the <code>retries</code> above it.","hint":"Both start with retr, so one search finds them. Search forward, then N goes back to the one above.","mode":"jsx","start":"// Wraps fetch for the API: a timeout, a few tries, and JSON either way.\nimport { config } from \"./config.js\";\nconst MAX_ATTEMPTS = config.retries ?? 3;\nconst DELAY_MS = 500;\n\nexport async function getJson(url) {\n  for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {\n    const response = await fetch(url, { signal: AbortSignal.timeout(8000) });\n    if (response.ok) return response.json();\n    if (response.status !== 429 || attempt === MAX_ATTEMPTS) {\n      throw new Error(`GET ${url} failed with ${response.status}`);\n    }\n    // Wait as long as the API asks, or a little longer each time.\n    const wait = Number(response.headers.get(\"Retry-After\")) * 1000 || DELAY_MS * attempt;\n    await new Promise((resolve) => setTimeout(resolve, wait));\n  }\n}","startCursor":{"line":3,"ch":0},"paths":[{"keys":["/","retr","<CR>","N"],"tier":"idiomatic","technique":"search:N","core":["search:N"],"note":"A search matches part of a word too. n goes on to the next match and N goes back."}],"kind":"navigate","land":{"line":2,"ch":28},"waypoints":[{"line":13,"ch":46}],"language":"javascript","evidence":"guided","canonicalKey":"foundation.11#2","canonicalFingerprint":"39gwn5"}]},"python":{"id":"foundation.11","title":"Inspect and reuse a search","moduleName":"Search and apply","tips":"","concept":"<p class=\"lead\">Repeat a search, reverse it, and search for whole words only.</p><p><strong>Before this lesson:</strong> Search for a destination.</p><p>n repeats your last search in the same direction and N goes the other way. After ?, n still searches backward. * searches forward for the whole word under the cursor and # searches backward. /cat can match catalog, but * on cat skips it. Check each match before you edit, in case it's one to leave alone.</p><div class=\"pkeys\"><kbd>n</kbd> <kbd>N</kbd> <kbd>*</kbd> <kbd>#</kbd></div><h3>Example</h3><p>With three “ready” lines, /ready then Enter reaches the next one and n the one after that. N goes back to the previous match. Searching only moves the cursor.</p><h4>Worked text</h4><pre class=\"lesson-example\">first = \"ready\"\nsecond = \"ready\"\nthird = \"ready\"</pre><p>Use Start over to try again.</p>","teaches":["search:n","search:*"],"introduces":["n","N","*","#"],"constraints":[],"drills":[{"task":"Put the cursor on the <code>subtotal</code> call in <code>total</code>.","hint":"* searches for the word under the cursor, and n goes on to the next match.","mode":"python","start":"VAT_RATE = 0.2\n\n\ndef subtotal(lines):\n    return sum(line.price * line.quantity for line in lines)\n\n\ndef vat(lines):\n    return round(subtotal(lines) * VAT_RATE)\n\n\ndef total(lines, shipping=0):\n    return subtotal(lines) + vat(lines) + shipping\n\n\ndef ships_free(lines):\n    return subtotal(lines) >= 5000","startCursor":{"line":3,"ch":4},"paths":[{"keys":["*","n"],"tier":"idiomatic","technique":"search:n","core":["search:n"],"note":"* searches for the word under the cursor, and n goes to the next match."}],"kind":"navigate","land":{"line":12,"ch":11},"language":"python","evidence":"guided","canonicalKey":"foundation.11#0","canonicalFingerprint":"r62y7q"},{"task":"Put the cursor on the previous use of <code>receipt</code>.","hint":"# searches back for the word under the cursor.","mode":"python","start":"from django.conf import settings\nfrom django.core.mail import send_mail\nfrom django.template.loader import render_to_string\nfrom django.utils import timezone\n\n\ndef send_receipt(order):\n    receipt = render_to_string(\"emails/order_receipt.txt\", {\"order\": order})\n    subject = f\"Northwind order {order.number}\"\n    send_mail(subject, receipt, settings.SHOP_EMAIL, [order.email])\n    order.receipt_sent_at = timezone.now()\n    order.save(update_fields=[\"receipt_sent_at\"])","startCursor":{"line":9,"ch":23},"paths":[{"keys":["#"],"tier":"idiomatic","technique":"search:#","core":["search:#"],"note":"# searches back for the word under the cursor."}],"kind":"navigate","land":{"line":7,"ch":4},"language":"python","evidence":"guided","canonicalKey":"foundation.11#1","canonicalFingerprint":"1517t27"},{"task":"Go to <code>Retry-After</code>, then back to the <code>retries</code> above it.","hint":"Both start with retr, so one search finds them. Search forward, then N goes back to the one above.","mode":"python","start":"\"\"\"Wraps httpx for the API: a timeout, a few tries, and JSON either way.\"\"\"\nimport time\n\nfrom httpx import get\n\nfrom shop.config import settings\n\nMAX_ATTEMPTS = settings.retries or 3\nDELAY = 0.5\n\n\ndef get_json(url):\n    for attempt in range(1, MAX_ATTEMPTS + 1):\n        response = get(url, timeout=8)\n        if response.status_code == 200:\n            return response.json()[\"data\"]\n        if response.status_code != 429 or attempt == MAX_ATTEMPTS:\n            raise RuntimeError(f\"GET {url} failed with {response.status_code}\")\n        # Wait as long as the API asks, or a little longer each time.\n        time.sleep(float(response.headers.get(\"Retry-After\", 0)) or DELAY * attempt)","startCursor":{"line":8,"ch":0},"paths":[{"keys":["/","retr","<CR>","N"],"tier":"idiomatic","technique":"search:N","core":["search:N"],"note":"A search matches part of a word too. n goes on to the next match and N goes back."}],"kind":"navigate","land":{"line":7,"ch":24},"waypoints":[{"line":19,"ch":47}],"language":"python","evidence":"guided","canonicalKey":"foundation.11#2","canonicalFingerprint":"39gwn5"}]},"text":{"id":"foundation.11","title":"Inspect and reuse a search","moduleName":"Search and apply","tips":"","concept":"<p class=\"lead\">Repeat a search, reverse it, and search for whole words only.</p><p><strong>Before this lesson:</strong> Search for a destination.</p><p>n repeats your last search in the same direction and N goes the other way. After ?, n still searches backward. * searches forward for the whole word under the cursor and # searches backward. /cat can match catalog, but * on cat skips it. Check each match before you edit, in case it's one to leave alone.</p><div class=\"pkeys\"><kbd>n</kbd> <kbd>N</kbd> <kbd>*</kbd> <kbd>#</kbd></div><h3>Example</h3><p>With three “ready” lines, /ready then Enter reaches the next one and n the one after that. N goes back to the previous match. Searching only moves the cursor.</p><h4>Worked text</h4><pre class=\"lesson-example\">First: ready\nSecond: ready\nThird: ready</pre><p>Use Start over to try again.</p>","teaches":["search:n","search:*"],"introduces":["n","N","*","#"],"constraints":[],"drills":[{"task":"Put the cursor on the third <code>Kemal</code>, in week 13.","hint":"* searches for the word under the cursor, and n goes on to the next match.","mode":"text/plain","start":"# On-call rota, spring\n\nEach person is on call for a week, from Monday 09:00.\nSwap with someone if you need to, and update this file.\n\nWeek 10: Kemal, backup Dana\nWeek 11: Ines, backup Priya\nWeek 12: Dana, backup Kemal\nWeek 13: Kemal, backup Ines\nWeek 14: Priya, backup Dana\nWeek 15: Ines, backup Kemal","startCursor":{"line":5,"ch":9},"paths":[{"keys":["*","n"],"tier":"idiomatic","technique":"search:n","core":["search:n"],"note":"* searches for the word under the cursor, and n goes to the next match."}],"kind":"navigate","land":{"line":8,"ch":9},"language":"text","evidence":"guided","canonicalKey":"foundation.11#0","canonicalFingerprint":"r62y7q"},{"task":"Put the cursor on the previous use of <code>budget</code>.","hint":"# searches back for the word under the cursor.","mode":"text/plain","start":"# Planning, 12 November\n\nPresent: Dana, Ines, Kemal, Priya\n\nInes showed the new checkout. Conversion is up a little, but returns are up too.\nWe agreed to keep the budget for ads as it is until January.\nKemal will look at why returns went up, starting with the size guide.\nPriya asked whether we can afford a second warehouse person before Christmas.\nDana thinks the budget can cover it if ads stay flat.\n\nNext meeting: 26 November, same time.","startCursor":{"line":8,"ch":16},"paths":[{"keys":["#"],"tier":"idiomatic","technique":"search:#","core":["search:#"],"note":"# searches back for the word under the cursor."}],"kind":"navigate","land":{"line":5,"ch":22},"language":"text","evidence":"guided","canonicalKey":"foundation.11#1","canonicalFingerprint":"1517t27"},{"task":"Go to <code>Retry-After</code>, then back to the <code>retries</code> above it.","hint":"Both start with retr, so one search finds them. Search forward, then N goes back to the one above.","mode":"text/plain","start":"# Rate limits\n\nEach API key can make 600 requests a minute, and our client makes three retries before it gives up.\nBatch jobs should use their own key, so a big import can't block the shop.\n\n## What counts\n\nEvery request counts, including ones that fail. Webhooks we send you don't count.\nReading the same order twice in a second counts twice, so cache what you can.\n\n## When you go over\n\nOver the limit, we answer with status 429 and stop serving that key for the minute.\nWe send a Retry-After header with the seconds that are left, so wait at least that long.\nIf a key goes over every minute for an hour, we email the account owner.\nThey can raise the limit for a key from the developer settings.","startCursor":{"line":3,"ch":0},"paths":[{"keys":["/","retr","<CR>","N"],"tier":"idiomatic","technique":"search:N","core":["search:N"],"note":"A search matches part of a word too. n goes on to the next match and N goes back."}],"kind":"navigate","land":{"line":2,"ch":72},"waypoints":[{"line":13,"ch":10}],"language":"text","evidence":"guided","canonicalKey":"foundation.11#2","canonicalFingerprint":"39gwn5"}]}},"concepts":{"javascript":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Search for a destination.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Repeat a search, reverse it, and search for whole words only.</p><p>n repeats your last search in the same direction and N goes the other way. After ?, n still searches backward. * searches forward for the whole word under the cursor and # searches backward. /cat can match catalog, but * on cat skips it. Check each match before you edit, in case it's one to leave alone.</p><h2 class=\"prose-subhead\">Example</h2><p>With three “ready” lines, /ready then Enter reaches the next one and n the one after that. N goes back to the previous match. Searching only moves the cursor.</p><p>Use Start over to try again.</p></div></details>"},"python":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Search for a destination.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Repeat a search, reverse it, and search for whole words only.</p><p>n repeats your last search in the same direction and N goes the other way. After ?, n still searches backward. * searches forward for the whole word under the cursor and # searches backward. /cat can match catalog, but * on cat skips it. Check each match before you edit, in case it's one to leave alone.</p><h2 class=\"prose-subhead\">Example</h2><p>With three “ready” lines, /ready then Enter reaches the next one and n the one after that. N goes back to the previous match. Searching only moves the cursor.</p><p>Use Start over to try again.</p></div></details>"},"text":{"lead":"","reminder":"<p class=\"lesson-prereq\"><strong>Before this lesson:</strong> Search for a destination.</p>","more":"<details class=\"lesson-more\"><summary>More about this lesson</summary><div class=\"lesson-more-body prose\"><p class=\"lead\">Repeat a search, reverse it, and search for whole words only.</p><p>n repeats your last search in the same direction and N goes the other way. After ?, n still searches backward. * searches forward for the whole word under the cursor and # searches backward. /cat can match catalog, but * on cat skips it. Check each match before you edit, in case it's one to leave alone.</p><h2 class=\"prose-subhead\">Example</h2><p>With three “ready” lines, /ready then Enter reaches the next one and n the one after that. N goes back to the previous match. Searching only moves the cursor.</p><p>Use Start over to try again.</p></div></details>"}}}