From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: Xref completion Date: Wed, 18 Nov 2020 15:46:03 +0200 Message-ID: <8b5f4961-f980-4971-50b7-4770205833ee@yandex.ru> References: <873617ets1.fsf@ambrevar.xyz> <878sazzsw5.fsf@mail.linkov.net> <7593e751-cff0-7c1a-7d4c-f927a16c07c9@yandex.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32762"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 To: William Xu , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 18 14:47:05 2020 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 1kfNnc-0008Pp-Lh for ged-emacs-devel@m.gmane-mx.org; Wed, 18 Nov 2020 14:47:04 +0100 Original-Received: from localhost ([::1]:51400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfNnb-0005kx-NL for ged-emacs-devel@m.gmane-mx.org; Wed, 18 Nov 2020 08:47:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfNmn-0004fy-Cd for emacs-devel@gnu.org; Wed, 18 Nov 2020 08:46:13 -0500 Original-Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:34992) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kfNmh-00051v-QN for emacs-devel@gnu.org; Wed, 18 Nov 2020 08:46:12 -0500 Original-Received: by mail-ed1-x534.google.com with SMTP id ay21so2061547edb.2 for ; Wed, 18 Nov 2020 05:46:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=kD+sxTp5fnykjLdkgyZIKGtn1H+NWdiKyuzgGwXmTWI=; b=EPcOZ0RC28MPFCQW3i3DkWtdcIEqGHCD7BY4IDPhHtXZEbS6eNWCP6ajlwiRv2AUqm Q1Kp7ikeWY4UCfxV2k1fEnqNTDyrrJZSMnZRAAMB0Ww/Y2kcReGS/2s1Hd1gkUotJInY 7AMDD2PvmQbywK4g5lqdR8o09VBGakTWXAgt3xB+7HbAzSVfQccB+jrEQ5LE74zrgd5G i/Ro0xh5+I3cMyAJXAm+CJM1UlHDEAbkCCWG0VjD1ALjozGUvgXFYV1PlkQ5Ew5PKfgE yZCZ8cA0uduosRrU19mJweKyK8MQUke/NM3k/y+GmitBU4hQyz5dFRc4UtJlSXAjpspn U1oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kD+sxTp5fnykjLdkgyZIKGtn1H+NWdiKyuzgGwXmTWI=; b=farW5bHhKQm+glXQptUcY2UDYNZJL7TPFetsh0G5S78TYwztkacaYU+3uyrsCLDnwk kbdizjFzgtO9EIhpRDsQGyTr5Om6BWfUuQ83+SVlOLrJrT8CccymhBzqRDCh1FAaDkIM +HP0+EVv87VWVUPqQ33fWjNfuRJ34bzvweYjRwLOeZMUKF8tPM5CZm/L5A82bbolU4ux hJJJj/UEsOnv0AmOEDNif56SkzUbaXpRVquogT0/EEpTQh1BVLuMZcUkPwKZRwLaT10G MKi0Ru0nhr1UDMkISW1uEdytrd7uPC1GiH1iNYoWxV6mEXXoetUB2YBPXAGP9yMfNkYo qVlg== X-Gm-Message-State: AOAM530BXR4ccdIj7CdqgHtvqlVMqG8yLwtn6pWUutjyqSLrM31/zXIr xzT/caAW7jY6WF/RzSML26df+tobKif0Zg== X-Google-Smtp-Source: ABdhPJyT1g7AWN6iCuuj2JNqC0rehybMPFgWdqeVeF657JvvErvHvglEC4QbzcGmKq4CiKSZKTk5mw== X-Received: by 2002:a50:8562:: with SMTP id 89mr1506769edr.144.1605707166111; Wed, 18 Nov 2020 05:46:06 -0800 (PST) Original-Received: from [192.168.0.4] ([66.205.71.3]) by smtp.googlemail.com with ESMTPSA id h20sm778577edw.12.2020.11.18.05.46.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Nov 2020 05:46:05 -0800 (PST) In-Reply-To: Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=raaahh@gmail.com; helo=mail-ed1-x534.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:259341 Archived-At: On 18.11.2020 09:35, William Xu wrote: > Dmitry Gutov writes: > >> On 17.11.2020 23:16, William Xu wrote: >>> (defun my-xref--show-defs-minibuffer (fetcher alist) >>> (let* ((xrefs (funcall fetcher)) >>> (xref-alist (xref--analyze xrefs)) >>> (xref (if (not (cdr xrefs)) >>> (car xrefs) >>> (cadr (assoc (completing-read "Jump to definition: " xref-alist) >>> xref-alist))))) >>> (xref-pop-to-location xref (assoc-default 'display-action alist)))) >> >> A solid try, but note you might have a problem when there are several >> matches in the same file: you won't be able to navigate to any but the >> first one. >> >> Of course, depending on your current programming language, this might >> be not important. > > In that case, we can just prepend the line and summary in front of the filename? Yup. I'm not sure why prepend and not append, but I suppose it's a matter of preference. Also, xref-location-line can return nil (then format will error out because of %d). So after a little experimenting, this is the form I ended up with: (format "%s:%s: %s" group line summary) > (defun my-xref--show-defs-minibuffer (fetcher alist) > (let* ((xrefs (funcall fetcher)) > (xref-alist (xref--analyze xrefs)) > xref-alist-with-line-info > xref) > > (cl-loop for ((group . xrefs) . more1) on xref-alist > do > (cl-loop for (xref . more2) on xrefs do > (with-slots (summary location) xref > (let ((line (xref-location-line location))) > (push (cons (format "%d: %s %s" line summary group) xref) > xref-alist-with-line-info))))) > > (setq xref (if (not (cdr xrefs)) > (car xrefs) > (cdr (assoc (completing-read "Jump to definition: " xref-alist-with-line-info) > xref-alist-with-line-info)))) > > (xref-pop-to-location xref (assoc-default 'display-action alist)))) >