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#52973: Adding a few context-menu-mode commands Date: Mon, 03 Jan 2022 08:34:18 +0000 Message-ID: <87o84tp69h.fsf@posteo.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="19132"; mail-complaints-to="usenet@ciao.gmane.io" To: 52973@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 03 09:38:12 2022 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 1n4Ir5-0004nW-KO for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Jan 2022 09:38:11 +0100 Original-Received: from localhost ([::1]:50714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n4Ir4-0000ON-Dk for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Jan 2022 03:38:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4Iqx-0000O9-5h for bug-gnu-emacs@gnu.org; Mon, 03 Jan 2022 03:38:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4Iqw-0000YA-TF for bug-gnu-emacs@gnu.org; Mon, 03 Jan 2022 03:38:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n4Iqw-0007aJ-Ni for bug-gnu-emacs@gnu.org; Mon, 03 Jan 2022 03:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 03 Jan 2022 08:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52973 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.164119902829067 (code B ref -1); Mon, 03 Jan 2022 08:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Jan 2022 08:37:08 +0000 Original-Received: from localhost ([127.0.0.1]:34072 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n4Iq4-0007Yk-3Z for submit@debbugs.gnu.org; Mon, 03 Jan 2022 03:37:08 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:52360) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n4Ipz-0007YY-5v for submit@debbugs.gnu.org; Mon, 03 Jan 2022 03:37:06 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4Ipy-0000Ls-UR for bug-gnu-emacs@gnu.org; Mon, 03 Jan 2022 03:37:02 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:39869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4Ipw-0000SC-9Z for bug-gnu-emacs@gnu.org; Mon, 03 Jan 2022 03:37:02 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id E5A91240104 for ; Mon, 3 Jan 2022 09:36:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1641199017; bh=yXjX+coZi1dpSnbqlH2gtaU2AKBbaI7KqdzmTxkmcM8=; h=From:To:Subject:Date:Autocrypt:From; b=Abj7HMJiF0zumELIz3sn5Qm21Ff5GpEaH6gY0WVXx8m0/txwx2T/yPKFQH0PWAxOc /EJai652jWNwqvFbfQj+/sA2kQO/SX7M6ISYwR6mvv3T/x6rUuTuVhCAwB0Waawh7C Tjt6HQNpHTjsjc5uPmaB/FvBAG9S9mBU5NyHJqSgT8Gz87A1oqnTjhupd9WeB8mK34 FhAUx9pVIf6CQTbjOT4nw/Csp/LsBMHqqpasBdmhzBHkAhGvnsbuZJqbbwfxrflfB9 naAADenU0V/bA8yYmtiT+0RBpkSVyEPdZnf7XmSO/bhWdAurRyI0wIY1KgK9uqGJAY 9yul5/NoMViOw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4JS8HY2Qmpz9rxD for ; Mon, 3 Jan 2022 09:36:57 +0100 (CET) Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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:223580 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Hi, I am attaching a few patches adding a few features for context-menu-mode, that I mentioned and explained here: https://ruzkuku.com/texts/emacs-mouse.html. Would it be OK to add these to Emacs itself? In GNU Emacs 29.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0) of 2021-12-25 built on viero Repository revision: f9d518bc2f333e03d5e7c4e935b08fbe19f33c5b Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Implement-context-menu-mode-support-for-man-pages.patch >From 17cd2634df3f71155efa5b9e534850f473b5b05e Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Fri, 31 Dec 2021 12:37:50 +0100 Subject: [PATCH 1/3] Implement context-menu-mode support for man pages * man.el (Man-at-mouse): Add new command (Man-context-menu): Add new function --- lisp/man.el | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lisp/man.el b/lisp/man.el index fff31baa5f..2f956525d3 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -1976,6 +1976,29 @@ Man-bookmark-jump (bookmark-default-handler `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bookmark))))) +;;; Mouse support +(defun Man-at-mouse (e) + "Open man manual at point." + (interactive "e") + (save-excursion + (mouse-set-point e) + (man (Man-default-man-entry)))) + +(defun Man-context-menu (menu click) + "Populate MENU with commands that open a man page at point." + (save-excursion + (mouse-set-point click) + (when (save-excursion + (skip-syntax-backward "^ ") + (and (looking-at + "[[:space:]]*\\([[:alnum:]_-]+([[:alnum:]]+)\\)") + (match-string 1))) + (define-key-after menu [man-separator] menu-bar-separator) + (define-key-after menu [man-at-mouse] + '(menu-item "Open man page" man-at-mouse + :help "Open man page around mouse click")))) + menu) + ;; Init the man package variables, if not already done. (Man-init-defvars) -- 2.34.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Implement-context-menu-mode-support-for-hi-lock.patch >From d08f6ef980b1e6464af112f692cfdaed1a6d7256 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Fri, 31 Dec 2021 12:45:52 +0100 Subject: [PATCH 2/3] Implement context-menu-mode support for hi-lock * hi-lock.el (hi-lock-symbol-at-mouse): Add new command (hi-lock-context-menu): Add new function --- lisp/hi-lock.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index 7d126cb558..5d99fb5288 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -854,6 +854,25 @@ hi-lock-unload-function ;; continue standard unloading nil) +;;; Mouse support +(defun hi-lock-symbol-at-mouse (event) + "Highlight symbol at mouse click EVENT." + (interactive "e") + (save-excursion + (mouse-set-point event) + (highlight-symbol-at-point))) + +(defun hi-lock-context-menu (menu click) + "Populate MENU with a menu item to highlight symbol at CLICK." + (save-excursion + (mouse-set-point click) + (when (symbol-at-point) + (define-key-after menu [highlight-search-separator] menu-bar-separator) + (define-key-after menu [highlight-search-mouse] + '(menu-item "Highlight Symbol" highlight-symbol-at-mouse + :help "Highlight symbol at point")))) + menu) + (provide 'hi-lock) ;;; hi-lock.el ends here -- 2.34.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-Add-command-to-invoke-a-search-engine.patch >From c5fbec3e04c5e4ef641ff8f99d9c2a58f3c8a770 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Fri, 31 Dec 2021 15:21:13 +0100 Subject: [PATCH 3/3] Add command to invoke a search engine * mouse.el (context-menu-online-search): Add new function (eww-search-prefix): Declare variable from eww.el (mouse-online-search-at-point): Add new command --- lisp/mouse.el | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lisp/mouse.el b/lisp/mouse.el index 11fdd3f639..edf4504bdd 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -523,6 +523,16 @@ context-menu-ffap :help "Find file or URL from text around mouse click")))) menu) +(defun context-menu-online-search (menu click) + "Populate MENU with command to search online." + (save-excursion + (mouse-set-point click) + (define-key-after menu [online-search-separator] menu-bar-separator) + (define-key-after menu [online-search-at-mouse] + '(menu-item "Online search" mouse-online-search-at-point + :help "Search for region or word online"))) + menu) + (defvar context-menu-entry `(menu-item ,(purecopy "Context Menu") ,(make-sparse-keymap) :filter ,(lambda (_) (context-menu-map))) @@ -3209,6 +3219,26 @@ mouse-drag-and-drop-region (with-current-buffer (window-buffer window) (setq cursor-type (nth 3 state))))))) +(defvar eww-search-prefix) +(defun mouse-online-search-at-point (event) + "Query an online search engine at EVENT. +If a region is active, the entire region will be sent, otherwise +the symbol at point will be used. This command uses EWW's +default search engine, as configured by `eww-search-prefix'." + (interactive "e") + (require 'eww) + (let ((query (if (use-region-p) + (buffer-substring (region-beginning) + (region-end)) + (save-excursion + (mouse-set-point event) + (thing-at-point 'symbol))))) + (unless query + (user-error "Nothing to search for")) + (browse-url (concat + eww-search-prefix + (mapconcat #'url-hexify-string (split-string query) "+"))))) + ;;; Bindings for mouse commands. -- 2.34.0 --=-=-= Content-Type: text/plain -- Philip Kaludercic --=-=-=--