nobiot / org-transclusion

Emacs package to enable transclusion with Org Mode
https://nobiot.github.io/org-transclusion/
GNU General Public License v3.0
902 stars 43 forks source link

Text read-only while exporting to other formats #86

Open gpetrini opened 3 years ago

gpetrini commented 3 years ago

I have a major org-mode file in which I use to gather other org files. At the end, I use org-transclusion (Awesome package btw) to tangle the section code block to some other specific file. Everything goes fine when I run org-transclusion-add-all and I can see the contents of each file. However, when I try to export to other format (e.g. html), I got the message Text-only at the bottom and no file is generated. There is any additional steps to export and tangle the transcluded chuncks? Here is a piece of code of my document:

* Current version

This section provides current version of the dissertation model always tangled as =current-version.nlogo=.
Model's information is provided in the respective change log subsection.
The following text is transcluded, so *read-only*.

#+transclude: [[file:Versions/cluster-geo/cluster-geo.org::*Implementation]] :level 2

* Noweb and tangle
:PROPERTIES:
  :header-args: netlogo :results output drawer :eval never-export :session export :exports code :tangle ./Versions/current-version.nlogo
  :END:

#+transclude: [[file:Versions/cluster-geo/cluster-geo.org::*Noweb and tangle]] :level 2 :only-contents

Thank you in advance

nobiot commented 3 years ago

Thank you for your kind words. If you don't transclude anything, does export work as expected?

gpetrini commented 3 years ago

Yes, everything works. I've tried using #+INCLUDE: instead and the export works as well. So I guess it is not specific to the included files.

nobiot commented 3 years ago

The org file below exports fine on my end. The first headline named "drawer" is actually transcluded from another file.

Is it possible to get the other two headlines someone? You can email me at me@nobiot.com if you wish to send them more privately.

** drawer
   #+begin_example
     (setq org-transclusion-exclude-elements '())
     (setq org-transclusion-exclude-elements '(property-drawer))
   #+end_example

   #+transclude: [[id:20210501T171427.051019][Bertrand Russell]]

* Current version

This section provides current version of the dissertation model always tangled as =current-version.nlogo=.
Model's information is provided in the respective change log subsection.
The following text is transcluded, so *read-only*.

#+transclude: [[file:Versions/cluster-geo/cluster-geo.org::*Implementation]] :level 2

* Noweb and tangle
:PROPERTIES:
  :header-args: netlogo :results output drawer :eval never-export :session export :exports code :tangle ./Versions/current-version.nlogo
  :END:

#+transclude: [[file:Versions/cluster-geo/cluster-geo.org::*Noweb and tangle]] :level 2 :only-contents
gpetrini commented 3 years ago

Thank you for the quick response. I'll send you an e-mail with the files since github does not support .org attachments.

nobiot commented 3 years ago

Hi @gpetrini

Had a quick look.

I think exporting a source block does something to the original text, and thus it cannot be read-only.

Export works without the "read-only error" when trascluding the first of the two below but not the second one. I assume the first one does not contain source blocks:

As a quick fix, set this before exporting: (setq inhibit-read-only t).

This will prevent the read-only text properties from working.

Set it back to nil (that's the default) after export. It's a global variable, so will affect your entire Emacs session.

I will need to think about something for long term for source code blocks and Org-export. At this stage, I am not sure what would be the best solution.

Thanks for reporting this issue; I have learned something new about Org-export :).

nobiot commented 3 years ago

By the way, the html document looks like a really good instruction web page 👍 I am very pleased that Org-transclusion could be of some help for a project like yours. Thank you.

gpetrini commented 3 years ago

Thank you a lot!

I am not really sure if I did the right thing, but I tried the following in both files and still got the same error message:

(setq-local inhibit-read-only t)

and `

+BIND: inhibit-read-only t

` Then I tried:

(setq inhibit-read-only t) and same result. Inspection inhibit-read-only variable, it seems to be nil globally and t in the local buffer even if I use (setq ...) instead (setq-local ...)

gpetrini commented 3 years ago

I found this line of code which made export to work:

(let ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) ())) However, after I run it, I am not able to save the current buffer :'( So it seems that it is inhibit-read-only related, but I don't know how to change it without side effects.

Next, I tried the following this:

