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

* Re: [PATCH] Source block fontification handling indentation
  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-25 22:11   ` Pontus Michael
  0 siblings, 2 replies; 5+ messages in thread
From: Bastien @ 2014-03-21  8:23 UTC (permalink / raw)
  To: Pontus Michael; +Cc: emacs-orgmode

Hi Michael,

thanks for the patch.

Pontus Michael <m.pontus@gmail.com> writes:

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

I'm not sure I understand what the real problem is.

Can you describe it against the behavior of the current version?
And maybe provide a minimal recipe to reproduce it?

Did you catch any side-effect of your patch?

Thanks,

-- 
 Bastien

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

* Re: [PATCH] Source block fontification handling indentation
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Pontus Michael @ 2014-03-25 21:59 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode


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

Source block fontification is achieved by copying source block contents
into temporary buffer under appropriate major mode and mirroring face
text-properties into original buffer.

Problem is that this procedure doesn't account for user option
`org-edit-src-content-indentation'. This option adds decorative indentation
to contents of source block after editing with command `org-edit-src-code'.

Correct behavior would be to strip this indentation in order to access the
actual actual source block content. This behavior can be observed during
expansion and during execution of `org-edit-src-code'.

However, when function `org-src-font-lock-fontify-block' copies contents of
src block into temporary buffer it leaves the indentation present.
Beginning whitespace can be significant to some languages semantics and
major-mode fontification  routines.

I have attached a file which will let you see examples of both correct and
incorrect behavior.


On 21 March 2014 12:23, Bastien <bzg@gnu.org> wrote:

> Hi Michael,
>
> thanks for the patch.
>
> Pontus Michael <m.pontus@gmail.com> writes:
>
> > 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.
>
> I'm not sure I understand what the real problem is.
>
> Can you describe it against the behavior of the current version?
> And maybe provide a minimal recipe to reproduce it?
>
> Did you catch any side-effect of your patch?
>
> Thanks,
>
> --
>  Bastien
>

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

[-- Attachment #2: fontification-example.org --]
[-- Type: application/vnd.lotus-organizer, Size: 3901 bytes --]

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

* Re: [PATCH] Source block fontification handling indentation
  2014-03-21  8:23 ` Bastien
  2014-03-25 21:59   ` Pontus Michael
@ 2014-03-25 22:11   ` Pontus Michael
  1 sibling, 0 replies; 5+ messages in thread
From: Pontus Michael @ 2014-03-25 22:11 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode


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

Sorry, the code in last source block in my attachment got a little bit
messed up. I corrected it in this attachment.


On 21 March 2014 12:23, Bastien <bzg@gnu.org> wrote:

> Hi Michael,
>
> thanks for the patch.
>
> Pontus Michael <m.pontus@gmail.com> writes:
>
> > 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.
>
> I'm not sure I understand what the real problem is.
>
> Can you describe it against the behavior of the current version?
> And maybe provide a minimal recipe to reproduce it?
>
> Did you catch any side-effect of your patch?
>
> Thanks,
>
> --
>  Bastien
>

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

[-- Attachment #2: fontification-example.org --]
[-- Type: application/vnd.lotus-organizer, Size: 3901 bytes --]

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

* Re: [PATCH] Source block fontification handling indentation
  2014-03-25 21:59   ` Pontus Michael
@ 2014-03-26 10:07     ` Bastien
  0 siblings, 0 replies; 5+ messages in thread
From: Bastien @ 2014-03-26 10:07 UTC (permalink / raw)
  To: Pontus Michael; +Cc: emacs-orgmode, schulte eric

Hi Michael,

Pontus Michael <m.pontus@gmail.com> writes:

> Source block fontification is achieved by copying source block
> contents into temporary buffer under appropriate major mode and
> mirroring face text-properties into original buffer.

thanks for the change and the detailed explanations.

Eric, I'm short of time this week, so if you have a chance to
review and perhaps apply this change, please go ahead.

Otherwise, I'll review this next week.

Thanks,

-- 
 Bastien

^ permalink raw reply	[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).