From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ag Newsgroups: gmane.emacs.devel Subject: Programmed completions are utterly confusing Date: Mon, 14 Nov 2022 14:01:36 -0600 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14390"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 15 00:34:21 2022 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 1ouiy3-0003Y1-QQ for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 00:34:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouijG-00037d-L6; Mon, 14 Nov 2022 18:19:02 -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 1ouieM-0002B8-FR for emacs-devel@gnu.org; Mon, 14 Nov 2022 18:13:58 -0500 Original-Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oufeG-0003Xb-G7 for emacs-devel@gnu.org; Mon, 14 Nov 2022 15:01:41 -0500 Original-Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-13b23e29e36so13734474fac.8 for ; Mon, 14 Nov 2022 12:01:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=El2j9QpMSyCNze38tI3Xg5xH3A+SWYbYLvBkOnqsNuw=; b=WPqVZunzp1WJCYxtl//Wan3GKfuGQnkahKOylDrtGIxWA+c7PwI9QC1HQi/i3xJTUl xdf7JLL2YFjcYonRC2G8s40EkMgoL151JztkiKZm/S9U3GZMKSPKoW00EmT82jzyK+ec XuGiOzCOHnOukrx/BAvBJaf/QvCrGNBbAL3uBCiw33LLPR9Xtmy6AcUlidFhYaJV8TX2 teIDxy2jQ+dr+39gwjWPy5IHsadI45T7qoi1dHa7ptalhaAeEz73/CqLszGH+CdrYGkE qj3dPukUfWSHLghueACfpLo1fRiO8OOYzWdIbjGbPQ4A/njSfDonBmGVbnfFsJm7bD0/ x7qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=El2j9QpMSyCNze38tI3Xg5xH3A+SWYbYLvBkOnqsNuw=; b=CLBfNji62xosMCYpOsnitk5sRBXM4tZz5Obzuzfgjk4xMKY6DWSQ/45ScFRJXBxvSq v8SBgHH1zu3CVDK6Y6c9ypT+y8ihxc86DzkBJqdMmCHOaW/+khAH2pXEN+srHhb06KMI 3g0KWrKCSaIOpxh4D1dAX7xLBIQdPMYAXpJ3qew8aim3xM352k81XyQhrVPDvq3grB5b 52omMrTbWI5f5JVvQHCAHT8XTcBneMPbyN+LyhnaNoXHdcxqCZFihDIBpJRIU9zKnpdD j/9RLPYObXO6IuVjn/2lH/UCwiaE+MktlrBDm8fFQb6kId44uwkmw58+T4j7bi5kGPMn JTgA== X-Gm-Message-State: ANoB5pnWIwWJfPCkC0xnpQVfbs5Eukey5K3TmyN5BCO46LEeQFVvG5NV hQSyWkVWcxtfg7KL/08GQK2Q2iZtExQ= X-Google-Smtp-Source: AA0mqf6vZhz4LYzGYutBMWnjR1o03fdWBiV88BkAqNEmEY32OFdaJFEP3/QMmW2e0+FnhJ+oJCC88A== X-Received: by 2002:a05:6870:51c5:b0:137:26c8:7a27 with SMTP id b5-20020a05687051c500b0013726c87a27mr7247343oaj.69.1668456097801; Mon, 14 Nov 2022 12:01:37 -0800 (PST) Original-Received: from AIBRAGIM-M-J8Z8 (99-97-209-112.lightspeed.rcsntx.sbcglobal.net. [99.97.209.112]) by smtp.gmail.com with ESMTPSA id f4-20020a056870898400b0012d130c2fdasm5364627oaq.48.2022.11.14.12.01.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 12:01:37 -0800 (PST) Received-SPF: pass client-ip=2001:4860:4864:20::35; envelope-from=agzam.ibragimov@gmail.com; helo=mail-oa1-x35.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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:299772 Archived-At: Before someone tells me that asking for help should be posted in help-gnu-emacs@gnu.org, I apologize for the noise, but I'm hoping maybe this could open a discussion for documentation improvements for completions. In my opinion, documentation around the subject is very terse and is lacking examples. I've been trying to understand how completions work, and I needed a completion that searches not only within the displayed rows but also in annotations. Someone suggested concatenating the annotation info into the main string, but I don't like this for a few reasons. I've even been told that the annotations are not designed for that, and if I want them to be searched upon, they really can't be annotations. - Use case I have right now: I want to search through URLs and their page titles. If I put each url into the main display string, and annotate them with titles, every row would be recognized as a "proper url", and packages like Embark could use that, e.g., I can dispatch embark-url-action and browse them. But if I concatenate the url and the page title, I would have to use tricks so Embark recognizes it as a url (and not a url with a string attached to it) - Another use case comes to mind, let's say I want to sift through some kind of log entries. Imagine I would want to provide a feature, where if typed something like "last 5 mins", it would limit the rows to include only log events with timestamps no older than five minutes ago. Obviously, there's no practical reason or a sensible way to encode dynamic time value into each row, So I dug a bit further and found: https://www.gnu.org/software/emacs/manual/html_node/elisp/Programmed-Completion.html I attempted to try it with something like this: ```lisp (defun dogs-filter (seq) (lambda (str pred flag) (pcase flag ('metadata (list 'metadata (cons 'annotation-function (lambda (c) (format "\n\t%s" (alist-get c seq nil nil #'string=)))))) ('t (if (string-blank-p str) (all-completions str seq) (all-completions str (lambda (s _ _) (seq-map #'car (seq-filter (lambda (x) (unless (string-blank-p str) (or (s-contains-p str (car x) :ignore-case) (s-contains-p str (cdr x) :ignore-case)))) seq))))))))) (let* ((coll '(("Affenpinscher" . "Loyal and amusing") ("Akita" . "Ancient Japanese") ("Bulldog" . "Kind but courageous") ("Caucasian Shepherd" . "Serious guarding breed") ("Miniature Schnauzer" . "Long-lived and low-shedding")))) (completing-read "Select a breed: " (dogs-filter coll))) ``` It looks like it works, but I don't think it really does. First of all, I have to use that weird "if" check, otherwise it won't display things when the completion string is empty. Also, it doesn't work like, for example, Consult does, which allows you to type multiple words and search for both occurrences. In the example above, `str` never gets set to be multiple words, always uses only the first one that's typed and ignores everything after the first whitespace. Also, I figured out how to attach metadata, but couldn't wrap my head around other flags, I don't know how `nil`, `lambda` and `boundaries` work. I understand some of the metadata properties: `category`, `annotation-function`, `affixation-function`, `group-function`. I know how `display-sort-function` works, but have no clue what `cycle-sort-function` is for and how it can be used. I don't understand all these `completion-table-dynamic`, `...-table-with-cache`, `...-with-predicate`, `...-case-fold`, etc. Can someone please help me learn all this? And can you please tell me what's wrong with the snippet?