* [Patch] don't add indent for empty line when exiting, a code edit
@ 2014-03-11 0:22 Arun Persaud
2014-03-12 18:08 ` Bastien
0 siblings, 1 reply; 12+ messages in thread
From: Arun Persaud @ 2014-03-11 0:22 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 415 bytes --]
Hi
I started using org babel for python, but when using C-c ' I always
ended up with white space added to the empty lines in the source code
when returning into the org buffer. This especially shows up
(setq-default show-trailing-whitespace t).
I tried to fix this in org. It seems to work over here, but my elisp as
well as my understanding of org-mode is not perfect ;) Let me know if it
needs more work.
Arun
[-- Attachment #2: 0001-lisp-org-src.el-don-t-add-indent-for-empty-line-when.patch --]
[-- Type: text/x-patch, Size: 1223 bytes --]
From e393fed9dbb132fdefff66d304f67f7def643140 Mon Sep 17 00:00:00 2001
From: Arun Persaud <arun@nubati.net>
Date: Mon, 10 Mar 2014 17:09:12 -0700
Subject: [PATCH] lisp/org-src.el: don't add indent for empty line when exiting
a code edit
Using C-c ' to edit code blocks adds an indent to all lines when exiting from
the code edit. This leaves trailing whitespace in the buffer, which can be especially
annoying when using show-trailing-whitespace.
---
lisp/org-src.el | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index d1f6879..ef09bd6 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -737,8 +737,10 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
(unless (or single preserve-indentation (= total-nindent 0))
(setq indent (make-string total-nindent ?\ ))
(goto-char (point-min))
- (while (re-search-forward "^" nil t)
- (replace-match indent)))
+ (while (re-search-forward "^" nil t)
+ (if (not (looking-at "$"))
+ (replace-match indent)
+ (forward-char 1))))
(if (org-bound-and-true-p org-edit-src-picture)
(setq total-nindent (+ total-nindent 2)))
(setq code (buffer-string))
--
1.9.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-11 0:22 [Patch] don't add indent for empty line when exiting, a code edit Arun Persaud
@ 2014-03-12 18:08 ` Bastien
2014-03-12 23:06 ` Charles Berry
0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2014-03-12 18:08 UTC (permalink / raw)
To: Arun Persaud; +Cc: emacs-orgmode
Hi Arun,
Arun Persaud <apersaud@lbl.gov> writes:
> I tried to fix this in org. It seems to work over here, but my elisp as
> well as my understanding of org-mode is not perfect ;) Let me know if it
> needs more work.
Applied, thanks!
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-12 18:08 ` Bastien
@ 2014-03-12 23:06 ` Charles Berry
2014-03-13 8:47 ` Bastien
0 siblings, 1 reply; 12+ messages in thread
From: Charles Berry @ 2014-03-12 23:06 UTC (permalink / raw)
To: emacs-orgmode
Bastien <bzg <at> gnu.org> writes:
>
> Hi Arun,
>
> Arun Persaud <apersaud <at> lbl.gov> writes:
>
> > I tried to fix this in org. It seems to work over here, but my elisp as
> > well as my understanding of org-mode is not perfect ;) Let me know if it
> > needs more work.
>
> Applied, thanks!
>
Bastien,
This seems to have broken org-edit-src-exit. :-(
I cannot figure out what triggers it (hence no ECM), but I sometimes get an
'End of buffer' error from inside the while loop.
I cannot exit the src edit buffer until I revert org-edit-src-exit to its
old version.
HTH,
Chuck
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-12 23:06 ` Charles Berry
@ 2014-03-13 8:47 ` Bastien
2014-03-13 18:03 ` Charles Berry
0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2014-03-13 8:47 UTC (permalink / raw)
To: Charles Berry; +Cc: emacs-orgmode
Hi Charles,
Charles Berry <ccberry@ucsd.edu> writes:
> This seems to have broken org-edit-src-exit. :-(
>
> I cannot figure out what triggers it (hence no ECM), but I sometimes get an
> 'End of buffer' error from inside the while loop.
I just pushed a fix. Can you confirm you don't see the error anymore?
Thanks!
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 8:47 ` Bastien
@ 2014-03-13 18:03 ` Charles Berry
2014-03-13 18:08 ` Bastien
0 siblings, 1 reply; 12+ messages in thread
From: Charles Berry @ 2014-03-13 18:03 UTC (permalink / raw)
To: emacs-orgmode
Bastien <bzg <at> gnu.org> writes:
>
> Hi Charles,
>
> Charles Berry <ccberry <at> ucsd.edu> writes:
>
> > This seems to have broken org-edit-src-exit.
> >
> > I cannot figure out what triggers it (hence no ECM), but I sometimes
> > get an
> > 'End of buffer' error from inside the while loop.
>
> I just pushed a fix. Can you confirm you don't see the error anymore?
>
Time to failure seems longer. But now I get an infinite loop.
The error message is gone. C-g stops the loop, but attempting to exit via
C-c ' re-indents the code and the loop starts again.
Chuck
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 18:03 ` Charles Berry
@ 2014-03-13 18:08 ` Bastien
2014-03-13 19:07 ` Charles Berry
0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2014-03-13 18:08 UTC (permalink / raw)
To: Charles Berry; +Cc: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Time to failure seems longer. But now I get an infinite loop.
Er, sorry for the confusion; should be fixed again.
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 18:08 ` Bastien
@ 2014-03-13 19:07 ` Charles Berry
2014-03-13 19:46 ` Bastien
0 siblings, 1 reply; 12+ messages in thread
From: Charles Berry @ 2014-03-13 19:07 UTC (permalink / raw)
To: emacs-orgmode
Bastien <bzg <at> gnu.org> writes:
>
> Charles Berry <ccberry <at> ucsd.edu> writes:
>
> > Time to failure seems longer. But now I get an infinite loop.
>
> Er, sorry for the confusion; should be fixed again.
>
It is not. I am now back to getting the 'End of Buffer' msg
Chuck
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 19:07 ` Charles Berry
@ 2014-03-13 19:46 ` Bastien
2014-03-13 22:08 ` Charles C. Berry
2014-03-13 22:27 ` Florian Beck
0 siblings, 2 replies; 12+ messages in thread
From: Bastien @ 2014-03-13 19:46 UTC (permalink / raw)
To: Charles Berry; +Cc: emacs-orgmode
Charles Berry <ccberry@ucsd.edu> writes:
> Bastien <bzg <at> gnu.org> writes:
>
>>
>> Charles Berry <ccberry <at> ucsd.edu> writes:
>>
>> > Time to failure seems longer. But now I get an infinite loop.
>>
>> Er, sorry for the confusion; should be fixed again.
>
> It is not. I am now back to getting the 'End of Buffer' msg
Ok, let me take some fresh air and come back to this later on.
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 19:46 ` Bastien
@ 2014-03-13 22:08 ` Charles C. Berry
2014-03-13 22:27 ` Florian Beck
1 sibling, 0 replies; 12+ messages in thread
From: Charles C. Berry @ 2014-03-13 22:08 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
On Thu, 13 Mar 2014, Bastien wrote:
> Charles Berry <ccberry@ucsd.edu> writes:
>
>> Bastien <bzg <at> gnu.org> writes:
>>
>>>
>>> Charles Berry <ccberry <at> ucsd.edu> writes:
>>>
>>>> Time to failure seems longer. But now I get an infinite loop.
>>>
>>> Er, sorry for the confusion; should be fixed again.
>>
>> It is not. I am now back to getting the 'End of Buffer' msg
>
> Ok, let me take some fresh air and come back to this later on.
Perhaps
- (forward-char 1))))
+ (forward-line 1))))
as the latter will not throw an error when (eobp) ?
Chuck
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 19:46 ` Bastien
2014-03-13 22:08 ` Charles C. Berry
@ 2014-03-13 22:27 ` Florian Beck
2014-03-14 9:00 ` Bastien
1 sibling, 1 reply; 12+ messages in thread
From: Florian Beck @ 2014-03-13 22:27 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode
On 13.03.2014 20:46, Bastien wrote:
> Ok, let me take some fresh air and come back to this later on.
>
How about this:
(while (re-search-forward "\\(^\\).+" nil t)
(replace-match indent nil nil nil 1)))
--
Florian Beck
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-13 22:27 ` Florian Beck
@ 2014-03-14 9:00 ` Bastien
2014-03-14 18:46 ` Arun Persaud
0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2014-03-14 9:00 UTC (permalink / raw)
To: Florian Beck; +Cc: emacs-orgmode
Hi Florian,
Florian Beck <fb@miszellen.de> writes:
> On 13.03.2014 20:46, Bastien wrote:
>> Ok, let me take some fresh air and come back to this later on.
>
> How about this:
>
> (while (re-search-forward "\\(^\\).+" nil t)
> (replace-match indent nil nil nil 1)))
Works fine here, I pushed this solution. Thanks!
--
Bastien
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Patch] don't add indent for empty line when exiting, a code edit
2014-03-14 9:00 ` Bastien
@ 2014-03-14 18:46 ` Arun Persaud
0 siblings, 0 replies; 12+ messages in thread
From: Arun Persaud @ 2014-03-14 18:46 UTC (permalink / raw)
To: emacs-orgmode
On 03/14/2014 02:00 AM, Bastien wrote:
> Hi Florian,
>
> Florian Beck <fb@miszellen.de> writes:
>
>> On 13.03.2014 20:46, Bastien wrote:
>>> Ok, let me take some fresh air and come back to this later on.
>>
>> How about this:
>>
>> (while (re-search-forward "\\(^\\).+" nil t)
>> (replace-match indent nil nil nil 1)))
>
> Works fine here, I pushed this solution. Thanks!
Thanks everyone for fixing this!
Arun
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-03-14 18:46 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-11 0:22 [Patch] don't add indent for empty line when exiting, a code edit Arun Persaud
2014-03-12 18:08 ` Bastien
2014-03-12 23:06 ` Charles Berry
2014-03-13 8:47 ` Bastien
2014-03-13 18:03 ` Charles Berry
2014-03-13 18:08 ` Bastien
2014-03-13 19:07 ` Charles Berry
2014-03-13 19:46 ` Bastien
2014-03-13 22:08 ` Charles C. Berry
2014-03-13 22:27 ` Florian Beck
2014-03-14 9:00 ` Bastien
2014-03-14 18:46 ` Arun Persaud
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.