[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : ThingAtPointPlus, and extending things at point

From: Drew Adams
Subject: RE: [External] : ThingAtPointPlus, and extending things at point
Date: Fri, 6 Jan 2023 17:30:28 +0000

> it finds string in Perl, like:
> print 'string';
> (thing-at-point 'string-contents)
> it finds:
> #("string" 0 6 (face font-lock-string-face fontified t))
> but not that it finds it in Elisp mode, because it is not string, and
> also not in mail mode

Of course.  It respects the meaning of "string", i.e.,
the "string" syntax that's defined _in the current
major mode_.  What else would you have it do?

If for some reason you need to have interpretation
take place wrt some other syntax table temporarily,
then just wrap the code that needs that with macro
`with-syntax-table'.  If there's a Python major mode
for Emacs, with a Python syntax table (such as, e.g.
`py-syntable'), (with-syntax-table py-syntable...).

> people often quote in this way `'. What is the name of
> that type of quoting?

Dunno.  It's the way Emacs has always quoted sexps
in its doc.  And much more than just Emacs, going
back decades.

More recently, Emacs started converting `...' to
curly quotes.  This is too bad, IMHO - harder to
insert/type and so also harder to search for.
But it's considered "prettier" and more "modern"...
"On n'arrete pas le progres..."

> Thanks, I find the function `fw-to-next-thing' very useful in this
> unification of functions. It is reinventing the wheel what GNU
> Hyperbole already has, with extensions.

Maybe so.  Does it allow for arbitrary predicates,
arbitrary/unlimited Lisp code?

> I can imagine that `fw-to-next-thing' must be slower function right?
> It is much slower then just using regular expression search.

Read the Commentary.  It begins:

;;; Commentary:
;;    Find where something is true.
;;  Get or go to the next place where some predicate is satisfied.
;;  But first, you don't really need this library! ;-)
;;  In Emacs and Emacs Lisp there are multiple ways to find things.
;;  And in many cases it will be simpler or more efficient to use
;;  another way than to take advantage of this library.
;;  What this library offers is some convenience sometimes, and a
;;  certain kind of generality: Specify what you want to find by a
;;  predicate.  The predicate is tested at successive places, forward
;;  or backward, until it is satisfied.

It then goes on to describe the default behavior
and implementation, it's strengths and weaknesses.
In particular, it says:

;;  Clearly, this move-one-char-and-test approach is not the way to go
;;  for ordinary string searching.  Emacs uses an efficient,
;;  Boyer-Moore string-search algorithm (see
;;  which essentially moves forward in chunks that are as long as what
;;  your search string matches, rather than moving just a character at
;;  a time before each match attempt.
;;  So if you want to search for a sequence of characters, just use
;;  `(re-)search-forward' or similar.  And if you need an additional
;;  test at a match position (e.g., check a text or overlay property)
;;  you can easily add that.  So forget about this library for
;;  ordinary buffer search.
;;  Still, you might find this library convenient for some things,
;;  even in cases where there is an easy alternative.  The abstraction
;;  of defining a destination by a predicate that holds there can be
;;  helpful.

Providing the abstraction I underlined is the sweet-spot
use case.

> > For example, you can find a text THING, such as the next vector with
> > 13 elements, and have it returned along with its bounds (start and
> > end positions).
> That is useful. Let us say I wish to collect all the anchors in the
> file, I can do it easier.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]