emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org-transclusion 1f687ba3f1 2/5: feat: org-transclusion


From: ELPA Syncer
Subject: [elpa] externals/org-transclusion 1f687ba3f1 2/5: feat: org-transclusion-after-add-hook
Date: Sat, 8 Jan 2022 15:57:41 -0500 (EST)

branch: externals/org-transclusion
commit 1f687ba3f19e1805a3f5ac6b66c9680ac41df79c
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>

    feat: org-transclusion-after-add-hook
    
    Refer to discussions in PR #119.
    
    A new abnormal hook, `org-transclusion-after-add-functions` has been added.
    
    "Functions to be called after a transclusion content has been added.  The 
hook
    runs after the content and the read-only text property have been added so 
it is
    not supposed to manipulate the content but to add further text properties.  
For
    example, it is used by the `org-transclusion-indent-mode' extension to 
support
    `org-indent-mode'.  The functions are called with arguments beg and end,
    pointing to the beginning and end of the transcluded content."
    
    The existing extension, `org-transclusion-indent-mode` has been refactored 
to
    use the newly added hook.  In this refactoring, the part which existed in 
the
    remove function has been removed and tested OK to do so.
    
    Documentation is WIP and to be added before a new version makes its way to 
ELPA.
---
 org-transclusion-indent-mode.el | 18 +++++++++++-------
 org-transclusion.el             | 24 +++++++++++++-----------
 test/test-2.0.org               |  4 ++++
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/org-transclusion-indent-mode.el b/org-transclusion-indent-mode.el
index 9b7c1ca664..d86565fce5 100644
--- a/org-transclusion-indent-mode.el
+++ b/org-transclusion-indent-mode.el
@@ -17,7 +17,7 @@
 
 ;; Author: Noboru Ota <me@nobiot.com>
 ;; Created: 22 August 2021
-;; Last modified: 4 December 2021
+;; Last modified: 07 January 2022
 
 ;;; Commentary:
 ;;  This file is part of Org-transclusion
@@ -29,14 +29,18 @@
 (declare-function org-transclusion-within-transclusion-p
                   "org-transclusion")
 
+(add-hook 'org-transclusion-after-add-functions
+          #'org-translusion-indent-add-properties)
+
 (defun org-translusion-indent-add-properties (beg end)
   "BEG END."
-  (advice-add #'org-indent-set-line-properties
-              :override
-              #'org-transclusion-indent-set-line-properties-ad)
-  (org-indent-add-properties beg end)
-  (advice-remove #'org-indent-set-line-properties
-                 #'org-transclusion-indent-set-line-properties-ad))
+  (when org-indent-mode
+    (advice-add #'org-indent-set-line-properties
+                :override
+                #'org-transclusion-indent-set-line-properties-ad)
+    (org-indent-add-properties beg end)
+    (advice-remove #'org-indent-set-line-properties
+                   #'org-transclusion-indent-set-line-properties-ad)))
 
 (defun org-transclusion-indent-set-line-properties-ad (level indentation 
&optional heading)
   "Set prefix properties on current line an move to next one.
diff --git a/org-transclusion.el b/org-transclusion.el
index 260c46521f..19fdf8002c 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -43,9 +43,6 @@
 (require 'org-transclusion-font-lock)
 (require 'text-property-search)
 (require 'seq)
-(declare-function org-translusion-indent-add-properties
-                  "org-transclusion-indent-mode")
-(defvar org-indent-mode)
 
 ;;;; Customization
 
@@ -104,6 +101,17 @@ See `display-buffer' for example options."
   :type '(choice (const :tag "No lighter" "") string)
   :safe 'stringp)
 
+(defcustom org-transclusion-after-add-functions nil
+  "Functions to be called after a transclusion content has been added.
+The hook runs after the content and the read-only text property
+have been added so it is not supposed to manipulate the content
+but to add further text properties.  For example, it is used by
+the `org-transclusion-indent-mode' extension to support
+`org-indent-mode'.  The functions are called with arguments beg
+and end, pointing to the beginning and end of the transcluded
+content."
+  :type '(repeat function))
+
 ;;;; Faces
 
 (defface org-transclusion-source-fringe
@@ -442,9 +450,7 @@ does not support all the elements.
               ;; `org-transclusion-keyword-remove' checks element at point is a
               ;; keyword or not
               (org-transclusion-keyword-remove)))
-          (when (and (featurep 'org-indent) org-indent-mode
-                     (memq 'org-transclusion-indent-mode 
org-transclusion-extensions))
-            (org-translusion-indent-add-properties beg end)))
+          (run-hook-with-args 'org-transclusion-after-add-functions beg end))
         t))))
 
 ;;;###autoload
@@ -521,11 +527,7 @@ When success, return the beginning point of the keyword 
re-inserted."
             ;; inevitably have the same position (location "between" lines)
             (when mkr-at-beg (move-marker mkr-at-beg beg))
             ;; Go back to the beginning of the inserted keyword line
-            (goto-char beg)
-            (when (and (featurep 'org-indent) org-indent-mode
-                       (memq 'org-transclusion-indent-mode
-                             org-transclusion-extensions))
-              (org-translusion-indent-add-properties beg (line-end-position))))
+            (goto-char beg))
           beg))
     (message "Nothing done. No transclusion exists here.") nil))
 
diff --git a/test/test-2.0.org b/test/test-2.0.org
index 2633374391..901ea93110 100644
--- a/test/test-2.0.org
+++ b/test/test-2.0.org
@@ -18,6 +18,10 @@ t/nil will be dropped after remove-at-point
 
 (setq inhibit-read-only nil)
 
+** test
+
+#+transclude: [[file:bertrand-russell.org::*Bertrand Russell - Wikipedia]] 
:level 1 
+
 ** Test =org-adapt-indentation=
 
 #+begin_example



reply via email to

[Prev in Thread] Current Thread [Next in Thread]