* [PATCH] Turn org-mouse features into minor-modes
@ 2024-12-26 13:14 Visuwesh
2024-12-27 8:25 ` Ihor Radchenko
0 siblings, 1 reply; 6+ messages in thread
From: Visuwesh @ 2024-12-26 13:14 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 432 bytes --]
[ Resending it as it seems like it never reached the mailing list. ]
To make loading org-mouse less annoying for all, I was thinking of
introducing minor-modes like in the attached patch. If this approach is
acceptable, I will get to calling out the change in NEWS and updating
the manual if required. We could also add a `add-hook' call to turn on
the minor-mode automatically to preserve the old behaviour if required.
WDYT?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-mouse-Make-it-possible-to-turn-on-and-off-the-fe.patch --]
[-- Type: text/x-diff, Size: 7894 bytes --]
From a4162d9e9204735ecd6ac864ed467e87362ace32 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 23 Dec 2024 12:41:13 +0530
Subject: [PATCH] org-mouse: Make it possible to turn on and off the feature
Introduce new minor-modes `org-mouse-minor-mode' and
`org-mouse-agenda-minor-mode' to make it easy to turn on/off the mouse
support.
* lisp/org-mouse.el (org-mode-hook, org-agenda-mode-hook): Remove the
lambda which makes it unnecessarily difficult to reverse the effect of
loading this file.
(org-mouse--old-mouse-map): New variable to hold the original
definition of org-mouse-map.
(org-mouse-minor-mode-map, org-mouse-minor-mode)
(org-mouse-agenda-minor-mode-map, org-mouse-agenda-minor-mode): Add
new minor-modes to easily toggle the mouse features on and off per
buffer.
---
lisp/org-mouse.el | 120 ++++++++++++++++++++++++++--------------------
1 file changed, 68 insertions(+), 52 deletions(-)
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index 7f85653f2..eb4355d2f 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -866,48 +866,59 @@ (defun org-mouse-down-mouse (event)
;; events to `mouse-drag-region'.
(put 'org-mouse-down-mouse 'ignored-mouse-command t)
-(add-hook 'org-mode-hook
- (lambda ()
- (setq org-mouse-context-menu-function #'org-mouse-context-menu)
-
- (when (memq 'context-menu org-mouse-features)
- (org-defkey org-mouse-map [mouse-3] nil)
- (org-defkey org-mode-map [mouse-3] #'org-mouse-show-context-menu))
- (org-defkey org-mode-map [down-mouse-1] #'org-mouse-down-mouse)
- (when (memq 'context-menu org-mouse-features)
- (org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
- (org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
- (when (memq 'yank-link org-mouse-features)
- (org-defkey org-mode-map [S-mouse-2] #'org-mouse-yank-link)
- (org-defkey org-mode-map [drag-mouse-3] #'org-mouse-yank-link))
- (when (memq 'move-tree org-mouse-features)
- (org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
- (org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start))
-
- (when (memq 'activate-stars org-mouse-features)
- (font-lock-add-keywords
- nil
+(defvar org-mouse-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (org-defkey map [mouse-3] #'org-mouse-show-context-menu)
+ (org-defkey map [down-mouse-1] #'org-mouse-down-mouse)
+ map)
+ "Keymap for `org-mouse-minor-mode'.")
+
+(defvar-local org-mouse--old-mouse-map (copy-keymap org-mouse-map))
+(define-minor-mode org-mouse-minor-mode
+ "Minor mode to enable better mouse support in `org-mode'."
+ :global nil
+ (let ((fl-fun (if org-mouse-minor-mode
+ (lambda (mode kw)
+ (font-lock-add-keywords mode kw t))
+ #'font-lock-remove-keywords)))
+ (setq org-mouse-context-menu-function
+ (and org-mouse-minor-mode #'org-mouse-context-menu))
+ (when org-mouse-minor-mode
+ ;; Without `copy-keymap', later `org-defkey' calls modify the
+ ;; value of keymap `org-mouse--old-mouse-map' holds.
+ (setq org-mouse--old-mouse-map (copy-keymap org-mouse-map)))
+ (setq org-mouse-map (copy-keymap org-mouse--old-mouse-map))
+ (org-defkey org-mouse-minor-mode-map [S-mouse-2] nil)
+ (org-defkey org-mouse-minor-mode-map [drag-mouse-3] nil)
+ (when org-mouse-minor-mode
+ (when (memq 'context-menu org-mouse-features)
+ (org-defkey org-mouse-map [mouse-3] nil)
+ (org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
+ (org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
+ (when (memq 'yank-link org-mouse-features)
+ (org-defkey org-mouse-minor-mode-map [S-mouse-2] #'org-mouse-yank-link)
+ (org-defkey org-mouse-minor-mode-map [drag-mouse-3] #'org-mouse-yank-link))
+ (when (memq 'move-tree org-mouse-features)
+ (org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
+ (org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start)))
+ (when (memq 'activate-stars org-mouse-features)
+ (funcall fl-fun nil
`((,org-outline-regexp
0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
- 'prepend))
- t))
-
- (when (memq 'activate-bullets org-mouse-features)
- (font-lock-add-keywords
- nil
+ 'prepend))))
+ (when (memq 'activate-bullets org-mouse-features)
+ (funcall fl-fun nil
`(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
(1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
- 'prepend)))
- t))
-
- (when (memq 'activate-checkboxes org-mouse-features)
- (font-lock-add-keywords
- nil
+ 'prepend)))))
+ (when (memq 'activate-checkboxes org-mouse-features)
+ (funcall fl-fun nil
`(("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
- (1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))
- t))
-
- (advice-add 'org-open-at-point :around #'org--mouse-open-at-point)))
+ (1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))))
+ (if org-mouse-minor-mode
+ (advice-add 'org-open-at-point :around #'org--mouse-open-at-point)
+ (advice-remove 'org-open-at-point #'org--mouse-open-at-point))
+ (font-lock-flush)))
(defun org--mouse-open-at-point (orig-fun &rest args)
(let ((context (org-context)))
@@ -923,7 +934,6 @@ (defun org-mouse-move-tree-start (_event)
(interactive "e")
(message "Same line: promote/demote, (***):move before, (text): make a child"))
-
(defun org-mouse-make-marker (position)
(with-current-buffer (window-buffer (posn-window position))
(copy-marker (posn-point position))))
@@ -1095,20 +1105,26 @@ (defun org-mouse-get-gesture (event)
(if (< (car startxy) (car endxy)) :right :left)))
- ; (setq org-agenda-mode-hook nil)
-(defvar org-agenda-mode-map)
-(add-hook 'org-agenda-mode-hook
- (lambda ()
- (setq org-mouse-context-menu-function #'org-mouse-agenda-context-menu)
- (org-defkey org-agenda-mode-map [mouse-3] #'org-mouse-show-context-menu)
- (org-defkey org-agenda-mode-map [down-mouse-3] #'org-mouse-move-tree-start)
- (org-defkey org-agenda-mode-map [C-mouse-4] #'org-agenda-earlier)
- (org-defkey org-agenda-mode-map [C-mouse-5] #'org-agenda-later)
- (org-defkey org-agenda-mode-map [drag-mouse-3]
- (lambda (event) (interactive "e")
- (cl-case (org-mouse-get-gesture event)
- (:left (org-agenda-earlier 1))
- (:right (org-agenda-later 1)))))))
+(defvar org-mouse-agenda-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (org-defkey map [mouse-3] #'org-mouse-show-context-menu)
+ (org-defkey map [down-mouse-3] #'org-mouse-move-tree-start)
+ (org-defkey map [C-mouse-4] #'org-agenda-earlier)
+ (org-defkey map [C-mouse-5] #'org-agenda-later)
+ (org-defkey map [drag-mouse-3]
+ (lambda (event) (interactive "e")
+ (cl-case (org-mouse-get-gesture event)
+ (:left (org-agenda-earlier 1))
+ (:right (org-agenda-later 1)))))
+ map)
+ "Keymap for `org-mouse-agenda-minor-mode'.")
+
+(define-minor-mode org-mouse-agenda-minor-mode
+ "Minor mode to enable better mouse support in `org-agenda-mode'."
+ :global nil
+ (setq org-mouse-context-menu-function
+ (and org-mouse-agenda-minor-mode
+ #'org-mouse-agenda-context-menu)))
(provide 'org-mouse)
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Turn org-mouse features into minor-modes
2024-12-26 13:14 [PATCH] Turn org-mouse features into minor-modes Visuwesh
@ 2024-12-27 8:25 ` Ihor Radchenko
2024-12-27 8:35 ` Visuwesh
2025-01-08 4:27 ` Visuwesh
0 siblings, 2 replies; 6+ messages in thread
From: Ihor Radchenko @ 2024-12-27 8:25 UTC (permalink / raw)
To: Visuwesh; +Cc: emacs-orgmode
Visuwesh <visuweshm@gmail.com> writes:
> [ Resending it as it seems like it never reached the mailing list. ]
>
> To make loading org-mouse less annoying for all, I was thinking of
> introducing minor-modes like in the attached patch. If this approach is
> acceptable, I will get to calling out the change in NEWS and updating
> the manual if required. We could also add a `add-hook' call to turn on
> the minor-mode automatically to preserve the old behaviour if required.
> WDYT?
Thanks!
Adding minor modes is indeed a good idea.
Although they should probably be globalized to keep things closer to the
existing behavior.
We do not need to preserve the old behavior - side effects are to be
eradicated even if the cost is introducing a breaking change.
NEWS announcement is good enough.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Turn org-mouse features into minor-modes
2024-12-27 8:25 ` Ihor Radchenko
@ 2024-12-27 8:35 ` Visuwesh
2024-12-27 8:40 ` Ihor Radchenko
2025-01-08 4:27 ` Visuwesh
1 sibling, 1 reply; 6+ messages in thread
From: Visuwesh @ 2024-12-27 8:35 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[வெள்ளி டிசம்பர் 27, 2024] Ihor Radchenko wrote:
> Visuwesh <visuweshm@gmail.com> writes:
>
>> [ Resending it as it seems like it never reached the mailing list. ]
>>
>> To make loading org-mouse less annoying for all, I was thinking of
>> introducing minor-modes like in the attached patch. If this approach is
>> acceptable, I will get to calling out the change in NEWS and updating
>> the manual if required. We could also add a `add-hook' call to turn on
>> the minor-mode automatically to preserve the old behaviour if required.
>> WDYT?
>
> Thanks!
> Adding minor modes is indeed a good idea.
> Although they should probably be globalized to keep things closer to the
> existing behavior.
That would make it hard to toggle the feature on/off on a per-buffer
basis, which was my intention behind using a minor mode. I don't have
strong opinions here so if you think otherwise, I will use a global
minor mode instead. If we go the global route, shall I make it so that
activating it would enable mouse support for both org-mode and
org-agenda-mode?
> We do not need to preserve the old behavior - side effects are to be
> eradicated even if the cost is introducing a breaking change.
Thanks, this will save some headache.
> NEWS announcement is good enough.
Noted.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Turn org-mouse features into minor-modes
2024-12-27 8:35 ` Visuwesh
@ 2024-12-27 8:40 ` Ihor Radchenko
0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2024-12-27 8:40 UTC (permalink / raw)
To: Visuwesh; +Cc: emacs-orgmode
Visuwesh <visuweshm@gmail.com> writes:
>> Although they should probably be globalized to keep things closer to the
>> existing behavior.
>
> That would make it hard to toggle the feature on/off on a per-buffer
> basis, which was my intention behind using a minor mode. I don't have
> strong opinions here so if you think otherwise, I will use a global
> minor mode instead. If we go the global route, shall I make it so that
> activating it would enable mouse support for both org-mode and
> org-agenda-mode?
I did not say global. I said globalized. Globalized minor mode will
provide 2 commands - one for normal minor mode (foo-mode) and one
for global version (global-foo-mode). See `define-globalized-minor-mode'.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Turn org-mouse features into minor-modes
2024-12-27 8:25 ` Ihor Radchenko
2024-12-27 8:35 ` Visuwesh
@ 2025-01-08 4:27 ` Visuwesh
2025-01-08 7:13 ` Visuwesh
1 sibling, 1 reply; 6+ messages in thread
From: Visuwesh @ 2025-01-08 4:27 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]
[வெள்ளி டிசம்பர் 27, 2024] Ihor Radchenko wrote:
> Visuwesh <visuweshm@gmail.com> writes:
>
>> [ Resending it as it seems like it never reached the mailing list. ]
>>
>> To make loading org-mouse less annoying for all, I was thinking of
>> introducing minor-modes like in the attached patch. If this approach is
>> acceptable, I will get to calling out the change in NEWS and updating
>> the manual if required. We could also add a `add-hook' call to turn on
>> the minor-mode automatically to preserve the old behaviour if required.
>> WDYT?
>
> Thanks!
> Adding minor modes is indeed a good idea.
> Although they should probably be globalized to keep things closer to the
> existing behavior.
>
> We do not need to preserve the old behavior - side effects are to be
> eradicated even if the cost is introducing a breaking change.
> NEWS announcement is good enough.
I've now attached a patch to this effect. I hope the NEWS entry is
legible.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-mouse-Make-it-possible-to-turn-on-and-off-the-fe.patch --]
[-- Type: text/x-diff, Size: 9109 bytes --]
From 99b9d8aa0b5ad14a015fdf7f7bfdc22eb804dde9 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 23 Dec 2024 12:41:13 +0530
Subject: [PATCH] org-mouse: Make it possible to turn on and off the feature
Introduce new minor-modes `org-mouse-minor-mode' and
`org-mouse-agenda-minor-mode' to make it easy to turn on/off the mouse
support.
* lisp/org-mouse.el (org-mode-hook, org-agenda-mode-hook): Remove the
lambda which makes it unnecessarily difficult to reverse the effect of
loading this file.
(org-mouse--old-mouse-map): New variable to hold the original
definition of org-mouse-map.
(org-mouse-minor-mode-map, org-mouse-minor-mode)
(org-mouse-agenda-minor-mode-map, org-mouse-agenda-minor-mode): Add
new minor-modes to easily toggle the mouse features on and off per
buffer.
* etc/ORG-NEWS: Announce the breaking change.
Link: https://list.orgmode.org/87seqad1sl.fsf@gmail.com
---
etc/ORG-NEWS | 15 ++++++
lisp/org-mouse.el | 120 ++++++++++++++++++++++++++--------------------
2 files changed, 83 insertions(+), 52 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c9bb192de..99d5b6b58 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -18,6 +18,21 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
# require user action for most Org mode users.
# Sorted from most important to least important.
+*** ~org-mouse~ is no longer activated by default by anymore
+
+To follow Emacs [[info:elisp#Coding Conventions][coding conventions]] and to avoid confusion of users who
+accidentally get ~org-mouse~ autoloaded due to help completion, the
+library does not modify ~org-mode-map~ and other variables during
+loading anymore.
+
+To enable the ~org-mouse~ features, the new minor-modes
+~org-mouse-minor-mode~ and ~org-mouse-agenda-minor-mode~ should be
+enabled.
+
+To turn on the features in all ~org-mode~ and ~org-agenda-mode~
+buffers, you can use the globalized versions
+~global-org-mouse-minor-mode~ and ~global-org-mouse-agenda-minor-mode~.
+
*** You may need to update =org-protocol= bookmarklets for browsers
In Firefox-133, and Firefox-128.5 ESR the previously suggested
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index 928d18d66..33f253fc4 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -866,48 +866,59 @@ (defun org-mouse-down-mouse (event)
;; events to `mouse-drag-region'.
(put 'org-mouse-down-mouse 'ignored-mouse-command t)
-(add-hook 'org-mode-hook
- (lambda ()
- (setq org-mouse-context-menu-function #'org-mouse-context-menu)
-
- (when (memq 'context-menu org-mouse-features)
- (org-defkey org-mouse-map [mouse-3] nil)
- (org-defkey org-mode-map [mouse-3] #'org-mouse-show-context-menu))
- (org-defkey org-mode-map [down-mouse-1] #'org-mouse-down-mouse)
- (when (memq 'context-menu org-mouse-features)
- (org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
- (org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
- (when (memq 'yank-link org-mouse-features)
- (org-defkey org-mode-map [S-mouse-2] #'org-mouse-yank-link)
- (org-defkey org-mode-map [drag-mouse-3] #'org-mouse-yank-link))
- (when (memq 'move-tree org-mouse-features)
- (org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
- (org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start))
-
- (when (memq 'activate-stars org-mouse-features)
- (font-lock-add-keywords
- nil
+(defvar org-mouse-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (org-defkey map [mouse-3] #'org-mouse-show-context-menu)
+ (org-defkey map [down-mouse-1] #'org-mouse-down-mouse)
+ map)
+ "Keymap for `org-mouse-minor-mode'.")
+
+(defvar-local org-mouse--old-mouse-map (copy-keymap org-mouse-map))
+(define-minor-mode org-mouse-minor-mode
+ "Minor mode to enable better mouse support in `org-mode'."
+ :global nil
+ (let ((fl-fun (if org-mouse-minor-mode
+ (lambda (mode kw)
+ (font-lock-add-keywords mode kw t))
+ #'font-lock-remove-keywords)))
+ (setq org-mouse-context-menu-function
+ (and org-mouse-minor-mode #'org-mouse-context-menu))
+ (when org-mouse-minor-mode
+ ;; Without `copy-keymap', later `org-defkey' calls modify the
+ ;; value of keymap `org-mouse--old-mouse-map' holds.
+ (setq org-mouse--old-mouse-map (copy-keymap org-mouse-map)))
+ (setq org-mouse-map (copy-keymap org-mouse--old-mouse-map))
+ (org-defkey org-mouse-minor-mode-map [S-mouse-2] nil)
+ (org-defkey org-mouse-minor-mode-map [drag-mouse-3] nil)
+ (when org-mouse-minor-mode
+ (when (memq 'context-menu org-mouse-features)
+ (org-defkey org-mouse-map [mouse-3] nil)
+ (org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
+ (org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
+ (when (memq 'yank-link org-mouse-features)
+ (org-defkey org-mouse-minor-mode-map [S-mouse-2] #'org-mouse-yank-link)
+ (org-defkey org-mouse-minor-mode-map [drag-mouse-3] #'org-mouse-yank-link))
+ (when (memq 'move-tree org-mouse-features)
+ (org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
+ (org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start)))
+ (when (memq 'activate-stars org-mouse-features)
+ (funcall fl-fun nil
`((,org-outline-regexp
0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
- 'prepend))
- t))
-
- (when (memq 'activate-bullets org-mouse-features)
- (font-lock-add-keywords
- nil
+ 'prepend))))
+ (when (memq 'activate-bullets org-mouse-features)
+ (funcall fl-fun nil
`(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
(1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
- 'prepend)))
- t))
-
- (when (memq 'activate-checkboxes org-mouse-features)
- (font-lock-add-keywords
- nil
+ 'prepend)))))
+ (when (memq 'activate-checkboxes org-mouse-features)
+ (funcall fl-fun nil
`(("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
- (1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))
- t))
-
- (advice-add 'org-open-at-point :around #'org--mouse-open-at-point)))
+ (1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))))
+ (if org-mouse-minor-mode
+ (advice-add 'org-open-at-point :around #'org--mouse-open-at-point)
+ (advice-remove 'org-open-at-point #'org--mouse-open-at-point))
+ (font-lock-flush)))
(defun org--mouse-open-at-point (orig-fun &rest args)
(let ((context (org-context)))
@@ -923,7 +934,6 @@ (defun org-mouse-move-tree-start (_event)
(interactive "e")
(message "Same line: promote/demote, (***):move before, (text): make a child"))
-
(defun org-mouse-make-marker (position)
(with-current-buffer (window-buffer (posn-window position))
(copy-marker (posn-point position))))
@@ -1095,20 +1105,26 @@ (defun org-mouse-get-gesture (event)
(if (< (car startxy) (car endxy)) :right :left)))
- ; (setq org-agenda-mode-hook nil)
-(defvar org-agenda-mode-map)
-(add-hook 'org-agenda-mode-hook
- (lambda ()
- (setq org-mouse-context-menu-function #'org-mouse-agenda-context-menu)
- (org-defkey org-agenda-mode-map [mouse-3] #'org-mouse-show-context-menu)
- (org-defkey org-agenda-mode-map [down-mouse-3] #'org-mouse-move-tree-start)
- (org-defkey org-agenda-mode-map [C-mouse-4] #'org-agenda-earlier)
- (org-defkey org-agenda-mode-map [C-mouse-5] #'org-agenda-later)
- (org-defkey org-agenda-mode-map [drag-mouse-3]
- (lambda (event) (interactive "e")
- (cl-case (org-mouse-get-gesture event)
- (:left (org-agenda-earlier 1))
- (:right (org-agenda-later 1)))))))
+(defvar org-mouse-agenda-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (org-defkey map [mouse-3] #'org-mouse-show-context-menu)
+ (org-defkey map [down-mouse-3] #'org-mouse-move-tree-start)
+ (org-defkey map [C-mouse-4] #'org-agenda-earlier)
+ (org-defkey map [C-mouse-5] #'org-agenda-later)
+ (org-defkey map [drag-mouse-3]
+ (lambda (event) (interactive "e")
+ (cl-case (org-mouse-get-gesture event)
+ (:left (org-agenda-earlier 1))
+ (:right (org-agenda-later 1)))))
+ map)
+ "Keymap for `org-mouse-agenda-minor-mode'.")
+
+(define-minor-mode org-mouse-agenda-minor-mode
+ "Minor mode to enable better mouse support in `org-agenda-mode'."
+ :global nil
+ (setq org-mouse-context-menu-function
+ (and org-mouse-agenda-minor-mode
+ #'org-mouse-agenda-context-menu)))
(provide 'org-mouse)
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Turn org-mouse features into minor-modes
2025-01-08 4:27 ` Visuwesh
@ 2025-01-08 7:13 ` Visuwesh
0 siblings, 0 replies; 6+ messages in thread
From: Visuwesh @ 2025-01-08 7:13 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1250 bytes --]
[புதன் ஜனவரி 08, 2025] Visuwesh wrote:
> [வெள்ளி டிசம்பர் 27, 2024] Ihor Radchenko wrote:
>
>> Visuwesh <visuweshm@gmail.com> writes:
>>
>>> [ Resending it as it seems like it never reached the mailing list. ]
>>>
>>> To make loading org-mouse less annoying for all, I was thinking of
>>> introducing minor-modes like in the attached patch. If this approach is
>>> acceptable, I will get to calling out the change in NEWS and updating
>>> the manual if required. We could also add a `add-hook' call to turn on
>>> the minor-mode automatically to preserve the old behaviour if required.
>>> WDYT?
>>
>> Thanks!
>> Adding minor modes is indeed a good idea.
>> Although they should probably be globalized to keep things closer to the
>> existing behavior.
>>
>> We do not need to preserve the old behavior - side effects are to be
>> eradicated even if the cost is introducing a breaking change.
>> NEWS announcement is good enough.
>
> I've now attached a patch to this effect. I hope the NEWS entry is
> legible.
Oops, I made a mistake when switching around branches. Now the
globalised minor-mode is actually present in the attached patch. Sorry
for the noise.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-mouse-Make-it-possible-to-turn-on-and-off-the-fe.patch --]
[-- Type: text/x-diff, Size: 9612 bytes --]
From bf809910761020bd86d089788467539843c3f7fd Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Mon, 23 Dec 2024 12:41:13 +0530
Subject: [PATCH] org-mouse: Make it possible to turn on and off the feature
Introduce new minor-modes `org-mouse-minor-mode' and
`org-mouse-agenda-minor-mode' to make it easy to turn on/off the mouse
support.
* lisp/org-mouse.el (org-mode-hook, org-agenda-mode-hook): Remove the
lambda which makes it unnecessarily difficult to reverse the effect of
loading this file.
(org-mouse--old-mouse-map): New variable to hold the original
definition of org-mouse-map.
(org-mouse-minor-mode-map, org-mouse-minor-mode)
(org-mouse-agenda-minor-mode-map, org-mouse-agenda-minor-mode): Add
new minor-modes to easily toggle the mouse features on and off per
buffer.
(global-org-mouse-minor-mode, global-org-mouse-agenda-minor-mode): Add
globalised minor-modes to preserve backwards compatibility.
* etc/ORG-NEWS: Announce the breaking change.
Link: https://list.orgmode.org/87seqad1sl.fsf@gmail.com
---
etc/ORG-NEWS | 15 ++++++
lisp/org-mouse.el | 132 ++++++++++++++++++++++++++++------------------
2 files changed, 95 insertions(+), 52 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c9bb192de..99d5b6b58 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -18,6 +18,21 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
# require user action for most Org mode users.
# Sorted from most important to least important.
+*** ~org-mouse~ is no longer activated by default by anymore
+
+To follow Emacs [[info:elisp#Coding Conventions][coding conventions]] and to avoid confusion of users who
+accidentally get ~org-mouse~ autoloaded due to help completion, the
+library does not modify ~org-mode-map~ and other variables during
+loading anymore.
+
+To enable the ~org-mouse~ features, the new minor-modes
+~org-mouse-minor-mode~ and ~org-mouse-agenda-minor-mode~ should be
+enabled.
+
+To turn on the features in all ~org-mode~ and ~org-agenda-mode~
+buffers, you can use the globalized versions
+~global-org-mouse-minor-mode~ and ~global-org-mouse-agenda-minor-mode~.
+
*** You may need to update =org-protocol= bookmarklets for browsers
In Firefox-133, and Firefox-128.5 ESR the previously suggested
diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el
index 928d18d66..e20256cf0 100644
--- a/lisp/org-mouse.el
+++ b/lisp/org-mouse.el
@@ -866,48 +866,59 @@ (defun org-mouse-down-mouse (event)
;; events to `mouse-drag-region'.
(put 'org-mouse-down-mouse 'ignored-mouse-command t)
-(add-hook 'org-mode-hook
- (lambda ()
- (setq org-mouse-context-menu-function #'org-mouse-context-menu)
-
- (when (memq 'context-menu org-mouse-features)
- (org-defkey org-mouse-map [mouse-3] nil)
- (org-defkey org-mode-map [mouse-3] #'org-mouse-show-context-menu))
- (org-defkey org-mode-map [down-mouse-1] #'org-mouse-down-mouse)
- (when (memq 'context-menu org-mouse-features)
- (org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
- (org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
- (when (memq 'yank-link org-mouse-features)
- (org-defkey org-mode-map [S-mouse-2] #'org-mouse-yank-link)
- (org-defkey org-mode-map [drag-mouse-3] #'org-mouse-yank-link))
- (when (memq 'move-tree org-mouse-features)
- (org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
- (org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start))
-
- (when (memq 'activate-stars org-mouse-features)
- (font-lock-add-keywords
- nil
+(defvar org-mouse-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (org-defkey map [mouse-3] #'org-mouse-show-context-menu)
+ (org-defkey map [down-mouse-1] #'org-mouse-down-mouse)
+ map)
+ "Keymap for `org-mouse-minor-mode'.")
+
+(defvar-local org-mouse--old-mouse-map (copy-keymap org-mouse-map))
+(define-minor-mode org-mouse-minor-mode
+ "Minor mode to enable better mouse support in `org-mode'."
+ :global nil
+ (let ((fl-fun (if org-mouse-minor-mode
+ (lambda (mode kw)
+ (font-lock-add-keywords mode kw t))
+ #'font-lock-remove-keywords)))
+ (setq org-mouse-context-menu-function
+ (and org-mouse-minor-mode #'org-mouse-context-menu))
+ (when org-mouse-minor-mode
+ ;; Without `copy-keymap', later `org-defkey' calls modify the
+ ;; value of keymap `org-mouse--old-mouse-map' holds.
+ (setq org-mouse--old-mouse-map (copy-keymap org-mouse-map)))
+ (setq org-mouse-map (copy-keymap org-mouse--old-mouse-map))
+ (org-defkey org-mouse-minor-mode-map [S-mouse-2] nil)
+ (org-defkey org-mouse-minor-mode-map [drag-mouse-3] nil)
+ (when org-mouse-minor-mode
+ (when (memq 'context-menu org-mouse-features)
+ (org-defkey org-mouse-map [mouse-3] nil)
+ (org-defkey org-mouse-map [C-drag-mouse-1] #'org-mouse-move-tree)
+ (org-defkey org-mouse-map [C-down-mouse-1] #'org-mouse-move-tree-start))
+ (when (memq 'yank-link org-mouse-features)
+ (org-defkey org-mouse-minor-mode-map [S-mouse-2] #'org-mouse-yank-link)
+ (org-defkey org-mouse-minor-mode-map [drag-mouse-3] #'org-mouse-yank-link))
+ (when (memq 'move-tree org-mouse-features)
+ (org-defkey org-mouse-map [drag-mouse-3] #'org-mouse-move-tree)
+ (org-defkey org-mouse-map [down-mouse-3] #'org-mouse-move-tree-start)))
+ (when (memq 'activate-stars org-mouse-features)
+ (funcall fl-fun nil
`((,org-outline-regexp
0 `(face org-link mouse-face highlight keymap ,org-mouse-map)
- 'prepend))
- t))
-
- (when (memq 'activate-bullets org-mouse-features)
- (font-lock-add-keywords
- nil
+ 'prepend))))
+ (when (memq 'activate-bullets org-mouse-features)
+ (funcall fl-fun nil
`(("^[ \t]*\\([-+*]\\|[0-9]+[.)]\\) +"
(1 `(face org-link keymap ,org-mouse-map mouse-face highlight)
- 'prepend)))
- t))
-
- (when (memq 'activate-checkboxes org-mouse-features)
- (font-lock-add-keywords
- nil
+ 'prepend)))))
+ (when (memq 'activate-checkboxes org-mouse-features)
+ (funcall fl-fun nil
`(("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
- (1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))
- t))
-
- (advice-add 'org-open-at-point :around #'org--mouse-open-at-point)))
+ (1 `(face nil keymap ,org-mouse-map mouse-face highlight) prepend)))))
+ (if org-mouse-minor-mode
+ (advice-add 'org-open-at-point :around #'org--mouse-open-at-point)
+ (advice-remove 'org-open-at-point #'org--mouse-open-at-point))
+ (font-lock-flush)))
(defun org--mouse-open-at-point (orig-fun &rest args)
(let ((context (org-context)))
@@ -923,7 +934,6 @@ (defun org-mouse-move-tree-start (_event)
(interactive "e")
(message "Same line: promote/demote, (***):move before, (text): make a child"))
-
(defun org-mouse-make-marker (position)
(with-current-buffer (window-buffer (posn-window position))
(copy-marker (posn-point position))))
@@ -1095,20 +1105,38 @@ (defun org-mouse-get-gesture (event)
(if (< (car startxy) (car endxy)) :right :left)))
- ; (setq org-agenda-mode-hook nil)
-(defvar org-agenda-mode-map)
-(add-hook 'org-agenda-mode-hook
- (lambda ()
- (setq org-mouse-context-menu-function #'org-mouse-agenda-context-menu)
- (org-defkey org-agenda-mode-map [mouse-3] #'org-mouse-show-context-menu)
- (org-defkey org-agenda-mode-map [down-mouse-3] #'org-mouse-move-tree-start)
- (org-defkey org-agenda-mode-map [C-mouse-4] #'org-agenda-earlier)
- (org-defkey org-agenda-mode-map [C-mouse-5] #'org-agenda-later)
- (org-defkey org-agenda-mode-map [drag-mouse-3]
- (lambda (event) (interactive "e")
- (cl-case (org-mouse-get-gesture event)
- (:left (org-agenda-earlier 1))
- (:right (org-agenda-later 1)))))))
+(defvar org-mouse-agenda-minor-mode-map
+ (let ((map (make-sparse-keymap)))
+ (org-defkey map [mouse-3] #'org-mouse-show-context-menu)
+ (org-defkey map [down-mouse-3] #'org-mouse-move-tree-start)
+ (org-defkey map [C-mouse-4] #'org-agenda-earlier)
+ (org-defkey map [C-mouse-5] #'org-agenda-later)
+ (org-defkey map [drag-mouse-3]
+ (lambda (event) (interactive "e")
+ (cl-case (org-mouse-get-gesture event)
+ (:left (org-agenda-earlier 1))
+ (:right (org-agenda-later 1)))))
+ map)
+ "Keymap for `org-mouse-agenda-minor-mode'.")
+
+(define-minor-mode org-mouse-agenda-minor-mode
+ "Minor mode to enable better mouse support in `org-agenda-mode'."
+ :global nil
+ (setq org-mouse-context-menu-function
+ (and org-mouse-agenda-minor-mode
+ #'org-mouse-agenda-context-menu)))
+
+(define-globalized-minor-mode global-org-mouse-minor-mode
+ org-mouse-minor-mode
+ (lambda ()
+ (when (derived-mode-p 'org-mode)
+ (org-mouse-minor-mode 1))))
+
+(define-globalized-minor-mode global-org-mouse-agenda-minor-mode
+ org-mouse-agenda-minor-mode
+ (lambda ()
+ (when (derived-mode-p 'org-agenda-mode)
+ (org-mouse-agenda-minor-mode 1))))
(provide 'org-mouse)
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-01-08 7:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-26 13:14 [PATCH] Turn org-mouse features into minor-modes Visuwesh
2024-12-27 8:25 ` Ihor Radchenko
2024-12-27 8:35 ` Visuwesh
2024-12-27 8:40 ` Ihor Radchenko
2025-01-08 4:27 ` Visuwesh
2025-01-08 7:13 ` Visuwesh
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).