From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: loss of text properties in org-export--generate-copy-script Date: Tue, 27 Nov 2018 13:21:57 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000001370b4057ba98739" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRhzx-0007H1-6t for emacs-orgmode@gnu.org; Tue, 27 Nov 2018 13:22:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRhzw-0004it-5Q for emacs-orgmode@gnu.org; Tue, 27 Nov 2018 13:22:13 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:52006) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRhzv-0004iV-Po for emacs-orgmode@gnu.org; Tue, 27 Nov 2018 13:22:12 -0500 Received: by mail-wm1-x334.google.com with SMTP id j207so13803wmj.1 for ; Tue, 27 Nov 2018 10:22:11 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: org-mode-email --0000000000001370b4057ba98739 Content-Type: text/plain; charset="UTF-8" In the function org-export--generate-copy-script, the buffer contents are copied over with buffer-substring-no-properties, so it appears that all text properties are lost in the temporary copy. I wondered why that is done? I came across this because I was using text properties to find pieces of text to modify before exporting in a org-export-before hook, but it doesn't work since the text properties are gone. The text properties are put on by font-lock. Curiously, if I add these three lines (switch-to-buffer (current-buffer)) (sem-mode 1) # refontifies buffer (message-box "") then the text-properties are put back on and I can find them again. If leave the first or last line off though, this does not work. The last line is especially mystifying. Here is a minimal example that shows the issue. When you run the src block, the word red will be italicized, and when you export it red will be turned into the word yellow. without the unintuitive switch-to-buffer and message box lines though, you will get an error. Any ideas on what is happening here? # begin This is red. #+BEGIN_SRC emacs-lisp :results silent :exports none (font-lock-add-keywords nil '(("red" 0 '(face italic changeme t)))) (defun preprocess (backend) (switch-to-buffer (current-buffer)) (font-lock-add-keywords nil '(("red" 0 '(face italic changeme t)))) (message-box "") (let* ((start (next-single-property-change (point) 'changeme)) (end (next-single-property-change start 'changeme))) (setf (buffer-substring start end) "yellow"))) (add-hook 'org-export-before-processing-hook 'preprocess nil t) #+END_SRC John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu --0000000000001370b4057ba98739 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In the function=C2=A0org-export--generate-copy-script, the buffer= contents are copied over with=C2=A0buffer-substring-no-properties, so it a= ppears that all text properties are lost in the temporary copy.

I wondered why that is done?=C2=A0

=
I came across this because I was using text properties to find p= ieces of text to modify before exporting in a org-export-before hook, but i= t doesn't work since the text properties are gone.=C2=A0

The text properties are put on by font-= lock. Curiously, if I add these three lines

=C2=A0 (switch-to-buffer (current-buffer= ))
=C2=A0 (sem-mode 1)=C2=A0 # refontifies buffer
=C2=A0 (message-box "")

then the text-properties are put back on a= nd I can find them again. If leave the first or last line off though, this = does not work. The last line is especially mystifying.

Here is a minimal example that shows the issue= . When you run the src block, the word red will be italicized, and when you= export it red will be turned into the word yellow. without the unintuitive= switch-to-buffer and message box lines though, you will get an error.

Any ideas on what is happening here?
=

# begin
This is red.


#+BEGIN_SRC emacs-lisp :results silent :exports none
(font-lock-add-keywords
=C2=A0nil
=C2=A0'(("red" 0 '(face italic chang= eme t))))


(defun preprocess (backend)
=C2=A0 (switch= -to-buffer (current-buffer))
=C2=A0 (font-lock-add-ke= ywords
=C2=A0 =C2=A0nil
=C2=A0 = =C2=A0'(("red" 0 '(face italic changeme t))))
=C2=A0 (message-box "")
=C2=A0 (= let* ((start (next-single-property-change (point) 'changeme))
(end (next-single-pro= perty-change start 'changeme)))
=C2=A0 =C2=A0 (se= tf (buffer-substring start end) "yellow")))

(add-hook 'org-export-before-processing-hoo= k 'preprocess nil t)
#+END_SRC

John

-----------------------------------
Professor = John Kitchin=C2=A0
Doherty Hall A207F
Department of Chemical Engineer= ing
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
--0000000000001370b4057ba98739--