From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#50552: 28.0.50; Add context-menu-occur Date: Sun, 12 Sep 2021 19:09:25 +0000 Message-ID: <87a6khd316.fsf@posteo.net> References: <87ilz5d9a1.fsf@posteo.net> <87o88xu13p.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2829"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50552@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 12 21:10:12 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 1mPUrj-0000XX-KL for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Sep 2021 21:10:11 +0200 Original-Received: from localhost ([::1]:47644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPUrh-00073U-L9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Sep 2021 15:10:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPUra-00073L-1X for bug-gnu-emacs@gnu.org; Sun, 12 Sep 2021 15:10:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mPUrZ-0004ZA-Pb for bug-gnu-emacs@gnu.org; Sun, 12 Sep 2021 15:10:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mPUrZ-0000WS-Hm for bug-gnu-emacs@gnu.org; Sun, 12 Sep 2021 15:10:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Sep 2021 19:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50552 X-GNU-PR-Package: emacs Original-Received: via spool by 50552-submit@debbugs.gnu.org id=B50552.16314737771973 (code B ref 50552); Sun, 12 Sep 2021 19:10:01 +0000 Original-Received: (at 50552) by debbugs.gnu.org; 12 Sep 2021 19:09:37 +0000 Original-Received: from localhost ([127.0.0.1]:43564 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mPUrB-0000Vl-3S for submit@debbugs.gnu.org; Sun, 12 Sep 2021 15:09:37 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:48867) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mPUr7-0000VV-Kr for 50552@debbugs.gnu.org; Sun, 12 Sep 2021 15:09:35 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 45C2C240101 for <50552@debbugs.gnu.org>; Sun, 12 Sep 2021 21:09:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1631473767; bh=WQB9vDSfpU/3ryTYw1M5P20/ppUuf19WmBu1vGOBn0U=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=MJNsWAWK4/GUPWZaX3UlYaFSDjfGFnWpAZKFTjC+j5KG2AkBg4UM+MBM/d++I84C/ cR5oyGgn2DfHgM1+LeTJYgSb2MHtgZgD8r5fkZg5yObKgQj4uiPad+clfA2FZSvMAi /rC8ajtlADKFwGq7VignqTLbwGw+l3m7O5S9ZZ6U/GnJ0kqqIlA3gqlO3uWwNrxbIs a0AtXm5znaJvDCc4TxnOGPNgylwnHVkXz+OfBvmf5gTECcHoQObg2h7ipOUjAIb5cT 40IQfPUg+tSV7C8PdyNdZaA7vYWhiqTl+7/RJAw8mkUuBUirIlMe3oMDv7IzlKlJaT Vpv6EtJ1LoUKQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4H6zgV36Wdz6tm5; Sun, 12 Sep 2021 21:09:26 +0200 (CEST) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=mutual; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB In-Reply-To: <87o88xu13p.fsf@mail.linkov.net> (Juri Linkov's message of "Sun, 12 Sep 2021 20:59:06 +0300") 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:214156 Archived-At: --=-=-= Content-Type: text/plain Juri Linkov writes: >> the below patch adds the commands occur-word-at-mouse and >> occur-symbol-at-mouse, and a function for context-menu-mode to occur >> words or symbols where the context menu was invoked. >> >> Would there be any interest in adding such a functionality? > > Thanks. There is a new function 'thing-at-mouse' with a new arg 'click' > added today that you can use instead of 'thing-at-point'. > You can see an example in lisp/net/dictionary.el. I see, but I wonder why dictionary.el directly manipulates context-menu-functions with add-hook. >> diff --git a/lisp/mouse.el b/lisp/mouse.el >> index 7d3ed9a0e4..3590e27e3e 100644 >> --- a/lisp/mouse.el >> +++ b/lisp/mouse.el >>[...] >> +(defun context-menu-occur (menu) > > The default set of context menus in mouse.el contains only menus > created from the existing non-context menus. All new context menus > should be added to their respective packages. So please move > context-menu-occur to replace.el. > > Another example prog-context-menu in lisp/progmodes/prog-mode.el also > demonstrates how context menus should belong to the package where they > are used. And prog-context-menu is similar to context-menu-occur, > so it should have the name prefix of the package: occur-context-menu. Ok, no problem. This should do it: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-occur-related-context-menu-operations.patch >From 77c080476a6e64ab9ae5717e75c2358d3e8d20a7 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sun, 12 Sep 2021 21:02:46 +0200 Subject: [PATCH] Add occur-related context-menu operations * replace.el (occur-word-at-mouse): Add new command (occur-symbol-at-mouse): Add new command (occur-context-menu): Add new function --- lisp/replace.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lisp/replace.el b/lisp/replace.el index 69bdfe1331..e8ca3fac80 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2367,6 +2367,31 @@ occur-context-lines ;; And the second element is the list of context after-lines. (if (> nlines 0) after-lines)))) +(defun occur-word-at-mouse (event) + "Display an occur buffer for the word at EVENT." + (interactive "e") + (occur (thing-at-mouse event 'word t))) + +(defun occur-symbol-at-mouse (event) + "Display an occur buffer for the symbol at EVENT." + (interactive "e") + (occur (thing-at-mouse event 'symbol t))) + +(defun occur-context-menu (menu click) + "Populate MENU with occur commands for CLICK. +To be added to `context-menu-functions'." + (let ((word (thing-at-mouse click 'word)) + (sym (thing-at-mouse click 'symbol))) + (when (or word sym) + (define-key-after menu [occur-separator] menu-bar-separator) + (when word + (define-key-after menu [occur-word-at-mouse] + '(menu-item "Occur Word" occur-word-at-mouse))) + (when sym + (define-key-after menu [occur-symbol-at-mouse] + '(menu-item "Occur Symbol" occur-symbol-at-mouse))))) + menu) + ;; It would be nice to use \\[...], but there is no reasonable way ;; to make that display both SPC and Y. -- 2.30.2 --=-=-= Content-Type: text/plain To keep in line with prog-context-menu and context-menu-dictionary, I also removed the modification of context-menu-functions's :type. -- Philip Kaludercic --=-=-=--