[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scanning parenthesis in string/comment
From: |
Jean Louis |
Subject: |
Re: Scanning parenthesis in string/comment |
Date: |
Mon, 23 Jan 2023 11:10:49 +0300 |
User-agent: |
Mutt/2.2.9+54 (af2080d) (2022-11-21) |
* Yuan Fu <casouri@gmail.com> [2023-01-22 20:17]:
> I’m writing an expand-region-like function, which expands region by logical
> entities, like word-at-point, list-at-point, etc. Say I have this string
>
> "Filter out invalid regions in REGIONS regarding ORIG.
> ORIG is the current position. Each region is (BEG . END).”
>
> And point is at the opening parenthesis, how do I detect this
> balanced parenthesis pair and expand the region over it? syntax-pass
> and forward-list only works with lists outside of strings and
> comments, IIUC.
What I understand is that you use thing-at-point similar functions, so
why not then define your own think at point in the sense as here below:
;;; Thing at point 'thing-within-quotes
(defun rcd-tap-thing-within-quotes-start ()
"Move point to the beginning of thing within quotes."
(re-search-backward (rx (or "\"" "'")))
(forward-char 1))
(defun rcd-tap-thing-within-quotes-end ()
"Move point to the end of thing within quotes."
(re-search-forward (rx (or "\"" "'")))
(backward-char 1))
(put 'thing-within-quotes 'beginning-op 'rcd-tap-thing-within-quotes-start)
(put 'thing-within-quotes 'end-op 'rcd-tap-thing-within-quotes-end)
Then the above will give you whatever is inside of quotes you define
when you apply function:
(thing-at-point 'thing-within-quotes)
on it, and it will not work well outside of quotes.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/