emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Source block fontification handling indentation
@ 2014-02-26 16:38 Pontus Michael
  2014-03-21  8:23 ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Pontus Michael @ 2014-02-26 16:38 UTC (permalink / raw)
  To: emacs-orgmode


[-- 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)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-26 10:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-26 16:38 [PATCH] Source block fontification handling indentation Pontus Michael
2014-03-21  8:23 ` Bastien
2014-03-25 21:59   ` Pontus Michael
2014-03-26 10:07     ` Bastien
2014-03-25 22:11   ` Pontus Michael

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).