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: Tue, 14 Sep 2021 20:45:44 +0000 Message-ID: <87lf3yj37r.fsf@posteo.net> References: <87ilz5d9a1.fsf@posteo.net> <87o88xu13p.fsf@mail.linkov.net> <87a6khd316.fsf@posteo.net> <8735q8g9dj.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="2594"; 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 Tue Sep 14 23:02:11 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 1mQFZC-0000Q7-J3 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Sep 2021 23:02:10 +0200 Original-Received: from localhost ([::1]:53752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQFZB-00084s-7N for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Sep 2021 17:02:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQFJb-0003gZ-2x for bug-gnu-emacs@gnu.org; Tue, 14 Sep 2021 16:46:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQFJa-0001py-M1 for bug-gnu-emacs@gnu.org; Tue, 14 Sep 2021 16:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mQFJa-0002Bd-Co for bug-gnu-emacs@gnu.org; Tue, 14 Sep 2021 16:46:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87ilz5d9a1.fsf@posteo.net> Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Sep 2021 20:46:02 +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.16316523558389 (code B ref 50552); Tue, 14 Sep 2021 20:46:02 +0000 Original-Received: (at 50552) by debbugs.gnu.org; 14 Sep 2021 20:45:55 +0000 Original-Received: from localhost ([127.0.0.1]:50291 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQFJS-0002BF-Ql for submit@debbugs.gnu.org; Tue, 14 Sep 2021 16:45:55 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:56647) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQFJP-0002B0-W9 for 50552@debbugs.gnu.org; Tue, 14 Sep 2021 16:45:53 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 990D5240028 for <50552@debbugs.gnu.org>; Tue, 14 Sep 2021 22:45:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1631652345; bh=5+CYMoLPLxlPVg91FezbaTwX780wuWW6TeuXvDRnboM=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=GIm7GzP+dbpFsfsTsek6NMatjSEvTgKzZ9tvPjixhct5D7xZ18jp7clUZH828E6fG tyvapBWBEiqQSlFqbrqs1GdbAqVDnPpt6nzEkMIbuPyIjHNaj8ToBW3d8XahODaVyz fxFEUnNqV7vp0EQSOKs0C+xDO35zGaD6j1iOI226ENVHXsh+3bJTKDpO2cuVLXJ+kE /2QAAler+1IiDoQj9igs54ImBpzDzBrS079aI0T5TcGmIVKTi2Yt6RlIjqS/+xtZ5m JNVc/gEUjfMdw8kuwoGkeqUJaPHHjFe2i/rnR6+crEX/onilzdpCMcuK8rz+VVEJo0 8MT7vrsEOkdCg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4H8Fjh4zj9z6tmD; Tue, 14 Sep 2021 22:45:44 +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 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:214342 Archived-At: --=-=-= Content-Type: text/plain Sorry for the delay, 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. > > The reasoning was the following: by default, dictionary.el is not loaded, > so its context menu item is not used. But when the user wants to use > dictionary.el and explicitly loads it, then automatically provide also > its context menu item. > > This reasoning can't be applied to occur, because occur in replace.el > is pre-loaded. > >> +(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))) > > Thanks, this is almost perfect. What remains to do is to create > a regexp that matches only words/symbols. You can see how > 'isearch-occur' converts a string to a word/symbol regexp by using > '(funcall isearch-regexp-function isearch-string)' before calling 'occur'. Ok, I've tried it here: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-occur-related-context-menu-operations1.patch >From 78a0be097333b1619c5d25b4b96facb703fb8ceb 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 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lisp/replace.el b/lisp/replace.el index 69bdfe1331..d652f37e4d 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2367,6 +2367,43 @@ 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") + (let ((word (thing-at-mouse event 'word t))) + (occur (cond + ((functionp isearch-regexp-function) + (funcall isearch-regexp-function word)) + (isearch-regexp-function (word-search-regexp word)) + (isearch-regexp word) + (t (regexp-quote word)))))) + +(defun occur-symbol-at-mouse (event) + "Display an occur buffer for the symbol at EVENT." + (interactive "e") + (let ((symbol (thing-at-mouse event 'symbol t))) + (occur (cond + ((functionp isearch-regexp-function) + (funcall isearch-regexp-function symbol)) + (isearch-regexp-function (word-search-regexp symbol)) + (isearch-regexp symbol) + (t (regexp-quote symbol)))))) + +(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 And here another version with word/symbol-start/end matching: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-occur-related-context-menu-operations.patch >From 3cde46258915dd7f56942fd1decba397d30f809b 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 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lisp/replace.el b/lisp/replace.el index 69bdfe1331..8c50a6ad4c 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2367,6 +2367,50 @@ 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") + (let ((word (thing-at-mouse event 'word t))) + (occur (concat + "\\<" + (cond + ((functionp isearch-regexp-function) + (funcall isearch-regexp-function word)) + (isearch-regexp-function (word-search-regexp word)) + (isearch-regexp word) + (t (regexp-quote word))) + "\\>")))) + +(defun occur-symbol-at-mouse (event) + "Display an occur buffer for the symbol at EVENT." + (interactive "e") + (let ((symbol (thing-at-mouse event 'symbol t))) + (occur + (concat + "\\_<" + (cond + ((functionp isearch-regexp-function) + (funcall isearch-regexp-function symbol)) + (isearch-regexp-function (word-search-regexp symbol)) + (isearch-regexp symbol) + (t (regexp-quote symbol))) + "\\_>")))) + +(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. > > I guess this is the right thing since the user still can add > 'occur-context-menu' as a function name to 'context-menu-functions'. Makes sense. -- Philip Kaludercic --=-=-=--