drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
271 stars 22 forks source link

Handling entering symex interface from inside a string #141

Open pbaille opened 2 months ago

pbaille commented 2 months ago

Summary of Changes

As discussed in #140, strings are treated as atomic entities in symex. That being said I think it make sense to select the whole string when entering symex interface from within.

https://github.com/drym-org/symex.el/assets/4739483/8c704afa-76f0-4601-ad7f-f3a2e58db746

Public Domain Dedication

(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)

countvajhula commented 2 months ago

(thing-at-point 'string) always returns nil for me. Are you sure that string is a valid input? I don't see it in the documentation for thing-at-point.

I agree in principle with your suggestion, but I'm not sure if there is an easy way to implement it. Unlike () and [], "" does not distinguish opening from closing delimiter, so it's not obvious whether point is within a string or outside it. For instance,

"abc" hi there "pqr"

Here, if we are within "abc" or "pqr" we might expect it to return true, but even "hi there" appears to be within quotes if you just start in the middle and look in each direction:

... " hi there " ...

This is especially true for multi-line strings:

"multi-line abc" hi there "pqr also multi-line"

Once again, it's "... abc" and "pqr ..." that seem to be the strings here, but it's impossible to determine this locally. (Then there are also escaped strings like " hi \"there\" abc" ... 😭 )

pbaille commented 2 months ago

Yes I agree that it is madness :) Not fun at all to implement ! I've just check for the 'string argument to the thing-at-point function, and it appears that the 'string type was added in emacs version 28.1. I am seeing this on the manual page

:PROPERTIES:
:changes:  28.1 New 'thing-at-point' target: 'existing-filename' and 'string'.
:changes+:  28.1 New variable 'thing-at-point-provider-alist'.
:END:

I don't know which version of emacs we want to support here.

countvajhula commented 2 months ago

Ah, interesting! Well, I'm currently on Emacs 27 myself. I do plan to upgrade soon, and we could consider dropping support for <28 at that point 😄