From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Completion: display of candidates Date: Tue, 19 Feb 2019 08:27:49 +0100 Message-ID: <87lg2cgruy.fsf@gnu.org> References: <877edx8rbh.fsf@gnu.org> <87mumtno2f.fsf@gnu.org> <877edwsxw1.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="109401"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 19 08:28:51 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvzpi-000SMX-ON for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Feb 2019 08:28:50 +0100 Original-Received: from localhost ([127.0.0.1]:43285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvzph-0007Gs-PC for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Feb 2019 02:28:49 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:35648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvzoq-0006tL-SZ for help-gnu-emacs@gnu.org; Tue, 19 Feb 2019 02:27:57 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:37835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvzon-00072r-SU; Tue, 19 Feb 2019 02:27:54 -0500 Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:57677) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1gvzom-0005yB-Pl; Tue, 19 Feb 2019 02:27:53 -0500 Original-Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 67F2221E71; Tue, 19 Feb 2019 02:27:52 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 19 Feb 2019 02:27:52 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtdefgdefudculddtuddrgedtledrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufhfffgjkfgfgggtgfesthhqredttderjeenucfhrhhomhepvfgrshhs ihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucfkphepudefgedruddule drvdegrdduleehnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnodhmvghsmhht phgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedvleekqdhtsh guhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhmnecuvehluhhsthgvrhfuihii vgeptd X-ME-Proxy: Original-Received: from jiffyarch (j289989.servers.jiffybox.net [134.119.24.195]) by mail.messagingengine.com (Postfix) with ESMTPA id 38B62E4385; Tue, 19 Feb 2019 02:27:51 -0500 (EST) Mail-Followup-To: Stefan Monnier , help-gnu-emacs@gnu.org In-Reply-To: (Stefan Monnier's message of "Mon, 18 Feb 2019 15:48:36 -0500") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:119462 Archived-At: Stefan Monnier writes: >> Right, and here comes the next problem: concretely I get my >> completions from `locate --basename `. So the user (me) >> might enter a wildcard pattern like "foo*bar.*". But the >> completions/matches obviously have no * in it, so no completion >> matches the candidates. > > That completely depends on the completion style. > > For example `partial-completion` (which is included in the default > `completion-styles`) does accept * so you can do `M-x r*v*uf TAB` to > find revert-buffer. Hm, that there can be dependencies between (1) finding completion candidates and (2) completion styles doesn't spark joy in my heart. I thought of (1) as a kind of generic backend and (2) as a frontend which users select based on personal preference. But since both have to work with the user's input string, I don't see how to make it better... >> How to handle that? Use the PREDICATE argument in completing-read so > > The PREDICATE argument can only rule out matches, not add new ones. Yeah, in the end I've waived my hands and went without text properties and just selected a unicode character which is unlikely to be used in file names as separator. The results are quite satisfying. --8<---------------cut here---------------start------------->8--- (defconst th/recentf-locate-excluded-paths (let ((home (getenv "HOME"))) (list #'backup-file-name-p (expand-file-name ".cargo/" home) (expand-file-name ".cache/" home) (expand-file-name ".m2/" home) (expand-file-name ".IntelliJIdea[^/]+/" home)))) (defun th/recentf-locate-completions (str) (with-current-buffer (get-buffer-create " *th/locate-matches*") (erase-buffer) (mapc (lambda (rf) (insert rf "\n")) recentf-list) (let ((home-dir (getenv "HOME")) lst line-move-visual) (when (> (length str) 2) (call-process "locate" nil t nil "--basename" "--existing" "--ignore-case" "--limit" "500" str)) (goto-char (point-min)) (while (not (eobp)) (let* ((path (buffer-substring (point) (line-end-position))) (basename (file-name-nondirectory path)) (dir (file-name-directory path))) (unless (seq-find (lambda (pred) (cond ((stringp pred) (string-match-p pred path)) ((functionp pred) (funcall pred path)) (t (error "Don't know how to handle %S" pred)))) th/recentf-locate-excluded-paths) (push (format "%s =E2=80=BC %s" basename dir) lst))) (next-line)) (sort lst (lambda (a b) (or ;; a is in HOME but b is not, so sort a before b (and (string-match-p (concat " =E2=80=BC " home-dir) a) (not (string-match-p (concat " =E2=80=BC " home-dir) b))) ;; otherwise sort by base name. (string-lessp a b))))))) (defun th/recentf-locate-file (locate-candidate) (interactive (list (completing-read "Locate File: " (completion-table-dynamic #'th/recentf-locate-completions) nil t))) (let ((path (progn (string-match "^\\(.*\\) =E2=80=BC \\(.*\\)$" locate-candidate) (expand-file-name (match-string 1 locate-candidate) (match-string 2 locate-candidate))))) (find-file path))) (global-set-key (kbd "") #'th/recentf-locate-file) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo