emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pontus Michael <m.pontus@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Source block fontification handling indentation
Date: Wed, 26 Feb 2014 20:38:28 +0400	[thread overview]
Message-ID: <CAPpfmHLunVjWNz33TbE6q=vL5o6EkmDeHNS_aiAVgg75vPNFHg@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1835 bytes --]

 I make a change to function which copies contents of source code
block to temporary buffer, applies fontification through the means of
relevant major mode and transcribes text-properties back to org-buffer
so that they are applied on top of code in affected source code block.
Primary reason for this change is to fix the problem which I describe as
follows:

This function is not 100% compatible with a org-edit-src facility,
which provides an option to have indentation added to the code inside
the block after using command `org-edit-src-code' to edit it. This
command also handles removal of indentation upon insertion of the code
in temporary buffer where editing of the code will in relevant
major-mode.

This behavior indicates presence of indentation to be irrelevant
outside the context of org-buffer, and in some instances
(e.g. diff-mode) presence of indentation may render the code
incompatible with semantics of it's language.

Here's a couple of points which guided me to implement the change in
this particular way:

Section of code which mirrors the fontification from temporary to
org-buffer updates variable `start' for each fontified segment, allowing
it to remain relevant as a value which, when added to the position of
point in temporary buffer, will find position of that point mirrored
upon source block in org-buffer. This variable follows same principle if
`org-src-preserve-indentation' option is enabled.

Segments of text fontified to be spanning several lines are broken in
fashion that forces section to end at the newline and continue after the
indentation. This approach prevents indentation characters to be colored
in chaotic fashion when changes in background are used for
fontification, e.g. diff-mode with standard emacs theme.
---
 lisp/org-src.el | 9 +++++++++
 1 file changed, 9 insertions(+)

[-- Attachment #1.2: Type: text/html, Size: 2253 bytes --]

[-- Attachment #2: 0001-Source-block-fontification-handeling-indentation.patch --]
[-- Type: text/x-patch, Size: 1106 bytes --]

diff --git a/lisp/org-src.el b/lisp/org-src.el
index d1f6879..dd3f3c2 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -922,10 +922,19 @@ fontification of code blocks see `org-src-fontify-block' and
 	       (concat " org-src-fontification:" (symbol-name lang-mode)))
 	    (delete-region (point-min) (point-max))
 	    (insert string " ") ;; so there's a final property change
+	    (unless org-src-preserve-indentation (org-do-remove-indentation))
 	    (unless (eq major-mode lang-mode) (funcall lang-mode))
 	    (font-lock-fontify-buffer)
 	    (setq pos (point-min))
 	    (while (setq next (next-single-property-change pos 'face))
+	      (unless org-src-preserve-indentation
+		(let ((eol (save-excursion (goto-char pos)
+					   (line-end-position))))
+		  (with-current-buffer org-buffer
+		    (goto-char (+ start (1- pos)))
+		    (setq start (- (line-end-position) (1- eol))))
+		  (when (< eol next)
+		    (setq next (1+ eol)))))
 	      (put-text-property
 	       (+ start (1- pos)) (1- (+ start next)) 'face
 	       (get-text-property pos 'face) org-buffer)

             reply	other threads:[~2014-02-26 16:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26 16:38 Pontus Michael [this message]
2014-03-21  8:23 ` [PATCH] Source block fontification handling indentation Bastien
2014-03-25 21:59   ` Pontus Michael
2014-03-26 10:07     ` Bastien
2014-03-25 22:11   ` Pontus Michael

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPpfmHLunVjWNz33TbE6q=vL5o6EkmDeHNS_aiAVgg75vPNFHg@mail.gmail.com' \
    --to=m.pontus@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).