From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.devel Subject: Re: Re: [External] : Re: Adding custom providers for thingatpt.el (was: [PATCH] Add support for 'thing-at-point' to get URL at point) Date: Thu, 16 May 2024 00:25:07 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17408"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.12 (2023-09-09) Cc: Pedro Andres Aranda Gutierrez , emacs-devel To: Drew Adams Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 15 23:26:15 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s7M8c-0004LQ-RN for ged-emacs-devel@m.gmane-mx.org; Wed, 15 May 2024 23:26:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7M80-0005B0-Ad; Wed, 15 May 2024 17:25:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s7M7x-00058v-8h for emacs-devel@gnu.org; Wed, 15 May 2024 17:25:33 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s7M7q-00031f-4T for emacs-devel@gnu.org; Wed, 15 May 2024 17:25:32 -0400 Original-Received: from localhost ([::ffff:197.239.11.132]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000A3AEB.0000000066452842.000A5C82; Wed, 15 May 2024 14:25:22 -0700 Mail-Followup-To: Drew Adams , Pedro Andres Aranda Gutierrez , emacs-devel Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319271 Archived-At: * Drew Adams [2024-05-15 23:57]: > > I was of understanding that it is the regular > > expression that decides what is on the point or not. > > What regular expression? > > Are you thinking of a regular expression that's > checked to see if some particular kind of thing > is at point, e.g. a regexp like the value of a > var such as `thing-at-point-newsgroup-regexp'? > > Such a regexp doesn't determine/define what "at > point" means. Maybe I have not call it right. I may explain it on the example: ;;; Thing at point 'iso-date We assume that rcd-rx-iso-date ➜ "[[:digit:]][[:digit:]][[:digit:]][[:digit:]]-\\(?:0[[:digit:]]\\|1[0-2]\\)-\\(?:[0-2][[:digit:]]\\|3[01]\\)" (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 () "Move point to the end of the ISO date." (when (thing-at-point-looking-at rcd-rx-iso-date) (goto-char (match-end 0)))) (put 'iso-date 'beginning-op 'rcd-tap-iso-date-start) (put 'iso-date 'end-op 'rcd-tap-iso-date-end) The definition of the thing at point is the one deciding what is the thing. And programmer is the one deciding where the thing actually begins. While user may have different view point where the thing at point begins, the actual definition is somewhere in the code and can be found and understood. I could define that my ISO date is surrounded by spaces " 2024-05-16 " and user may assume that it is not: "2024-05-16", so the definition is in the code and left for programmers to decide how to define it. What if I wish that thing at point is anywhere on the line, regardless where is the cursor? While I did not try it out, I think that is quite feasible to do. Then why try to make general STRICT, to try to affect specific random or indefinite definitions of code, instead, complaint or suggestion, patch on specific code can be made to make it stricter, or new code may be written to make that what other user wish to achieve. > That movement is customizable (with properties > `forward-op', `beginning-op', `end-op', > `bounds-of-thing-at-point', `thing-at-point', > and in other ways). But the starting position > is `(point)'; that's where the check is done. Yes, I agree on everything you said with the exception not mentioned, and that is the consideration of programmer. Programmer may say that ISO date below is at point, when cursor or point is at X, and that ISO date shall be extracted or memorized, noted, etc. by follow up functions. It is matter of consideration. ..X.......................... 2024-05-16 ISO date need not be like below X to say that it is "at point" as it is matter of consideration. I see your words that you said the same what I am saying here. 2X24-05-16 > The bug is in `bounds-of-thing-at-point'. It > should be faithful to its name, and check only > at (point), not at EITHER point OR (1- (point)). 1. The thing at point is defined by programmer. 2. What are bounds of thing at point is thus result of definition of programmer. 3. It implies that thing at point may be looking like having spaces or being forward or backwards from cursor, and still be considered at point, as that is defined by programmer. I do not consider that a bug. 2024-05-16 A cursors before the above ISO date is not captured, and after it, is not captured as thing at point. I have tried it with M-: (thing-at-point 'iso-date), though I believe that other thing at point may be defined so to be sensed close to cursor, and that freedom is fine. What is the "bound" is defined by programmer not by function "bounds-of-thing-at-point". > Even if the fix were to always check only at > (1- (point)), instead of (point), it would be > a legitimate fix for the problem caused by the > ambiguity: there's _no way to determine whether_ > there's a thing at a given position. I see that as freedom, and you see as ambiguity. Without looking into the code and understanding it, isn't it all of the code at some point ambiguity? > IOW, it technically doesn't matter which single > position is the "origin" for checking: (point) > or (1- (point)) or whatever else. The bug is > that _no single_ position is used. I see that function `thing-at-point-looking-at' is using function `point'. You are here expert, you see some bug there, and I see freedom of considerations. > However, since "at point" does mean something > in Emacs English, the proper fix is to always > check starting from (point), not (1- (point)) > or any other position. I did not experience that with the ISO date, so I do not see it is bug. Maybe it is, as I forgot what I did to make it work. But I do understand that other things at point are invoked when cursor is before it. And that is freedom to define it, it does not need to be strictly on the point. My searchable text area maybe a line, not so? And I wish to capture or record that date on the line, while I did not make it so, it may be useful. Point could be anywhere far from the ISO date, and invoking function could capture the date. I find that useful. > Either always-(point) or always-(1- (point)) > would be a fix. But always-(point) is the > better/proper fix, just because it accords > with Emacs terminology. Sure, but where is that (1- (point))? I did not find it. I was using this function below, and I do not see that. I tried searching for "(1- )" and did not find that reference, but found something for the URL https://www.EXAMPLE.comX - if I place cursor on X it will detect the URL. But that is because URL thing was defined that way to be detected. Maybe you should complain on that specific function to be changed, instead of trying to change general code in present and in future with STRICT. The function below has DISTANCE argument for those settings. (defun thing-at-point-looking-at (regexp &optional distance) "Return non-nil if point is in or just after a match for REGEXP. Set the match data from the earliest such match ending at or after point. Optional argument DISTANCE limits search for REGEXP forward and back from point." (let* ((old (point)) (beg (if distance (max (point-min) (- old distance)) (point-min))) (end (if distance (min (point-max) (+ old distance)))) prev match) (save-excursion (goto-char beg) (while (and (setq prev (point) match (re-search-forward regexp end t)) (< (match-end 0) old)) (goto-char (match-beginning 0)) ;; Avoid inflooping when `regexp' matches the empty string. (unless (< prev (point)) (forward-char)))) (and match (<= (match-beginning 0) old (match-end 0))))) What if I think of visible buffer as thing at point? Why not? Then I wish to capture specific text inside, and no matter where is cursor, it would work. I find that handy, useful. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns ✡️🛡️ Proudly standing with Israel, a nation rooted in history and culture. Let's condemn hatred and promote understanding. In support of Richard M. Stallman https://stallmansupport.org/