From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id QPyPJKQE6WNWfAEAbAwnHQ (envelope-from ) for ; Sun, 12 Feb 2023 16:24:20 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id kE6UI6QE6WNNEAEAG6o9tA (envelope-from ) for ; Sun, 12 Feb 2023 16:24:20 +0100 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 CDC24B506 for ; Sun, 12 Feb 2023 16:24:19 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRECP-0005Pv-8l; Sun, 12 Feb 2023 10:23:29 -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 1pRECF-0005ML-RM for emacs-orgmode@gnu.org; Sun, 12 Feb 2023 10:23:19 -0500 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRECD-0008P7-2I for emacs-orgmode@gnu.org; Sun, 12 Feb 2023 10:23:19 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id CEE9724012D for ; Sun, 12 Feb 2023 16:23:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1676215393; bh=kBDPa0jfNkFZjWF0tZATd0XKPOb3myLk/ebqMjV68eY=; h=From:To:Cc:Subject:Date:From; b=NLsP73ayK3PSpXnOeDkykCZrVfkegi3swGxjyA0prHeH/ytYezSvMIbYoHAv4mfiD IgrLjcGwC14zjvQ77aGlQ5rnLkQhw1iukqK0UqRif6kRbJ2WQ1UAiZBbE12E3Abrf5 DVUldcTemGBafS5bjDQXY2GgCR4r9E69+dsXt8h0LA6ZRJ5UxzJAODQIAgFj6YljZi a3anngrPLAWM+ugw1PfSYKxYjtscHCD/Hlwhp+rd5BgB5yAJnRso3Ha4ORC4pXt8kN 8kQvRCo4geSWbBzvwiF0SyVNU7HkkwMUQyIjjS+QPhq3CnIBoHnnbV+sBbyufNlHdo XZorGfIhE/wqw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PFB7L5kKSz6tm5; Sun, 12 Feb 2023 16:23:10 +0100 (CET) From: Ihor Radchenko To: alain.cochard@unistra.fr Cc: emacs-orgmode Subject: [PATCH] Allow customizing commands affected by `org-fold-catch-invisible-edits' (was: Should we extend org-catch-invisible-edits to more interactive commands? (was: Catching invisible edits: problem understanding doc)) In-Reply-To: <25576.34807.805766.160813@gargle.gargle.HOWL> References: <25573.3996.714544.156631@gargle.gargle.HOWL> <87bkm1etd9.fsf@localhost> <25575.52322.757469.405610@gargle.gargle.HOWL> <87a61kukn1.fsf@localhost> <25576.34807.805766.160813@gargle.gargle.HOWL> Date: Sun, 12 Feb 2023 15:23:51 +0000 Message-ID: <87wn4mgb5k.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, 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 ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=NLsP73ay; 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=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1676215460; a=rsa-sha256; cv=none; b=Vpb6F6rVgpBtbXks/nax/i5OnPOgTo8An2aNDfnzFpIA2lVSYws1qFiU+Woi4Pvch0c9Yf yd2eKbkT8DkHUJ8Rucy86FAHKFJOfXoJx4j9ME71KlGclgg6mk7yPA4Bw8LVuyhdhJMjnu KNGij4fuVZ7IjDfl3SVhTBx3+8fueWehHJJsbcqpTOb7q4Uh0JuX0qGwdBt4b/jsZRW400 anZ7t88ADeMTp9pCF7gdGpU/wrGGDY10jOnyerIBT329iyMbWcu5nhiCpRpZ+QPhm/UiGo F3d264HXv7D+xYVSeT2DsYEbrLvCsdKi34Yi4v6cuxZv3M420D3laeBvvN1Slw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1676215460; 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=M+/giHSFKWklzfbEpkBuBX/TWT8Uz5c5J56SekXEDEg=; b=MGty3Z64PTot4ZRfGH+VxhYjMZnUP/h8hnf2BfyAYsY1VrSH6dDduRBjLqatJAqF8zfDnw H4+YYeqdKj1u0SmZoLDKezN3P3nD6S3XqPwb+wLe8B9oQFj5BsOtBC1ZH4dJIkEf/c2z4d iGtHoGG5WRcmh6A+EvSJE14+vRIYXPvSaH23vLrl3NREN/QZJnxrxWWF54kZkFyZ4ezjr8 XQS6ifJErb0qqYzicK1DglgT2VZuyLsvMZsNvb0hoOMUcOLHZO1jlzKoFMTjbx+Tpjx0H6 dhUpBNLtfa7kiJYmscOpH/6MSH905Og/u5d1TRnxTPuvqKyzSWR3wF8ZG4FpwQ== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -4.45 X-Spam-Score: -4.45 X-Migadu-Queue-Id: CDC24B506 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=NLsP73ay; 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=posteo.net X-TUID: diYMz3/ETLEi --=-=-= Content-Type: text/plain Alain.Cochard@unistra.fr writes: > Ihor Radchenko writes on Sat 11 Feb 2023 18:22: > > > We can indeed at such warning, but it will probably be not very > > helpful. > > I don't understand this. And isn't it better to have a more accurate > manual anyway? Sure. But I want to implement more generic feature. See the attached patch. > Also, this is another instance where 'C-h v' with the cursor on > 'org-fold-catch-invisible-edits' does not offer it right away in the > minibuffer. I am surprised since it does so in 9.5 (with > 'org-catch-invisible-edit'). The variable has been moved to a different file. C-h v not working is an Emacs bug. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-fold-Allow-customizing-commands-where-invisible-.patch >From 653005e1b383b4c7ad9086fc0b7e40d262dab744 Mon Sep 17 00:00:00 2001 Message-Id: <653005e1b383b4c7ad9086fc0b7e40d262dab744.1676215378.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sun, 12 Feb 2023 18:13:36 +0300 Subject: [PATCH] org-fold: Allow customizing commands where invisible edits are checked * lisp/org-fold.el (org-fold-catch-invisible-edits-commands): New custom option. (org-fold-catch-invisible-edits): Mention the new custom option in the docstring. (org-fold-check-before-invisible-edit-maybe): New function checking if edits are safe for `this-command'. (org-fold--advice-edit-commands): New function advising the functions with `org-fold-check-before-invisible-edit-maybe'. * lisp/org.el (org-mode): Advice functions on Org startup. (org-self-insert-command): (org-delete-backward-char): (org-delete-char): (org-meta-return): Do not call `org-fold-check-before-invisible-edit' and rely on the new advise mechanism instead. * etc/ORG-NEWS (Commands affected by ~org-fold-catch-invisible-edits~ can now be customized): Announce the change. * doc/org-manual.org (Catching invisible edits): Mention new customization. --- doc/org-manual.org | 12 +++++++++--- etc/ORG-NEWS | 12 ++++++++++++ lisp/org-fold.el | 45 ++++++++++++++++++++++++++++++++++++++++++++- lisp/org.el | 6 ++---- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 2d38cf76c..2b836a026 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -622,11 +622,17 @@ *** Catching invisible edits #+cindex: edits, catching invisible #+vindex: org-fold-catch-invisible-edits +#+vindex: org-fold-catch-invisible-edits-commands Sometimes you may inadvertently edit an invisible part of the buffer and be confused on what has been edited and how to undo the mistake. -Setting ~org-fold-catch-invisible-edits~ to non-~nil~ helps preventing -this. See the docstring of this option on how Org should catch -invisible edits and process them. +By default, Org prevents such edits for a limited set of user +commands. Users can control which commands are affected by +customizing ~org-fold-catch-invisible-edits-commands~. + +The strategy used to decide if a given edit is dangerous is controlled +by ~org-fold-catch-invisible-edits~. See the docstring of this option +on the available strategies. Set the option to ~nil~ to disable +catching invisible edits completely. ** Motion :PROPERTIES: diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 87ecd77cd..b85c46758 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -24,6 +24,18 @@ consider [[https://gitlab.com/jackkamm/ob-python-mode-mode][ob-python-mode-mode] has been ported to. ** New and changed options +*** Commands affected by ~org-fold-catch-invisible-edits~ can now be customized + +New user option ~org-fold-catch-invisible-edits-commands~ controls +which commands trigger checking for invisible edits. + +The full list of affected commands is: +- ~org-self-insert-command~ +- ~org-delete-backward-char~ +- ~org-delete-char~ +- ~org-meta-return~ +- ~org-return~ (not checked in earlier Org versions) + *** New escape in ~org-beamer-environments-extra~ for labels in Beamer export The escape =%l= in ~org-beamer-environments-extra~ inserts the label obtained from ~org-beamer--get-label~. This is added to the default diff --git a/lisp/org-fold.el b/lisp/org-fold.el index 1b7ca22b0..3d86eb802 100644 --- a/lisp/org-fold.el +++ b/lisp/org-fold.el @@ -189,7 +189,10 @@ (defcustom org-fold-catch-invisible-edits 'smart Never delete a previously invisible character or add in the middle or right after an invisible region. Basically, this allows insertion and backward-delete right before ellipses. - FIXME: maybe in this case we should not even show?" + FIXME: maybe in this case we should not even show? + +This variable only affects commands listed in +`org-fold-catch-invisible-edits-commands'." :group 'org-edit-structure :version "24.1" :type '(choice @@ -199,6 +202,33 @@ (defcustom org-fold-catch-invisible-edits 'smart (const :tag "Show invisible part and do the edit" show) (const :tag "Be smart and do the right thing" smart))) +(defcustom org-fold-catch-invisible-edits-commands + ;; We do not add non-Org commands here by default to avoid advising + ;; globally. See `org-fold--advice-edit-commands'. + '((org-self-insert-command . insert) + (org-delete-backward-char . delete-backward) + (org-delete-char . delete) + (org-meta-return . insert) + (org-return . insert)) + "Alist of commands where Org checks for invisible edits. +Each element is (COMMAND . KIND), where COMMAND is symbol representing +command as stored in `this-command' and KIND is symbol `insert', +symbol `delete', or symbol `delete-backward'. + +The checks are performed around `point'. + +This variable must be set before loading Org in order to take effect. + +Also, see `org-fold-catch-invisible-edits'." + :group 'org-edit-structure + :package-version '("Org" . "9.7") + :type '(alist + :key-type symbol + :value-type (choice + (const insert) + (const delete) + (const delete-backward)))) + ;;; Core functionality ;;; API @@ -901,6 +931,19 @@ (defun org-fold-check-before-invisible-edit (kind) ;; Don't do the edit, make the user repeat it in full visibility (user-error "Edit in invisible region aborted, repeat to confirm with text visible")))))))) +(defun org-fold-check-before-invisible-edit-maybe (&rest _) + "Check before invisible command by `this-command'." + (when (derived-mode-p 'org-mode) + (pcase (alist-get this-command org-fold-catch-invisible-edits-commands) + ((pred null) nil) + (kind (org-fold-check-before-invisible-edit kind))))) + +(defun org-fold--advice-edit-commands () + "Advice editing commands according to `org-fold-catch-invisible-edits-commands'. +The advices are installed in current buffer." + (dolist (command (mapcar #'car org-fold-catch-invisible-edits-commands)) + (advice-add command :before #'org-fold-check-before-invisible-edit-maybe))) + (provide 'org-fold) ;;; org-fold.el ends here diff --git a/lisp/org.el b/lisp/org.el index 4d12084d9..8d88f83e7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4839,6 +4839,8 @@ (define-derived-mode org-mode outline-mode "Org" (add-hook 'before-change-functions 'org-before-change-function nil 'local) ;; Check for running clock before killing a buffer (add-hook 'kill-buffer-hook 'org-check-running-clock nil 'local) + ;; Check for invisible edits. + (org-fold--advice-edit-commands) ;; Initialize cache. (org-element-cache-reset) (when (and org-element-cache-persistent @@ -16440,7 +16442,6 @@ (defun org-self-insert-command (N) If the cursor is in a table looking at whitespace, the whitespace is overwritten, and the table is not marked as requiring realignment." (interactive "p") - (org-fold-check-before-invisible-edit 'insert) (cond ((and org-use-speed-commands (let ((kv (this-command-keys-vector))) @@ -16510,7 +16511,6 @@ (defun org-delete-backward-char (N) because, in this case the deletion might narrow the column." (interactive "p") (save-match-data - (org-fold-check-before-invisible-edit 'delete-backward) (if (and (= N 1) (not overwrite-mode) (not (org-region-active-p)) @@ -16530,7 +16530,6 @@ (defun org-delete-char (N) because, in this case the deletion might narrow the column." (interactive "p") (save-match-data - (org-fold-check-before-invisible-edit 'delete) (cond ((or (/= N 1) (eq (char-after) ?|) @@ -17944,7 +17943,6 @@ (defun org-meta-return (&optional arg) `org-table-wrap-region', depending on context. When called with an argument, unconditionally call `org-insert-heading'." (interactive "P") - (org-fold-check-before-invisible-edit 'insert) (or (run-hook-with-args-until-success 'org-metareturn-hook) (call-interactively (cond (arg #'org-insert-heading) ((org-at-table-p) #'org-table-wrap-region) -- 2.39.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--