(defun set-region-writeable (begin end)
  "Removes the read-only text property from the marked region."
  ;; See http://stackoverflow.com/questions/7410125
  (interactive "r")
  (let ((modified (buffer-modified-p))
        (inhibit-read-only t))
    (remove-text-properties begin end '(read-only t))
    (set-buffer-modified-p modified)))

Then, I was able to export normally, however the text is copied into the buffer and I cannot use org-transclusion functions anymore (like org-transclusion-remove all since there is no transclusion)

nobiot commented 3 years ago

I suggest you try this function below. I quickly tested it and worked for me -- no problem with exporting and saving afterwards.

You don't need to remove text-properties like the scripts you pasted above -- you probably don't want to. Also, I think you need to set inhibit-read-only globally. If I remember correctly, Org Export copies the buffer to a temp buffer with all the text properties. If you use setq-local, it affects only the orginal buffer, not the temp buffer to be actually exported -- this is my guess.

(defun my/export ()
  (interactive)
  (setq inhibit-read-only t)
  (org-export-dispatch)
  (setq inhibit-read-only nil))
gpetrini commented 3 years ago

Worked like a charm! I'll include in my config. Thank you a lot.

gpetrini commented 3 years ago

Actually, it worked for one transclusion at the end of the file. If a transclude more than one, I got: 'copy-tree: Lisp nesting exceeds ‘max-lisp-eval-depth’ and the export does not work and I am no able to save the buffer. I don't know if this is a org-transclusion or doom-emacs related.

nobiot commented 3 years ago

@gpetrini , I don't get this error. I only transclude 4 parts as per the file you sent me -- I didn't convert all the "include" present in it. Your file contained 3 transclude; I manually changed the last include under *Current version to transclude.

No issue in exporting using the custom function.

Instead, how about just evaluating three lines one by one manually? The function only chains them together as one action; it's just turn off read-only globally, export, and turn read-only back on.

nobiot commented 3 years ago

Emailed the files and HTML to you for your reference.

nobiot commented 3 years ago

I'm responding to your last email here. The last transclusion in the file you gave me this, and it exports to an HTML file that looks like the second image below.

image

image

nobiot commented 3 years ago

I don't use export and don't know what noweb is, so I don't know if this export looks as you intended it to be.

gpetrini commented 3 years ago

noweb is supposed to replace the <<source-block-name>> by the source block code's contents. So, the expected behavior is to return all the previous code in this section. The exported html worked for all text other them code source blocks. Probably, there is a conflict between org-export, noweb syntax, org-transclusion procedures. However, as I emailed you, I think this is more doom-related. My guess is that there are some packages that are pinned in a specific version which causes this problem.

Since this is not an org-transclusion problem, I'll close this issue. If I find out how to fix it, I'll reopen it. For those who have a similar problem, here is my doom-infooutput:

Executing 'doom info' with Emacs 28.0.50 at 2021-07-09 18:35:20
    generated    jul 09, 2021 18:35:20
      system       Debian GNU/Linux 11 (bullseye) Linux 5.10.0-7-amd64 x86_64
      emacs        28.0.50 ~/.emacs.d/ -> ~/.emacs.d/
      doom         3.0.0-alpha HEAD -> develop 42ff36914 2021-07-09 01:13:13 -0400 ~/.doom.d/ -> ~/.doom.d/
      shell        /usr/bin/zsh
      features     ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB
      traits       batch server-running envvar-file custom-file
      modules      :completion (company +childframe) (ivy +fonts +fuzzy +prescient +icons +childframe) :ui deft doom doom-dashboard hl-todo indent-guides (ligatures +extra) modeline nav-flash ophints (popup +all) unicode (window-select +numbers) workspaces :editor (evil +everywhere) file-templates fold (format +onsave) snippets :emacs (dired +icons) electric (ibuffer +icons) (undo +tree) vc :checkers syntax (spell +flyspell +aspell) grammar :tools debugger (eval +overlay) (lookup +dictionary) (lsp +eglot) magit rgb biblio :lang cc data emacs-lisp (ess +lsp) (latex +latexmk +cdlatex +fold +lsp) markdown (org +pretty +dragndrop +roam +jupyter +pandoc +org-bullets +noter +journal +present) (python +lsp) (sh +lsp) :app (rss +org) :config literate (default +bindings +smartparens)
      packages     (org-ref) (ivy-bibtex) (org-pretty-tags) (info-colors) (exec-path-from-shell) (elfeed) (org-bullets) (rainbow-mode) (writeroom-mode) (zen-mode) (ox-reveal) (academic-phrases) (citeproc-org) (async) (elpy) (org-roam-bibtex :recipe (:host github :repo org-roam/org-roam-bibtex)) (org-roam-server) (ess-view) (ess-view-data) (org-appear :recipe (:host github :repo awth13/org-appear)) (elfeed-goodies) (nov) (flycheck-aspell) (lsp-python-ms :disable t) (vlf :recipe (:host github :repo m00natic/vlfi :files (*.el)) :pin cc02f25337... :disable t) (org-pandoc-import :recipe (:host github :repo tecosaur/org-pandoc-import :files (*.el filters preprocessors))) (company-org-block) (dashboard) (org-transclusion :recipe (:host github :repo nobiot/org-transclusion :branch main :files (*.el)))
      unpin        org-roam company-org-roam bibtex-completion helm-bibtex ivy-bibtex

Thank you a lot

nobiot commented 3 years ago

I'll keep it open.

Org-transclusion does not support expansion of noweb references when transcluded source code has them.

jeszyman commented 2 years ago

Thank you for a very useful package, nobiot.

Regarding the modified export with inhibit-read-only:

(defun my/export ()
  (interactive)
  (setq inhibit-read-only t)
  (org-export-dispatch)
  (setq inhibit-read-only nil))

While export of read-only blocks works with this function, I found that it does not set the global inhibit-read-only variable back to nil after export.

But the below function will inhibit-read-only just for the export call. After export, the global variable is unchanged (if originally nil, remains is nil).

(defun my/export ()
  (interactive)  
  (let ((inhibit-read-only t))
    (org-export-dispatch)
        ))
nobiot commented 2 years ago

@jeszyman thank you for this. Yeah, I think I tried the let binding and for some reason I could not make it work. It's good that it works on your end. I have no idea why though.

nobiot commented 2 years ago

I believe the current ELPA version 1.1.1 supports this (fixed for noweb). Closing for now. Please reopen or create a new issue if something is missing

dmitrym0 commented 2 years ago

Hi @nobiot, thank you for a wonderful package. I think it's going to be a game changer for my organization. I'm having the same issue as the original poster:

plantuml_test.org:

:PROPERTIES:
:ID:       C99A5598-567F-4447-8F5E-AF454AEC76C4
:mtime:    20220224150502
:ctime:    20220224150502
:END:
#+title: plantuml test

#+begin_src plantuml :file plantuml-test.png
  !include /Users/dmitry/org-roam/external/C4_Container.puml
  Person_Ext(consumer, "Consumer", "API or real person")
  SHOW_LEGEND()
#+end_src

transclusion_test.org:

:PROPERTIES:
:ID:       D2616496-68B8-424B-ACD8-C59D0A4EA22D
:mtime:    20220224150530
:ctime:    20220224150530
:END:
#+title: transclusion test

#+transclude: [[id:C99A5598-567F-4447-8F5E-AF454AEC76C4][plantuml test]]

Once I try export (C-e h o for HTML) I get the following error:

save-current-buffer: Buffer is read-only: #<buffer *Messages*>

If I

(setq inhibit-read-only t)

it works fine.

Emacs 27.2 on macOS Monterey with org-transclusion 1.2.0.

nobiot commented 2 years ago

@dmitrym0

I just tried with Emacs with no packages and no user configuration, and installed Org-transclusion 1.2.0 from ELPA. I cannot reproduce the problem... My Emacs is 29.0.50 that I compiled on 13 November 2021, on Ubuntu Linux -- this is a different Emacs version from yours but I don't believe it is the cause of the different behaviour.

Could you please try with no configuration and install only with Org-transclusion?

2022-02-26T184903

Unless I can reproduce the issue, I am afraid that I cannot do anything on my end.

nobiot commented 2 years ago

By the way, my Org version is 9.5 -- if it is different to yours, this might explain the issue.

dmitrym0 commented 2 years ago

I'm running Emacs 27.2; but Org 9.5.2.

What's the best way to test emacs with an isolated install? I tried -Q but it still picked up installed org-transclusion.

nobiot commented 2 years ago

What do you mean by “pick up” more precisely?

If you launched Emacs by typing emacs -Q in your terminal, it shouldn’t load org-transclusion automatically.

nobiot commented 2 years ago

I’d temporarily remove the configuration file and directory — e.g. .emacs and .emacs.d. Then launch Emacs and install org-transclusion with M-x package-install

dmitrym0 commented 2 years ago

Thanks @nobiot.

I created a script to run a "cleanroom emacs" instance which you may find useful: https://github.com/dmitrym0/cleanroom-emacs. It allows you to run an isolated instance of emacs.

It turns out you're right; something on my end is causing this behaviour, because I cannot reproduce it in the clean instance. Any advice where to begin trouble shooting it?

nobiot commented 2 years ago

As you are getting an error message, I’d turn on toggle-debug-on-error. It should tell you which function gives you the error, then use edebug to see how programs behave in runtime.