From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id mPBiN8clfmcMKgAAe85BDQ:P1 (envelope-from ) for ; Wed, 08 Jan 2025 07:14:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id mPBiN8clfmcMKgAAe85BDQ (envelope-from ) for ; Wed, 08 Jan 2025 08:14:16 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jGRdbqbF; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736320455; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=2DtLWQKrjjeKR1AxC22RbbjUeJ2yowwClPh5nZ6lwOQ=; b=c/ls4TIxIp8yaV2+0Ei/SIptXuZpcE7NSORU8g8NXaXYQ6qBFB5yLgbLmp/0s9u2NPGiGx yZbvtfx2xKRANiuxAQJaiKf/gRqkQxcOVKUJ3BvhsYHqFXRTJAtDdWBXWpLYB+lTJTDrVq zSLhTKUDhm5nLyp2MeAb4/4s7MsI5tXmNRRqSPzlNpk8Yyh23/6QJEgn9ELlPQr8dH6fsd 8nRxGOv6a6wke3JsSpxgnPtOoQE7y4neCHwVlfHROashWQ1VPnt7NKSl75hsDJuXKk+GWA 8O9LoojUMPe1Hn7r4FDhvYhy7cM7rLk3DeCnuq5CNZsa2sh71gZhHwgSa2auxw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jGRdbqbF; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736320455; a=rsa-sha256; cv=none; b=KtJBQZtxOj66TplmFsEW5mJUyOGt4KDaQZXIACW6AV6mPFNiIeB0iDtxctzHjk/2gQDtzv 1n0BQv9srUdspNC3LdfGOe7N6Jw7gLgu6D/aHb7MORyfJ1AJgf9/eCTVJtdRUeWe8ROEiY ERPKFDV1u6sYqpHoZ0w8sZxOYGCSeORYfgnuysFfbfc8n+Tits4zNKVE7Gwv1B36wGG3Ke gYaYxvwUPLOckpHTw9GMHmBgUW+RRRmRRTY+YTe35E5gYib1sVIgPBVAtOWF/M0Oy94q9z rGOxhMEAz+UxGlyCkuccfCY1wkxTDp20oARHjO13YIJGSOw4FeUqXPDdIRylzw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6C5357BED9 for ; Wed, 08 Jan 2025 08:14:15 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVQFj-00064p-2G; Wed, 08 Jan 2025 02:13:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVQFc-00063j-PU for emacs-orgmode@gnu.org; Wed, 08 Jan 2025 02:13:12 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVQFa-0007Ys-6Z for emacs-orgmode@gnu.org; Wed, 08 Jan 2025 02:13:12 -0500 Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-21634338cfdso30155785ad.2 for ; Tue, 07 Jan 2025 23:13:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736320388; x=1736925188; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=2DtLWQKrjjeKR1AxC22RbbjUeJ2yowwClPh5nZ6lwOQ=; b=jGRdbqbF3zyLQESSCdGbYakHQenI6mYsIA6CldlCw1oNKlHQ7+BlVuHopswO9lQ+ic GWraObmkn1A1KBjA0E+DexvURVmcKMjcJUsVEO5INwN4AuMwZQlE3JOofS2asnmHb+m3 bC1P6IMF8PHF8PTXe0xgYVj1NGpEMcJ2NsNAvYSsacDOfyCrPoXhehO9MvBWRSEmNC0U FdK5xtVoaL2mi3H9mlNAKQ7ulGiJYSGaY0UENrciiFQSpji9CJoKJKa+Iu7VF+8MkWt+ IU6NhhG7UYt3g9YH7RfOMtPej51gz+PMAXbHGwVCXBzJYnZAfLDlOz6luMnkmO+dZLyJ i20w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736320388; x=1736925188; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2DtLWQKrjjeKR1AxC22RbbjUeJ2yowwClPh5nZ6lwOQ=; b=JuPwFgB+ckETHrIWzPSGFmqUO6ygLzv06tjppz+gM1LOlPSkq3PAahc+jjTQfZgrpa w07FmgbNjy56VbWmPdodn6qPUCI5DzEeVlLa6ONho2exMDV6UVoaSQOpiV8YHUg/mPtI p9LW+TOwo+59ETojNWzTG8tfDPSF0sAtZWP5rvaij7+q5EEdu6UTgNj1TrKoZFWzOV+7 x9Jd5DwKlQrwsS+UzPMDlqOciAyjTzjv10R0oXlBzt4TJ9ovO0NriMLaD+KaaVfFcJK5 9jjtd3BJwmJRkkHVRPqHUan2DAa4sNy04thbenSDVSXYGo2/jbJ1VSrOXGKXTnyU9GgJ 31kw== X-Gm-Message-State: AOJu0YwsF37g49irZrVHZ47U1eymTctsw71aynnn1ecp2mjx0m/dQk8J h/WsZSV8IaXtyQKdijsAwLZjp51Al12BL3uFSNevssRtnJqnhWIqWbqmlB14 X-Gm-Gg: ASbGncvhrnPOoRV6svXz5+E8Q3e51juDpl3mHnqX8Y3ED/lD7pUD1n2pa4iZjXJhnl/ O39JAQ6uNkmUgj2FXY/EDpLrj7PY6LWPgGjvpL+8k9JRamarnltk2BX+52sc1+jmIKtexu+UQZm VjJl30EoWRphyIrVMYGf0h0AAo5lRVZxMkNEdkx1YcGjp0STILpGtz+Dhi9TWg3JXgKVtpX9FpV aqBxB5gYQ7JrqhZIC4RUtneKCblZL51BVcvcoZuztsU4pVGvYfM X-Google-Smtp-Source: AGHT+IF+sUIzOcwLnILIfHv1IjZjIs5JJYDrmEhVEmSxLrbdiHEM/49Z64p/SqXnMA2e7wIinFulXg== X-Received: by 2002:a05:6a20:12cc:b0:1e0:be48:177d with SMTP id adf61e73a8af0-1e88d0e170dmr3634521637.3.1736320388483; Tue, 07 Jan 2025 23:13:08 -0800 (PST) Received: from localhost ([49.204.137.15]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad84eb34sm34617731b3a.87.2025.01.07.23.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 23:13:07 -0800 (PST) From: Visuwesh To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] Turn org-mouse features into minor-modes In-Reply-To: <878qrmudzu.fsf@gmail.com> (Visuwesh's message of "Wed, 08 Jan 2025 09:57:17 +0530") References: <87seqad1sl.fsf@gmail.com> <874j2p7crt.fsf@localhost> <878qrmudzu.fsf@gmail.com> Date: Wed, 08 Jan 2025 12:43:04 +0530 Message-ID: <8734htvkvz.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=visuweshm@gmail.com; helo=mail-pl1-x643.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -5.54 X-Spam-Score: -5.54 X-Migadu-Queue-Id: 6C5357BED9 X-TUID: VQEFrDom9X50 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [=E0=AE=AA=E0=AF=81=E0=AE=A4=E0=AE=A9=E0=AF=8D =E0=AE=9C=E0=AE=A9=E0=AE=B5= =E0=AE=B0=E0=AE=BF 08, 2025] Visuwesh wrote: > [=E0=AE=B5=E0=AF=86=E0=AE=B3=E0=AF=8D=E0=AE=B3=E0=AE=BF =E0=AE=9F=E0=AE= =BF=E0=AE=9A=E0=AE=AE=E0=AF=8D=E0=AE=AA=E0=AE=B0=E0=AF=8D 27, 2024] Ihor Ra= dchenko wrote: > >> Visuwesh 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-mouse-Make-it-possible-to-turn-on-and-off-the-fe.patch >From bf809910761020bd86d089788467539843c3f7fd Mon Sep 17 00:00:00 2001 From: Visuwesh 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 --=-=-=--