emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* left padding added each time a code block is edited
@ 2014-08-07 22:18 Noah Hoffman
  2014-08-07 22:41 ` Thorsten Jolitz
  2014-08-08 15:34 ` Achim Gratz
  0 siblings, 2 replies; 6+ messages in thread
From: Noah Hoffman @ 2014-08-07 22:18 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 556 bytes --]

Hello,

Each time I edit a code block using =C-c '= (org-edit-special) and then
return to the org-mode buffer, two spaces are added to the left margin of
the code. For example,

#+BEGIN_SRC python
print "hello"
#+END_SRC

becomes

#+BEGIN_SRC python
  print "hello"
#+END_SRC

after one round-trip. This is particularly problematic for python code
blocks since leading whitespace is meaningful.

This is behavior that has been present in org-mode for so long that I
suspect that it's not a bug - but I'd love to know how to disable it.

Thanks a lot,
Noah

[-- Attachment #2: Type: text/html, Size: 863 bytes --]

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

* Re: left padding added each time a code block is edited
  2014-08-07 22:18 left padding added each time a code block is edited Noah Hoffman
@ 2014-08-07 22:41 ` Thorsten Jolitz
  2014-08-07 23:08   ` Fwd: " Noah Hoffman
  2014-08-08 15:34 ` Achim Gratz
  1 sibling, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2014-08-07 22:41 UTC (permalink / raw)
  To: emacs-orgmode

Noah Hoffman <noah.hoffman@gmail.com> writes:

Hello,

> Each time I edit a code block using =C-c '= (org-edit-special) and
> then return to the org-mode buffer, two spaces are added to the left
> margin of the code. For example,
>
> #+BEGIN_SRC python
> print "hello"
> #+END_SRC
>
> becomes
>
> #+BEGIN_SRC python
> print "hello"
> #+END_SRC
>
> after one round-trip. This is particularly problematic for python code
> blocks since leading whitespace is meaningful.
>
> This is behavior that has been present in org-mode for so long that I
> suspect that it's not a bug - but I'd love to know how to disable it.

At the risk of being critizised by this mailing-list's QC department I
give you this (unedited) hint:

,----[ C-h v org-edit-src-content-indentation RET ]
| org-edit-src-content-indentation is a variable defined in `org-src.el'.
| Its value is 2
| 
| Documentation:
| Indentation for the content of a source code block.
| This should be the number of spaces added to the indentation of the #+begin
| line in order to compute the indentation of the block content after
| editing it with M-x org-edit-src-code.  Has no effect if
| `org-src-preserve-indentation' is non-nil.
`----

-- 
cheers,
Thorsten

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

* Fwd:  left padding added each time a code block is edited
  2014-08-07 22:41 ` Thorsten Jolitz
@ 2014-08-07 23:08   ` Noah Hoffman
  2014-08-08 13:47     ` Rasmus
  0 siblings, 1 reply; 6+ messages in thread
From: Noah Hoffman @ 2014-08-07 23:08 UTC (permalink / raw)
  To: emacs-orgmode

Noah Hoffman <noah.hoffman@gmail.com> writes:

Hello,

> Each time I edit a code block using =C-c '= (org-edit-special) and
> then return to the org-mode buffer, two spaces are added to the left
> margin of the code. For example,
>
> #+BEGIN_SRC python
> print "hello"
> #+END_SRC
>
> becomes
>
> #+BEGIN_SRC python
> print "hello"
> #+END_SRC
>
> after one round-trip. This is particularly problematic for python code
> blocks since leading whitespace is meaningful.
>
> This is behavior that has been present in org-mode for so long that I
> suspect that it's not a bug - but I'd love to know how to disable it.

At the risk of being critizised by this mailing-list's QC department I
give you this (unedited) hint:

,----[ C-h v org-edit-src-content-indentation RET ]
| org-edit-src-content-indentation is a variable defined in `org-src.el'.
| Its value is 2
|
| Documentation:
| Indentation for the content of a source code block.
| This should be the number of spaces added to the indentation of the #+begin
| line in order to compute the indentation of the block content after
| editing it with M-x org-edit-src-code.  Has no effect if
| `org-src-preserve-indentation' is non-nil.
`----

--
cheers,
Thorsten

Thanks a lot, Thorsten - that's perfect. If I may provide some
suggestions/feedback to the list:

1. A more sensible value for this variable in python code blocks in
particular would be 0 if language-specific defaults are possible
(though I'll be setting my default to 0 for all languages).
2. While this variable is very well documented, it isn't very
discoverable via apropos or the html manual (at least, I wasn't able
to discover it). Perhaps a reference can be added to this variable in
the docstring for org-edit-src-code?

Best,
Noah

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

* Re: left padding added each time a code block is edited
  2014-08-07 23:08   ` Fwd: " Noah Hoffman
@ 2014-08-08 13:47     ` Rasmus
  2014-08-08 15:51       ` Noah Hoffman
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus @ 2014-08-08 13:47 UTC (permalink / raw)
  To: emacs-orgmode

Hi Noah,

Noah Hoffman <noah.hoffman@gmail.com> writes:

> Noah Hoffman <noah.hoffman@gmail.com> writes:
>
>> Each time I edit a code block using =C-c '= (org-edit-special) and
>> then return to the org-mode buffer, two spaces are added to the left
>> margin of the code. For example,
>>
>> #+BEGIN_SRC python
>> print "hello"
>> #+END_SRC
>>
>> becomes
>>
>> #+BEGIN_SRC python
>>   print "hello"
>> #+END_SRC
>>
>> after one round-trip. This is particularly problematic for python code
>> blocks since leading whitespace is meaningful.

Have you experienced any bugs with respect to this? On my system Babel
will even run this code correctly:

#+BEGIN_SRC python
           if True:
               return( "hello!")
#+END_SRC

#+RESULTS:
: hello!


> 2. While this variable is very well documented, it isn't very
> discoverable via apropos or the html manual (at least, I wasn't able
> to discover it). Perhaps a reference can be added to this variable in
> the docstring for org-edit-src-code?

Patches are more than welcome!  There's a guide on Worg:

        http://orgmode.org/worg/org-contribute.html

Cheers,
Rasmus

-- 
A page of history is worth a volume of logic

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

* Re: left padding added each time a code block is edited
  2014-08-07 22:18 left padding added each time a code block is edited Noah Hoffman
  2014-08-07 22:41 ` Thorsten Jolitz
@ 2014-08-08 15:34 ` Achim Gratz
  1 sibling, 0 replies; 6+ messages in thread
From: Achim Gratz @ 2014-08-08 15:34 UTC (permalink / raw)
  To: emacs-orgmode

Noah Hoffman writes:
> This is particularly problematic for python code
> blocks since leading whitespace is meaningful.

The problem you imagine doesn't exist because the leading whitespace is
stripped before the code is sent to the interpreter.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

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

* Re: left padding added each time a code block is edited
  2014-08-08 13:47     ` Rasmus
@ 2014-08-08 15:51       ` Noah Hoffman
  0 siblings, 0 replies; 6+ messages in thread
From: Noah Hoffman @ 2014-08-08 15:51 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

On Fri, Aug 8, 2014 at 6:47 AM, Rasmus <rasmus@gmx.us> wrote:

> Have you experienced any bugs with respect to this? On my system Babel
> will even run this code correctly:
>
> #+BEGIN_SRC python
>            if True:
>                return( "hello!")
> #+END_SRC
>
> #+RESULTS:
> : hello!
>
>

To use a slightly different example:

#+BEGIN_SRC python
  import sys
  for i in range(10):
      print "foo"
#+END_SRC

-*- mode: compilation; default-directory: "~/Downloads/" -*-
Compilation started at Fri Aug  8 08:44:39

~/.emacs.d/bin/pychecker /Users/nhoffman/Downloads/broken.py
/Users/nhoffman/Downloads/broken.py:1:2: unexpected indent
  import sys
 ^
/Users/nhoffman/Downloads/broken.py:1:3: E111 indentation is not a
multiple of four
/Users/nhoffman/Downloads/broken.py:1:3: E113 unexpected indentation
/Users/nhoffman/Downloads/broken.py:2:3: E111 indentation is not a
multiple of four
/Users/nhoffman/Downloads/broken.py:3:7: E111 indentation is not a
multiple of four

Compilation finished at Fri Aug  8 08:44:40

Anything other than 4 spaces per indention level is flagged by python
style/syntax checkers that enforce pep8 (and yes, many flame wars have
been fought on the topic, but there are good reasons for enforcing
consistency). This is an issue when editing code blocks and in tangled
code. Maybe it's primarily an aesthetic thing, but I think that it's
best when possible to set the default to follow the standard
conventions for the language (my python mode certainly seems to think
so!).

>> 2. While this variable is very well documented, it isn't very
>> discoverable via apropos or the html manual (at least, I wasn't able
>> to discover it). Perhaps a reference can be added to this variable in
>> the docstring for org-edit-src-code?
>
> Patches are more than welcome!  There's a guide on Worg:
>
>         http://orgmode.org/worg/org-contribute.html

I'll do so with pleasure! Thanks again.

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

end of thread, other threads:[~2014-08-08 15:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-07 22:18 left padding added each time a code block is edited Noah Hoffman
2014-08-07 22:41 ` Thorsten Jolitz
2014-08-07 23:08   ` Fwd: " Noah Hoffman
2014-08-08 13:47     ` Rasmus
2014-08-08 15:51       ` Noah Hoffman
2014-08-08 15:34 ` Achim Gratz

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