help-gnu-emacs
[Top][All Lists]
Advanced

[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: Thu, 5 Jan 2023 17:00:28 +0000

> The library thingatpt+.el extends thingatpt.el
> EmacsWiki: Thing At Point Plus:
> https://www.emacswiki.org/emacs/ThingAtPointPlus
> 
> Though itself is not used extensively in many of
> your libraries, Drew. At least I did grep on many.

I try to have my libraries _not_ depend on
each other needlessly.  I try to avoid having
them be "package" sacks of stuff.  Better that
you should be able to load several or just a
few or just one, depending on what you want.

Typically I SOFT-require a library and so take
advantage of it only IF you _load_ it.  And in
some cases certain commands in a library might
themselves really require a particular library
(in which case they're either not defined if
that library isn't available or they raise an
error telling you it's needed).

My libraries DO make use of thingatpt+.el
extensively - IF it's loaded.  Anytime a
library of mine uses THING stuff it takes
advantage of thingatpt+.el enhancements, 
if it's loaded.

Typical is the use of a function to obtain 
a default value for something.  E.g., in
Bookmark+ the default value of option
`bmkp-new-bookmark-default-names' includes
`region-or-non-nil-symbol-name-nearest-point'
if that's `fboundp'. 

[That thingatpt+ function returns the text
 in the region, if it's active and not empty.
 Otherwise it returns the name of the symbol
 nearest point (other than `nil'), within max
 search distances `tap-near-point-x-distance'
 (left/right) and `tap-near-point-y-distance'
 (up/ down).]

And function `bmkp-read-variable' uses as
default the `symbol-nearest-point' if that
thingatpt+ function is defined; otherwise
just `symbol-at-point'.

And if available `bmkp-thing-at-point' uses
the thingatpt+ version of `thing-at-point';
else it uses the vanilla version.

And so on, for all of my libraries.

A library HARD-requires thingatpt+.el only
when no (usable, however poor) substitute
for some needed functionality is available
with vanilla thingatpt.el.  It's rare that
a library absolutely needs thingatpt+. It's
more common that some part of a library
(e.g. some command) needs thingatpt+, in
which case that part of the code does the
requiring itself.
___

> There is 'string and 'string-contents, really good.
> 
> Though in various modes 'string should be re-defined to support
> various quotes in various modes, let us say in Perl.

Send me the relevant info.  The code uses
(eq (char-syntax (char-after)) ?\"), and it
uses `syntax-ppss'.  So I'd expect that it
already DTRT for strings with different
delimiters.  But suggestions welcome.

> I have examined (thing-at-point 'list):
> - it works on '(1 "OK" 2) and then I can choose
>   (thing-at-point 'list-contents) to get the elements
> - but it does not work on (list 1 2 3), as there I get
>   the element `list' by using 'list-contents, that is now
>   what I expected, but OK, it is more generalized "list".

I guess you mean that you get the string
"list 1 2 3".  That's correct - that's the
text that's the list content.

You'll need to clarify.  I suggest you do
that off-list.  If the text `(list 1 2 3)' is
in a buffer and you try (thing-at-point 'list)
then that literal, textual list is the string
you get and should get, IMO.  It's not about
evaluating code and then returning the thing
that's the result of that evaluation.  It's
about getting a textual thing (e.g. list) at
point.

> The concept of elementary things basically teach
> computer to recognize where is the point.

I don't follow you there.

> Things at point are elementary contexts.

Or there.

> It is possible to teach computer to recognize stuff, and then act upon
> it in unified way.

Or there.  Maybe try to be more specific.

> Unification to one key is helpful. No need to remember too many keys.
> 
> Contexts may be expanded by looking into major mode, buffer file name,
> position in the file, various elements of the file, TODO states, and
> similar.

Feel free to communicate any _specific_
suggestions for thingatpt+.el.

> I defined this:
> (defun rcd-tap-iso-date-start ()
>   "Move point to the beginning of the ISO date."
>   (when (thing-at-point-looking-at rcd-rx-iso-date)
>     (goto-char (match-beginning 0))))
> (defun rcd-tap-iso-date-end ()...)
> (put 'iso-date 'beginning-op 'rcd-tap-iso-date-start)
> (put 'iso-date 'end-op 'rcd-tap-iso-date-end)
> 
> Then on 2023-01-05 the (thing-at-point 'iso-date)
> gives result: "2023-01-05"
> jump quickly to messages and calls from that day.

You might also be interested in my `find-where.el'.
It lets you move forward/back to the beginning/end
of the next/previous thing etc. (repeatably).   

https://www.emacswiki.org/emacs/FindWhere

By default, movement is to the START position
of something, but really the <where>, in
relation to the <what>, is up to you.  The
default behavior is thus different from the
standard Emacs `forward|backward-THING'
behavior, which moves just PAST the THING
rather than just TO it.

More generally, `find-where.el' finds (and
optionally moves to) the next/previous place
where <something> is true.  <Something> can
be anything - a predicate.

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).

reply via email to

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