From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id MLbsBD7NTmSXHgAASxT56A (envelope-from ) for ; Sun, 30 Apr 2023 22:19:10 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id wC/ABD7NTmQUOAAAauVa8A (envelope-from ) for ; Sun, 30 Apr 2023 22:19:10 +0200 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 76B1735C27 for ; Sun, 30 Apr 2023 22:19:09 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptDUl-0008VE-0K; Sun, 30 Apr 2023 16:18:07 -0400 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 1ptDUj-0008V2-Ig for emacs-orgmode@gnu.org; Sun, 30 Apr 2023 16:18:05 -0400 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 1ptDUg-00053m-Nj for emacs-orgmode@gnu.org; Sun, 30 Apr 2023 16:18:05 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 927B0240180 for ; Sun, 30 Apr 2023 22:17:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1682885879; bh=0VSDXs66JB4I8jZ51aWB3UfHRfd6HBM2S6R56MUTxYU=; h=From:To:Subject:Date:From; b=KqCCxgoo18LTKHxYNwVppEJjQyl5BagShdGFfrwpvzgt6AUMsP0wZxchQXCjQaVSN 5Sgk1h4hUBcFXWtINpe/pBwOqjqiRyDm4Bf9TgghyFn7aHa0KFvgUM5haUZGpF7K8d w1h/iz2ZiCpVzzqht4CBb++w2IikbJ29D1sei2HfY2V2TuE/+9Z57Iz4K9pN1b5bp7 l/6yf85csmqa9fnrymNf4ImwEjhOX4IyAF2FwYgIOXWcnWdR2X9LZzLadxQXWMuFUr v3SaNWyEBM27doR4JdKaCrC8j6iGI9/VPnZC9+dnxWsbSIEmjMqwoRG9LdPZFw/rpE /irlbSaboRhPg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Q8d1z1Vwwz6trm for ; Sun, 30 Apr 2023 22:17:59 +0200 (CEST) From: Ihor Radchenko To: emacs-orgmode@gnu.org Subject: [PATCH] org-crypt-decrypt-entry: Apply initial visibility upon decryption Date: Sun, 30 Apr 2023 20:21:02 +0000 Message-ID: <87pm7lyvdd.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, T_SCC_BODY_TEXT_LINE=-0.01 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-Seal: i=1; s=key1; d=yhetil.org; t=1682885949; a=rsa-sha256; cv=none; b=iPEIAepZBIF8f4sjc+IKYlLlsMwOcy+paanArI4yx8c8s3OAm+q4VxDCBkI6Su06jQWm/1 1ltr2FDdVHubMMqFRQW07RvwDfHc+6DyU8CuyzOviY8rtysaGg0lU4Mm90kIcPSALeGAe1 rt9Ibx9z8w2JyiOLQ0gK4KdQDN3yFj4H+VBE1DWHI8uoLFrNiNieiAd+wkm/NA4F4BXd16 BqxvG5B9blQt6vOXjvSwrIibgJ6yWPdMmTdBjPFJ5Czi3zKlUj1FYKVuMPY6w9X3i+zweU uLvVbg7jQ53h3R+1WqLtKLGjZi7ywx+puyM0Znph47ohGCjqDMgOGLtlD8eOcA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KqCCxgoo; dmarc=pass (policy=none) header.from=posteo.net; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1682885949; 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=0mXjWEpSXum9Zg69TkGkzn0lrCKzIBq9Dqxq+7DNMz4=; b=dE59Bm+QOrqPLZbiHMQEERLdgLvk8qQPO7nq9lL+fCFA2LQiWxJZS3QAIdZKPRLqc2tp6K YEJ4+ufP7Ah+KkR4YMe1GuZwajm8PSkuIKHW+2Nzf1mfMg6pzxWSqw/ZkcoONkfHNd6Awa NXiG5lsF0z9EsJ/mepxR5bHvB5DUqr2YIAuxXLppmsvAsentqxIaQj3yyCbTPYIt7E2Cpg SRvTgfQCHunofxvq/qOeI5o3DCXUIGCjCuq8ugBMknr56OifqODCyH2rD1KLIAzdFw92nd DC65sohDbWJqJOuZv1Z1cQaz6FZg5f2eomQUrGR6uCYgu1eD+jkXc16yAtgQoQ== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KqCCxgoo; dmarc=pass (policy=none) header.from=posteo.net; 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" X-Migadu-Spam-Score: -4.69 X-Spam-Score: -4.69 X-Migadu-Queue-Id: 76B1735C27 X-TUID: UCqDO9+kmufK --=-=-= Content-Type: text/plain Hi, I'd like to propose applying initial visibility to the freshly decrypted headings. IMHO, it makes much more sense by default compared to showing all the text unfolded, including property drawers. Any objections? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-crypt-decrypt-entry-Apply-initial-visibility-upo.patch >From 5f90460cf565e9c3185f58a631500207e9b14d39 Mon Sep 17 00:00:00 2001 Message-Id: <5f90460cf565e9c3185f58a631500207e9b14d39.1682886052.git.yantar92@posteo.net> From: Ihor Radchenko Date: Sun, 30 Apr 2023 22:15:11 +0200 Subject: [PATCH] org-crypt-decrypt-entry: Apply initial visibility upon decryption * lisp/org-crypt.el: Call `org-cycle-set-startup-visibility' on the decrypted entries. Still re-fold if the decrypted entry has been inside an existing fold. * lisp/org-cycle.el (org-cycle-set-visibility-according-to-property): Respect narrowing. * etc/ORG-NEWS (=org-crypt.el= now applies initial visibility settings to decrypted entries): Announce the change. This patch solves a slight annoyance when the freshly decrypted entry is fully unfolded, including all the property drawers. It will make more sense to make the folding state follow initial visibility settings, including VISIBILITY properties. --- etc/ORG-NEWS | 4 ++++ lisp/org-crypt.el | 11 ++++++++++- lisp/org-cycle.el | 15 ++++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 03894f128..70e684d10 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -214,6 +214,10 @@ execution completes. The new ~:async~ header allows users to continue editing with Emacs while a ~:session~ block executes. ** Miscellaneous +*** =org-crypt.el= now applies initial visibility settings to decrypted entries + +Previously, all the text was unfolded unconditionally, including property drawers. + *** Blank lines after removed objects are not retained during export When certain objects in Org document are to be excluded from export, diff --git a/lisp/org-crypt.el b/lisp/org-crypt.el index b5df115cf..39d1a421d 100644 --- a/lisp/org-crypt.el +++ b/lisp/org-crypt.el @@ -81,6 +81,7 @@ (declare-function org-make-tags-matcher "org" (match)) (declare-function org-previous-visible-heading "org" (arg)) (declare-function org-scan-tags "org" (action matcher todo-only &optional start-level)) (declare-function org-set-property "org" (property value)) +(declare-function org-cycle-set-startup-visibility "org-cycle" ()) (defgroup org-crypt nil "Org Crypt." @@ -269,10 +270,12 @@ (defun org-decrypt-entry () (decrypted-text (decode-coding-string (epg-decrypt-string epg-context encrypted-text) - 'utf-8))) + 'utf-8)) + origin-marker) ;; Delete region starting just before point, because the ;; outline property starts at the \n of the heading. (delete-region (1- (point)) end) + (setq origin-marker (point-marker)) ;; Store a checksum of the decrypted and the encrypted text ;; value. This allows reusing the same encrypted text if the ;; text does not change, and therefore avoid a re-encryption @@ -282,6 +285,12 @@ (defun org-decrypt-entry () 'org-crypt-checksum (sha1 decrypted-text) 'org-crypt-key (org-crypt-key-for-heading) 'org-crypt-text encrypted-text)) + ;; Apply initial visibility. + (save-restriction + (narrow-to-region origin-marker (point)) + (set-marker origin-marker nil) + (org-cycle-set-startup-visibility)) + ;; ... but keep the previous folded state. (when folded-heading (goto-char folded-heading) (org-fold-subtree t)) diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el index 50aa0d21d..44e015746 100644 --- a/lisp/org-cycle.el +++ b/lisp/org-cycle.el @@ -638,20 +638,21 @@ (defun org-cycle-set-visibility-according-to-property () "Switch subtree visibility according to VISIBILITY property." (interactive) (let ((regexp (org-re-property "VISIBILITY"))) - (org-with-point-at 1 + (save-restriction + (goto-char (point-min)) (while (re-search-forward regexp nil t) - (let ((state (match-string 3))) + (let ((state (match-string 3))) (if (not (org-at-property-p)) (outline-next-heading) (save-excursion (org-back-to-heading t) (org-fold-subtree t) (pcase state - ("folded" + ("folded" (org-fold-subtree t)) - ("children" + ("children" (org-fold-show-hidden-entry) (org-fold-show-children)) - ("content" + ("content" ;; Newline before heading will be outside the ;; narrowing. Make sure that it is revealed. (org-fold-heading nil) @@ -659,9 +660,9 @@ (defun org-cycle-set-visibility-according-to-property () (save-restriction (org-narrow-to-subtree) (org-cycle-content)))) - ((or "all" "showall") + ((or "all" "showall") (org-fold-show-subtree)) - (_ nil))) + (_ nil))) (org-end-of-subtree t))))))) (defun org-cycle-overview () -- 2.40.0 --=-=-= 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 --=-=-=--