Okay, we've cut our teeth on emacs regular expressions. Let's use 'em. (Not our teeth. Regexes.) To start, let's save our reStructuredText regular expression to find a ref so we can easily grab it later. I'll save the one I came up with to the name tmp/re (this name is arbitrary, I drop temporary variables into tmp/<name> out of habit) ELispFont used to highlight built-in function names. Font used to highlight strings. Font used to highlight keywords. (setq tmp/re (rx bol ".." (+ blank) "_" (group (+ (not ":"))) ":" eol)) Now we can reference it easily. I mentioned before that re-search-forward accepts a regex, so let's hop into a reStructuredText rev up the regex. Here's my sample text that I'll work with: ReSTFont used for directives and roles. Font used for all other defining constructs. Font used for the adornment of a section header. Default font for section title text at level 1. A Title ======= Beware the Jabberwock, my son. .. _my-reference: You are like a little baby. Watch this. .. _code-sample: .. code:: python print("emacs needs telemetry") The end? The re-search-forward documentation indicates that it starts at the point's current position, so head to the start of the buffer, hit M-: to enter the elisp Eval prompt, and try: ELispFont used to highlight built-in function names. (re-search-forward tmp/re) This is anticlimactic because you'll just see the point move to the end of one of the references. BUT. This means that the search succeeded. So… what now? More reading in the re-search-forward documentation will educate you about emacs global match data. In non-functional-programming style, functions like match-beginning and match-end serve to interrogate a global state that functions like re-search-forward will modify. In concise terms, our regular expression defines one match group and we can grab it with (match-string-no-properties 1) to get the first group match (match-string will return a string with "properties", which is a bunch of data like font s...
First seen: 2025-09-12 17:01
Last seen: 2025-09-12 20:03