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.help Subject: ThingAtPointPlus, and extending things at point Date: Thu, 5 Jan 2023 11:37:09 +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="38798"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.9+54 (af2080d) (2022-11-21) Cc: Help GNU Emacs To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 05 09:39:04 2023 Return-path: Envelope-to: geh-help-gnu-emacs@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 1pDLmC-0009qh-65 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 05 Jan 2023 09:39:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDLlV-00073s-C7; Thu, 05 Jan 2023 03:38:21 -0500 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 1pDLlT-00073L-TN for help-gnu-emacs@gnu.org; Thu, 05 Jan 2023 03:38:19 -0500 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 1pDLlS-0001fO-0r for help-gnu-emacs@gnu.org; Thu, 05 Jan 2023 03:38:19 -0500 Original-Received: from localhost ([::ffff:102.85.153.82]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000055D5E.0000000063B68C5C.00005E21; Thu, 05 Jan 2023 01:37:48 -0700 Mail-Followup-To: Drew Adams , Help GNU Emacs 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: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:142123 Archived-At: 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 am just examining it. 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. 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". The concept of elementary things basically teach computer to recognize where is the point. Things at point are elementary contexts. It is possible to teach computer to recognize stuff, and then act upon it in unified way. 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. Here is how I have defined thing 'iso-date First I have defined imperfect ISO date regular expression: (defvar rcd-rx-iso-date (rx (seq (any digit) (any digit) (any digit) (any digit)) "-" (or (seq "0" (any digit)) (seq "1" (any "0-2"))) "-" (or (seq (any "0-2") (any digit)) (seq "3" (any "0-1")))) "Regular expression for ISO date.") It is imperfect as it does not check for number of days in specific month. (string-match rcd-rx-iso-date "2023-01-05") ➜ 0 (string-match rcd-rx-iso-date "2023-01-32") ➜ nil (string-match rcd-rx-iso-date "2023-01-31") ➜ 0w but incorrect for: (string-match rcd-rx-iso-date "2023-02-31") ➜ 0 then 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 () "Move point to the end of the ISO date." (when (thing-at-point-looking-at rcd-rx-iso-date) (goto-char (match-end 0)))) and finally definition of thing at point 'iso-date here below: (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" 0 10 (fontified t)) Thanks to thingatpt.el (by Mike Williams) and thingatpt+.el (by Drew Adams). Why is it useful? It is useful in the context, like having list of people who communicated on 2023-01-05 or 2023-01-04, Joe Doe 2023-01-05 Marry 2023-01-04 to jump quickly to messages and calls from that day. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/