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.bugs Subject: bug#50067: Context menus Date: Tue, 24 Aug 2021 20:59:40 +0300 Message-ID: References: <83sfz639lh.fsf@gnu.org> <8735r6ppf0.fsf@mail.linkov.net> <83o89u37gh.fsf@gnu.org> <87wnohx5zd.fsf@mail.linkov.net> <831r6p3lzc.fsf@gnu.org> <87o89sh96g.fsf@mail.linkov.net> <837dgg1hdg.fsf@gnu.org> <87mtpcf79p.fsf@mail.linkov.net> <83zgtcyp2k.fsf@gnu.org> <56454B2B-0250-4BC6-BC26-E1C5579ACF49@acm.org> <83eeanyrm5.fsf@gnu.org> <4BC1074D-DE75-4303-8385-B70BAACFCDA0@acm.org> <83czq7youc.fsf@gnu.org> <32ef6b91-107c-d7e5-b103-0ff062bf8ebd@yandex.ru> <83y28twahy.fsf@gnu.org> <7af845e0-1f19-61fc-65e0-b23fac3927aa@yandex.ru> <83v93wx5ny.fsf@gnu.org> <83r1ekwfrd.fsf@gnu.org> <871r6ki6aw.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------731E6E4EEEFB597FE81CAC05" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14233"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 Cc: alan@idiocy.org, mattiase@acm.org, homeros.misasa@gmail.com, tkk@misasa.okayama-u.ac.jp, larsi@gnus.org, 50067@debbugs.gnu.org To: Juri Linkov , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 24 20:00:15 2021 Return-path: Envelope-to: geb-bug-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 1mIaic-0003Rv-7s for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Aug 2021 20:00:14 +0200 Original-Received: from localhost ([::1]:47798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mIaia-0000Up-S1 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Aug 2021 14:00:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mIaiR-0000UR-Iw for bug-gnu-emacs@gnu.org; Tue, 24 Aug 2021 14:00:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mIaiR-0000uo-Ax for bug-gnu-emacs@gnu.org; Tue, 24 Aug 2021 14:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mIaiQ-0004JG-Qw for bug-gnu-emacs@gnu.org; Tue, 24 Aug 2021 14:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Aug 2021 18:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50067 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 50067-submit@debbugs.gnu.org id=B50067.162982799216508 (code B ref 50067); Tue, 24 Aug 2021 18:00:02 +0000 Original-Received: (at 50067) by debbugs.gnu.org; 24 Aug 2021 17:59:52 +0000 Original-Received: from localhost ([127.0.0.1]:45149 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mIaiG-0004IC-1z for submit@debbugs.gnu.org; Tue, 24 Aug 2021 13:59:52 -0400 Original-Received: from mail-wr1-f50.google.com ([209.85.221.50]:43871) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mIaiD-0004Hv-Lc for 50067@debbugs.gnu.org; Tue, 24 Aug 2021 13:59:50 -0400 Original-Received: by mail-wr1-f50.google.com with SMTP id z9so32491558wrh.10 for <50067@debbugs.gnu.org>; Tue, 24 Aug 2021 10:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=EhZ2SPDHce6H4Ye8wzeRpMx2FVhxeEdFa1K8/4ZmlqQ=; b=SlhOj6Xu1QrIRRm/P4lnYMQti6Vof0IqN/AGQLc/ur8W1ll09Kz/u5JjBq0QThj/pM pMgvjECaPFpzKBozG0w6Y/GdlcPNpGHJNmHnVzsQXgIEXRitKJxI2Qk4f9BS/1N+khC0 g+LBVW56xZrM1GOKE6Ikpdavrr3qDlsynnJSWdcmLHAVJtbGPB+Jr/jCdZC3qQ6+red1 kvCLAlxQ5LPx8zk9v+eEltaClfKU9GswSuJRmRbdNWO6rkbSnfTqlg/O+JR0/sc1QWig Kh7sxrH+Ghil2mrKS48oq7M3Cadxd0HbqGUNXtJ8PHva5Gn6z+MReFPeKYkT6YnP1FWy 3Lug== 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:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=EhZ2SPDHce6H4Ye8wzeRpMx2FVhxeEdFa1K8/4ZmlqQ=; b=bS79I5dGymwgNRVTfxAlBw3GzQX8n9auD/NegojKug9Gavvx7/QywteRQEB860v6CM uUWy2Bu2kfFNsYXEmTBZxWB/jmpgaTysm4KddZYlJmNMM9QEXndHIZ5yYNoFBtzf9IcF RDEEyfmd/RY+6t2yO7g1/lvU8a7K70ryrI37TmN1d3K5Bz7LHSDKFIpfeWYAvXvutCWQ uAe4Vv1V9O1cZ/UNTAbjzAXeLrpXfe7VU8oHNP2g5Im2O+I4zX6VIB5yMjVAjjBH5rg8 vwXiBbSFEhAZi6hZWnlDL9ZdgO7v3V/8x4uyDS3XU1lkjNmsShe0P9gCrtiZKxdrZC0v JFSA== X-Gm-Message-State: AOAM533xT6LMiVk2kJv3jfzw7QHmOuSPAYzEI0XLYmfrRZR++ZAOfqaa QoZlogfGamMF7vKPyHBZxeFinvZGbHA= X-Google-Smtp-Source: ABdhPJw6PFEltgzxaR5Uxv97IbF9XqOebrC+2kUXVslPq/zr99RoA5v3xV/QtDNbA1/IRg8O1U8PnQ== X-Received: by 2002:a5d:5305:: with SMTP id e5mr21027504wrv.243.1629827983150; Tue, 24 Aug 2021 10:59:43 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id l2sm3008997wme.28.2021.08.24.10.59.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Aug 2021 10:59:42 -0700 (PDT) In-Reply-To: <871r6ki6aw.fsf@mail.linkov.net> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212564 Archived-At: This is a multi-part message in MIME format. --------------731E6E4EEEFB597FE81CAC05 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 23.08.2021 19:02, Juri Linkov wrote: >>> We could add an option, at the very least. >> An option to display the first match right away will be most >> appreciated, thanks. > Like compilation-auto-jump-to-first-error. So we even have a precedent, very good. Could you both check out the attached patch? Together with (setq xref-auto-jump-to-first-definition t) Questions for feedback: 1. Does the new behavior work okay window management-wise (it does occupy +1 window, after all)? 2. Should this setting also extend to other commands like xref-find-references? Asking for personal preferences here. --------------731E6E4EEEFB597FE81CAC05 Content-Type: text/x-patch; charset=UTF-8; name="xref-auto-jump-to-first-definition.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xref-auto-jump-to-first-definition.diff" diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index d004a0c32c..ca055a36af 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -416,6 +416,12 @@ xref-after-update-hook :version "28.1" :package-version '(xref . "1.0.4")) +(defcustom xref-auto-jump-to-first-definition nil + "If non-nil, `xref-find-definitions' always jumps to the first result." + :type 'boolean + :version "28.1" + :package-version '(xref . "1.2.0")) + (defvar xref--marker-ring (make-ring xref-marker-ring-length) "Ring of markers to implement the marker stack.") @@ -1060,19 +1066,30 @@ xref-revert-buffer (error-message-string err) 'face 'error))))))) +(defun xref--auto-jump-first (buf) + (select-window (get-buffer-window buf)) + (goto-char (point-min)) + (xref-next-line-no-show) + (xref-goto-xref)) + (defun xref-show-definitions-buffer (fetcher alist) "Show the definitions list in a regular window. When only one definition found, jump to it right away instead." - (let ((xrefs (funcall fetcher))) + (let ((xrefs (funcall fetcher)) + buf) (cond ((not (cdr xrefs)) (xref-pop-to-location (car xrefs) (assoc-default 'display-action alist))) (t - (xref--show-xref-buffer fetcher - (cons (cons 'fetched-xrefs xrefs) - alist)))))) + (setq buf + (xref--show-xref-buffer fetcher + (cons (cons 'fetched-xrefs xrefs) + alist))) + (when (assoc-default 'auto-jump alist) + (xref--auto-jump-first buf)) + buf)))) (define-obsolete-function-alias 'xref--show-defs-buffer #'xref-show-definitions-buffer "28.1") @@ -1088,7 +1105,8 @@ xref-show-definitions-buffer-at-bottom ;; XXX: Make percentage customizable maybe? (max-height (/ (window-height) 2)) (size-fun (lambda (window) - (fit-window-to-buffer window max-height)))) + (fit-window-to-buffer window max-height))) + buf) (cond ((not (cdr xrefs)) (xref-pop-to-location (car xrefs) @@ -1101,7 +1119,10 @@ xref-show-definitions-buffer-at-bottom (pop-to-buffer (current-buffer) `(display-buffer-in-direction . ((direction . below) (window-height . ,size-fun)))) - (current-buffer)))))) + (setq buf (current-buffer))) + (when (assoc-default 'auto-jump alist) + (xref--auto-jump-first buf)) + buf)))) (define-obsolete-function-alias 'xref--show-defs-buffer-at-bottom #'xref-show-definitions-buffer-at-bottom "28.1") @@ -1236,7 +1257,8 @@ xref--show-defs (xref--push-markers) (funcall xref-show-definitions-function xrefs `((window . ,(selected-window)) - (display-action . ,display-action)))) + (display-action . ,display-action) + (auto-jump . ,xref-auto-jump-to-first-definition)))) (defun xref--push-markers () (unless (region-active-p) (push-mark nil t)) --------------731E6E4EEEFB597FE81CAC05--