From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id qEf8MdBWbWcE7wAAqHPOHw:P1 (envelope-from ) for ; Thu, 26 Dec 2024 13:14:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id qEf8MdBWbWcE7wAAqHPOHw (envelope-from ) for ; Thu, 26 Dec 2024 14:14:56 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="cd/TvGCU"; 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=1735218896; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=bCFFwj0JYGmm+M7SwNtBRnl7agwHlby4VlcSlMVgy0E=; b=kiVEjBaysqS0n6/cb3Y+R5eSwK7axPQfOAQWULcKm4XGMOzgH4IhirUuSJ/L6N9zMjurFe VS0nr/HmwtIGWDBk64iN6DDGF5cPA0CFCejOsMknxg+ary0kZkQrjh5pz0KaiV2VTX9yk6 MA+ASW7+k0RaPg9Nx1cA+A258obnT4RJIogif9hQSGuwHN2r4Y7MMgXc0/Uax2vjP38Zrn mVM6tQvk9LXApUxdb9HowvPk+8IVIf7F6EyEe7uOyzRMsBbkszaOnNTgjsC2nEzd4qANSg KKA0TSqk+EGLxeR7vcKA/OdKn8wq70wqR6FlimPAiq4JXv0E3kzW4BPSrRb22g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="cd/TvGCU"; 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=1735218896; a=rsa-sha256; cv=none; b=qlVcGH9Ji+zRkE9ObV5+GzsDJIUHLe8A2uzGOAFpNPWLcdc2JfkrJbhM0FJRTs+hghkk2f qNENIPfuyHD1Pfg1SCHRMmpW5NXbazkRNSPPz/tq1v4Vs2g8xMyvcZlDqnIZck72FxK+XC EhBIe8yJdY8LwCHSpccsXuksG/hUr8YvX1m0PcDvVnoHz6lqj072U6ElLYWMzVggqI/t2x Myl258W9FpC2cm9mQmZYJllCzMZG9eG7UcJKeMpPymrjfS1LwvRSMVLcY8j2mxmXBYzKLj Ucq3lDrWQtbJ9gdl7om91YXa9Vv18GbWr9Va3hCfnFfyZQ/Eylk0XPCNgxCCwQ== 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 8C1805D0B2 for ; Thu, 26 Dec 2024 14:14:56 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQnh6-0003RK-QL; Thu, 26 Dec 2024 08:14:28 -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 1tQnh4-0003PY-UN for emacs-orgmode@gnu.org; Thu, 26 Dec 2024 08:14:27 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tQnh2-0003d0-NS for emacs-orgmode@gnu.org; Thu, 26 Dec 2024 08:14:26 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-21631789fcdso59171885ad.1 for ; Thu, 26 Dec 2024 05:14:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735218863; x=1735823663; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=bCFFwj0JYGmm+M7SwNtBRnl7agwHlby4VlcSlMVgy0E=; b=cd/TvGCUsh+MT00o9ixc3Szw2KLvck5sFmV1C6dor/ho6zK8AxCDkhyFBn/ZYGENLR 4BcidQNqhNk/rJewNNduzhN95uyMseeGiSbSi868qohc5FZVgxLoxGqlm7p7B9Ll3SOo a4ivXc8jgZ2e/U1BtGMuLuk5scjC/s7SR62LHzg9uq3gUmP7nzYMXaalj31d9mjFzco2 cv+E/8cVYsVOWaD8K3xkUcjxDjQRQ2R8puJ3ixQakiK0QO+B268d7HNyAnpVIn7z1OmA n2ecuuxxXZiWnWTqsn/Li5UMmj2YM+MJsvut2ACpeofISEZ0VN6cESrtec7RBNGvDQVV 4uyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735218863; x=1735823663; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bCFFwj0JYGmm+M7SwNtBRnl7agwHlby4VlcSlMVgy0E=; b=QXi2wl3stqmdXSBu0ch0tgMGj3PfwLoKjlHpVVRjPoXAsXubZlTWLA5Ptn01XH8Dvm y3Q2mFGj6UtI2gniQXORVe7aplM4HksjEud5j9NFDAt8Bf4i4mtYHLpzBOZzyHJ1Ju1w tw4COt0AbEIni0nfvAdDiWxotoomdOiGZ20RJP6zc7OZQblLkCY6yV+MGeKHBVYaM3GB cvLJqMtQBEzZajjPMnNjhuiXupKqbREJmpJw7iknpuVsXpPXkAzfdoLJLMrYlcot71ai q49iNgDJbgfUpwA9VXAiFIhzFi4bEoWAL2sNRNvrBNDvYX/DOoPER02hz9smxvUzqEGu f00Q== X-Gm-Message-State: AOJu0YyyGIDNaMnzwjwdAc/ia11Yneup07ucW8HyEfF0AaN/L05T188p 1/1A6ucWpHKvvTqwPwJwXaUL0zmlmuY9AFutdApRWnS45O22fbw0qnxQjQGv X-Gm-Gg: ASbGncs4yqgBV50gkdkKFPRkBlN4RXHroxpt2JG7ghrMfAZLnjg1Yp2HbShd8xnAP2E N/AjtBUDgobKRpggMAP+XnS0AlNGwhx1OV0gzrIVFFIQImZO8JcCc5NyzXe+lmKS0/5qd5RCXHI 9u5FVG+wZFs4M7L7OA02TSicT27dUqGmeZ3jPF/98+YQ3PPkJRb3BGcGRt0pouoUqXY7/pxbCsv mtmrT4gtROxLGAZbvBJVzaSt4+/dGAhVls5pJhcQaQQx83h+a8= X-Google-Smtp-Source: AGHT+IGDzRRdkRQUDJYXs6QyiZ4UVJByRSjuvX6lHTdQJtQCEARV1V+mfRH/cjUl6avPQHBemo3pAA== X-Received: by 2002:a05:6a21:c8c:b0:1e0:d3e9:1f8 with SMTP id adf61e73a8af0-1e5e1e70b36mr30944697637.10.1735218862784; Thu, 26 Dec 2024 05:14:22 -0800 (PST) Received: from localhost ([49.205.85.12]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad816305sm12787934b3a.31.2024.12.26.05.14.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2024 05:14:22 -0800 (PST) From: Visuwesh To: emacs-orgmode@gnu.org Subject: [PATCH] Turn org-mouse features into minor-modes Date: Thu, 26 Dec 2024 18:44:18 +0530 Message-ID: <87seqad1sl.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::642; envelope-from=visuweshm@gmail.com; helo=mail-pl1-x642.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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 8C1805D0B2 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -2.89 X-Spam-Score: -2.89 X-TUID: BgnsrSHzfdaq --=-=-= Content-Type: text/plain [ 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? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-org-mouse-Make-it-possible-to-turn-on-and-off-the-fe.patch >From a4162d9e9204735ecd6ac864ed467e87362ace32 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. --- 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 --=-=-=--