all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#52973: Adding a few context-menu-mode commands
@ 2022-01-03  8:34 Philip Kaludercic
  2022-01-03 12:45 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 75+ messages in thread
From: Philip Kaludercic @ 2022-01-03  8:34 UTC (permalink / raw)
  To: 52973

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]


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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-context-menu-mode-support-for-man-pages.patch --]
[-- Type: text/x-patch, Size: 1496 bytes --]

From 17cd2634df3f71155efa5b9e534850f473b5b05e Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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)
+
 \f
 ;; Init the man package variables, if not already done.
 (Man-init-defvars)
-- 
2.34.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Implement-context-menu-mode-support-for-hi-lock.patch --]
[-- Type: text/x-patch, Size: 1342 bytes --]

From d08f6ef980b1e6464af112f692cfdaed1a6d7256 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-Add-command-to-invoke-a-search-engine.patch --]
[-- Type: text/x-patch, Size: 2295 bytes --]

From c5fbec3e04c5e4ef641ff8f99d9c2a58f3c8a770 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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) "+")))))
+
 \f
 ;;; Bindings for mouse commands.
 
-- 
2.34.0


[-- Attachment #5: Type: text/plain, Size: 24 bytes --]


-- 
	Philip Kaludercic

^ permalink raw reply related	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2022-01-25 12:24 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-03  8:34 bug#52973: Adding a few context-menu-mode commands Philip Kaludercic
2022-01-03 12:45 ` Eli Zaretskii
2022-01-03 13:52   ` Philip Kaludercic
2022-01-03 14:32     ` Eli Zaretskii
2022-01-03 17:23       ` Philip Kaludercic
2022-01-03 17:36         ` Eli Zaretskii
2022-01-03 21:17         ` Juri Linkov
2022-01-04 12:26           ` Eli Zaretskii
2022-01-04 17:46             ` Juri Linkov
2022-01-04 20:01               ` Eli Zaretskii
2022-01-04 20:08                 ` Philip Kaludercic
2022-01-04 20:15                   ` Eli Zaretskii
2022-01-05 19:09                     ` Juri Linkov
2022-01-05 19:29                       ` Eli Zaretskii
2022-01-05 20:57                         ` Juri Linkov
2022-01-06  6:54                           ` Eli Zaretskii
2022-01-06  8:20                             ` Juri Linkov
2022-01-06  9:10                               ` Eli Zaretskii
2022-01-03 21:12 ` Juri Linkov
2022-01-04 19:39   ` Philip Kaludercic
2022-01-05 18:58     ` Juri Linkov
2022-01-05 20:14       ` Philip Kaludercic
2022-01-06  8:17         ` Juri Linkov
2022-01-06 18:59           ` Philip Kaludercic
2022-01-06 20:03             ` Juri Linkov
2022-01-06 20:32               ` Eli Zaretskii
2022-01-06 20:35                 ` Juri Linkov
2022-01-07  6:38                   ` Eli Zaretskii
2022-01-07  6:46                     ` Lars Ingebrigtsen
2022-01-07  8:20                       ` Eli Zaretskii
2022-01-07  8:29                     ` Philip Kaludercic
2022-01-07  8:37                       ` Eli Zaretskii
2022-01-08 18:30                         ` Juri Linkov
2022-01-08 18:44                           ` Eli Zaretskii
2022-01-08 19:01                             ` Philip Kaludercic
2022-01-08 19:10                               ` Eli Zaretskii
2022-01-08 19:39                                 ` Philip Kaludercic
2022-01-08 20:09                                   ` Eli Zaretskii
2022-01-12  6:16                           ` Lars Ingebrigtsen
2022-01-12 13:12                             ` Eli Zaretskii
2022-01-12 17:16                               ` Juri Linkov
2022-01-12 17:36                                 ` Eli Zaretskii
2022-01-12 18:03                                   ` Juri Linkov
2022-01-12 19:27                                     ` Eli Zaretskii
2022-01-12 19:41                                       ` Juri Linkov
2022-01-12 19:53                                         ` Eli Zaretskii
2022-01-12 20:00                                           ` Juri Linkov
2022-01-12 20:42                                             ` Eli Zaretskii
2022-01-13  8:39                                               ` Juri Linkov
2022-01-13 10:06                                                 ` Eli Zaretskii
2022-01-13  6:03                                 ` Lars Ingebrigtsen
2022-01-13  8:35                                   ` Juri Linkov
2022-01-13  8:53                                     ` Lars Ingebrigtsen
2022-01-13  9:10                                       ` Juri Linkov
2022-01-13  9:23                                         ` Lars Ingebrigtsen
2022-01-13 10:11                                         ` Eli Zaretskii
2022-01-13  8:54                                   ` Eli Zaretskii
2022-01-06 20:19             ` Lars Ingebrigtsen
2022-01-06 20:32               ` Juri Linkov
2022-01-22 19:39             ` Philip Kaludercic
2022-01-23  9:08               ` Juri Linkov
2022-01-23 12:09                 ` Philip Kaludercic
2022-01-23 12:13                   ` Lars Ingebrigtsen
2022-01-23 16:30                     ` Philip Kaludercic
2022-01-23 18:06                       ` Juri Linkov
2022-01-23 19:49                         ` Philip Kaludercic
2022-01-23 20:04                           ` Juri Linkov
2022-01-24  9:14                       ` Lars Ingebrigtsen
2022-01-25 12:06                         ` Philip Kaludercic
2022-01-25 12:24                           ` Lars Ingebrigtsen
2022-01-04 20:09   ` Philip Kaludercic
2022-01-05 19:03     ` Juri Linkov
2022-01-14  8:52 ` Lars Ingebrigtsen
2022-01-14 14:33   ` Philip Kaludercic
2022-01-15  8:07     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.