all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Yuan Fu <casouri@gmail.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Scanning parenthesis in string/comment
Date: Mon, 23 Jan 2023 11:10:49 +0300	[thread overview]
Message-ID: <Y85BCQeiPv5jdWq5@protected.localdomain> (raw)
In-Reply-To: <497B6D44-1C2D-4C45-9B6B-6719D49B4A69@gmail.com>

* 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/



      parent reply	other threads:[~2023-01-23  8:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y85BCQeiPv5jdWq5@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=casouri@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.