* Scanning parenthesis in string/comment
@ 2023-01-22 17:15 Yuan Fu
2023-01-23 1:49 ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-23 8:10 ` Jean Louis
0 siblings, 2 replies; 4+ messages in thread
From: Yuan Fu @ 2023-01-22 17:15 UTC (permalink / raw)
To: help-gnu-emacs
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.
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Scanning parenthesis in string/comment
2023-01-22 17:15 Scanning parenthesis in string/comment Yuan Fu
@ 2023-01-23 1:49 ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-23 19:24 ` Yuan Fu
2023-01-23 8:10 ` Jean Louis
1 sibling, 1 reply; 4+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-01-23 1:49 UTC (permalink / raw)
To: Yuan Fu; +Cc: help-gnu-emacs
Yuan Fu <casouri@gmail.com> writes:
> 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.
>
> Yuan
Based on what I remember reading from the relevant info pages and
docstrings, is it possible that you start a new syntax scan that starts
*at point* and ends *before the ending quotes*? IIUC the function
`parse-partial-sexp' might be what you should look into next.
Best,
RY
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Scanning parenthesis in string/comment
2023-01-22 17:15 Scanning parenthesis in string/comment Yuan Fu
2023-01-23 1:49 ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-01-23 8:10 ` Jean Louis
1 sibling, 0 replies; 4+ messages in thread
From: Jean Louis @ 2023-01-23 8:10 UTC (permalink / raw)
To: Yuan Fu; +Cc: help-gnu-emacs
* 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Scanning parenthesis in string/comment
2023-01-23 1:49 ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-01-23 19:24 ` Yuan Fu
0 siblings, 0 replies; 4+ messages in thread
From: Yuan Fu @ 2023-01-23 19:24 UTC (permalink / raw)
To: Ruijie Yu; +Cc: help-gnu-emacs
> On Jan 22, 2023, at 5:49 PM, Ruijie Yu <ruijie@netyu.xyz> wrote:
>
>
> Yuan Fu <casouri@gmail.com> writes:
>
>> 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.
>>
>> Yuan
>
> Based on what I remember reading from the relevant info pages and
> docstrings, is it possible that you start a new syntax scan that starts
> *at point* and ends *before the ending quotes*? IIUC the function
> `parse-partial-sexp' might be what you should look into next.
Thanks, that seems to be the way to go.
> 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.
Yeah I can find the range of the string and do a parse inside. Thanks!
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-23 19:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-22 17:15 Scanning parenthesis in string/comment Yuan Fu
2023-01-23 1:49 ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-01-23 19:24 ` Yuan Fu
2023-01-23 8:10 ` Jean Louis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).