Re: looking-back
Jean Louis <[email protected]> Sat, 1 Aug 2026 20:14:25 +0300
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
* Andreas Röhler <[email protected]> [2026-08-01 15:56]: > Hi, > > > want to match an opening paren followed by a whitespace. Tried the forms > below without success. > Any suggestion? > > ( (looking-back "\\\\( +" (line-beginning-position) t) ==> nil > ( (looking-back (regexp-quote (rx "(" (+ space))) (line-beginning-position) > t) ==> nil ;; Step 1: Type this literal text on a new line (without quotes or backslash): ( hello) So you need to place cursor after space like where is "h" in hello and evaluate: (looking-back "( +" (line-beginning-position) t) So it gives me true at h. But not if I press cursor at "e" in hello above. You probably wanted to lookback longer than that... ( (re-search-backward (rx "(" (+ space)) (line-beginning-position) t) => 706 so this one would put cursor backwords... on the "( " ( (save-excursion (when (re-search-backward "( +" (line-beginning-position) t) (match-string 0))) ⇒ #("( " 0 2 (face font-lock-string-face fontified t)) (save-excursion (when (re-search-backward "( +" (line-beginning-position) t) (substring-no-properties (match-string 0)))) ⇒ "( " (save-excursion (when (re-search-backward "( +" (line-beginning-position) t) (list (match-string-no-properties 0) (match-beginning 0) (match-end 0)))) ⇒ ("( " 1166 1168) means finding this one ^^^^^ (save-excursion (when (re-search-backward "( +" nil t) ; nil = no limit (list (match-string-no-properties 0) (match-beginning 0) (match-end 0)))) ⇒ ("( " 1389 1391) -- Jean Louis