emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Indentation of code blocks within lists
@ 2013-05-13 12:11 Francesco Pizzolante
       [not found] ` <87ehdb13lo.fsf-oHC15RC7JGTNLxjTenLetw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Francesco Pizzolante @ 2013-05-13 12:11 UTC (permalink / raw)
  To: mailing-list-org-mode

Hi All,

I'd like to let you know about issues I'm having while trying to put source
code blocks within lists.

Here's my example and how I indent it:

--8<---------------cut here---------------start------------->8---
* First situation

- My first bullet

  We need to do this:

  #+begin_src emacs-lisp
  (message "this is a string")
  (defun x()
    "Doc..."
    (interactive)
    (message "hello"))
  #+end_src

- My second bullet

  #+begin_src emacs-lisp
  "test"
  #+end_src

  #+results:
  : test

  - Sub-point of second bullet

    We need to do this as well:

    #+begin_src emacs-lisp
    (sort)
    #+end_src
--8<---------------cut here---------------end--------------->8---

This way if indenting code blocks has the following advantages:

- it looks nice;

- thanks to the indentation, you directly know at which list level the code
  block belongs to;

- you can easily use Emacs commands (like `C-x TAB') on regions or Org
  promote/demote commands on items or subtrees to edit and reorganize your
  text: "relative" indentation is preserved in all cases.

But, I have 2 issues with it:

- when using `C-c '' (`org-edit-special'), I see spaces before my code, while
  I would expect to see my code starting at column 0 in the edit buffer (the
  "reference" column for the "margin" being, here, the column with the '#'
  from '#+begin_src';

- when exporting, the spaces from column 0 to the start of my code are also
  exported, while I would again expect these spaces to be ignored for the
  export.

The only way I found to fix these issues is to edit my text like this (and
make any code to start in column 0):

--8<---------------cut here---------------start------------->8---
- My first bullet

  We need to do this:

  #+begin_src emacs-lisp
(message "this is a string")
(defun x()
  "Doc..."
  (interactive)
  (message "hello"))
  #+end_src

- My second bullet

  #+begin_src emacs-lisp
"test"
  #+end_src

  #+results:
  : test

  - Sub-point of second bullet

    We need to do this as well:

    #+begin_src emacs-lisp
(sort)
    #+end_src
--8<---------------cut here---------------end--------------->8---

But:

- as you can see, the text does not look anymore as nice as in the previous
  example;

- I'm no longer able to edit and reorganize the text using Emacs `C-x TAB'
  command. That command becomes "forbidden" as it can't correctly respect the
  indentation requirements:

  + starting at column 0 for code;

  + relative for list items (depending on their depth);

- even Org promote/demote commands are buggy in this case: as a simple
  example, when I try to promote (with M-Shift-Left) the last point "Sub-point
  of second bullet" I get an error ("indent-line-to: Wrong type argument:
  wholenump, -2" ) and the following half-baked result:

--8<---------------cut here---------------start------------->8---
  - Sub-point of second bullet

    We need to do this:

    #+begin_src emacs-lisp
(sort)
  #+end_src
--8<---------------cut here---------------end--------------->8---

  The "#+end_src" line got misaligned.

So, my question is the following: is there a way to edit my text as shown in
the first example and edit/export it ignoring the "margin" spaces?

Any help is welcome.

Thanks a lot,
 Francesco

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

* Re: Indentation of code blocks within lists
       [not found] ` <87ehdb13lo.fsf-oHC15RC7JGTNLxjTenLetw@public.gmane.org>
@ 2013-05-21  8:25   ` Francesco Pizzolante
  2013-05-23 22:20     ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Francesco Pizzolante @ 2013-05-21  8:25 UTC (permalink / raw)
  To: mailing-list-org-mode

Hi,

May I bump up this thread?

Thanks,
 Francesco

"Francesco Pizzolante" wrote:
> Hi All,
>
> I'd like to let you know about issues I'm having while trying to put source
> code blocks within lists.
>
> Here's my example and how I indent it:
>
> * First situation
>
> - My first bullet
>
>   We need to do this:
>
>   #+begin_src emacs-lisp
>   (message "this is a string")
>   (defun x()
>     "Doc..."
>     (interactive)
>     (message "hello"))
>   #+end_src
>
> - My second bullet
>
>   #+begin_src emacs-lisp
>   "test"
>   #+end_src
>
>   #+results:
>   : test
>
>   - Sub-point of second bullet
>
>     We need to do this as well:
>
>     #+begin_src emacs-lisp
>     (sort)
>     #+end_src
>
> This way if indenting code blocks has the following advantages:
>
> - it looks nice;
>
> - thanks to the indentation, you directly know at which list level the code
>   block belongs to;
>
> - you can easily use Emacs commands (like `C-x TAB') on regions or Org
>   promote/demote commands on items or subtrees to edit and reorganize your
>   text: "relative" indentation is preserved in all cases.
>
> But, I have 2 issues with it:
>
> - when using `C-c '' (`org-edit-special'), I see spaces before my code, while
>   I would expect to see my code starting at column 0 in the edit buffer (the
>   "reference" column for the "margin" being, here, the column with the '#'
>   from '#+begin_src';
>
> - when exporting, the spaces from column 0 to the start of my code are also
>   exported, while I would again expect these spaces to be ignored for the
>   export.
>
> The only way I found to fix these issues is to edit my text like this (and
> make any code to start in column 0):
>
> - My first bullet
>
>   We need to do this:
>
>   #+begin_src emacs-lisp
> (message "this is a string")
> (defun x()
>   "Doc..."
>   (interactive)
>   (message "hello"))
>   #+end_src
>
> - My second bullet
>
>   #+begin_src emacs-lisp
> "test"
>   #+end_src
>
>   #+results:
>   : test
>
>   - Sub-point of second bullet
>
>     We need to do this as well:
>
>     #+begin_src emacs-lisp
> (sort)
>     #+end_src
>
> But:
>
> - as you can see, the text does not look anymore as nice as in the previous
>   example;
>
> - I'm no longer able to edit and reorganize the text using Emacs `C-x TAB'
>   command. That command becomes "forbidden" as it can't correctly respect the
>   indentation requirements:
>
>   + starting at column 0 for code;
>
>   + relative for list items (depending on their depth);
>
> - even Org promote/demote commands are buggy in this case: as a simple
>   example, when I try to promote (with M-Shift-Left) the last point "Sub-point
>   of second bullet" I get an error ("indent-line-to: Wrong type argument:
>   wholenump, -2" ) and the following half-baked result:
>
>   - Sub-point of second bullet
>
>     We need to do this:
>
>     #+begin_src emacs-lisp
> (sort)
>   #+end_src
>
>   The "#+end_src" line got misaligned.
>
> So, my question is the following: is there a way to edit my text as shown in
> the first example and edit/export it ignoring the "margin" spaces?
>
> Any help is welcome.
>
> Thanks a lot,
>  Francesco

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

* Re: Indentation of code blocks within lists
  2013-05-21  8:25   ` Francesco Pizzolante
@ 2013-05-23 22:20     ` Sebastien Vauban
  2013-05-24 12:31       ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2013-05-23 22:20 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Francesco,

That won't help you, but I've already sent questions on this problem, last
year (Org < 8). See my post on
http://lists.gnu.org/archive/html/emacs-orgmode/2012-02/msg00247.html.

Though, it's (for me) still unfixed as of today.

The good news is that Nicolas seemed OK to look at it, and find a solution for
it...

Best regards,
  Seb

"Francesco Pizzolante" wrote:
> I'd like to let you know about issues I'm having while trying to put source
> code blocks within lists.
>
> Here's my example and how I indent it:
>
> * First situation
>
> - My first bullet
>
>   We need to do this:
>
>   #+begin_src emacs-lisp
>   (message "this is a string")
>   (defun x()
>     "Doc..."
>     (interactive)
>     (message "hello"))
>   #+end_src
>
> - My second bullet
>
>   #+begin_src emacs-lisp
>   "test"
>   #+end_src
>
>   #+results:
>   : test
>
>   - Sub-point of second bullet
>
>     We need to do this as well:
>
>     #+begin_src emacs-lisp
>     (sort)
>     #+end_src
>
> This way if indenting code blocks has the following advantages:
>
> - it looks nice;
>
> - thanks to the indentation, you directly know at which list level the code
>   block belongs to;
>
> - you can easily use Emacs commands (like `C-x TAB') on regions or Org
>   promote/demote commands on items or subtrees to edit and reorganize your
>   text: "relative" indentation is preserved in all cases.
>
> But, I have 2 issues with it:
>
> - when using `C-c '' (`org-edit-special'), I see spaces before my code, while
>   I would expect to see my code starting at column 0 in the edit buffer (the
>   "reference" column for the "margin" being, here, the column with the '#'
>   from '#+begin_src';
>
> - when exporting, the spaces from column 0 to the start of my code are also
>   exported, while I would again expect these spaces to be ignored for the
>   export.
>
> The only way I found to fix these issues is to edit my text like this (and
> make any code to start in column 0):
>
> - My first bullet
>
>   We need to do this:
>
>   #+begin_src emacs-lisp
> (message "this is a string")
> (defun x()
>   "Doc..."
>   (interactive)
>   (message "hello"))
>   #+end_src
>
> - My second bullet
>
>   #+begin_src emacs-lisp
> "test"
>   #+end_src
>
>   #+results:
>   : test
>
>   - Sub-point of second bullet
>
>     We need to do this as well:
>
>     #+begin_src emacs-lisp
> (sort)
>     #+end_src
>
> But:
>
> - as you can see, the text does not look anymore as nice as in the previous
>   example;
>
> - I'm no longer able to edit and reorganize the text using Emacs `C-x TAB'
>   command. That command becomes "forbidden" as it can't correctly respect the
>   indentation requirements:
>
>   + starting at column 0 for code;
>
>   + relative for list items (depending on their depth);
>
> - even Org promote/demote commands are buggy in this case: as a simple
>   example, when I try to promote (with M-Shift-Left) the last point "Sub-point
>   of second bullet" I get an error ("indent-line-to: Wrong type argument:
>   wholenump, -2" ) and the following half-baked result:
>
>   - Sub-point of second bullet
>
>     We need to do this:
>
>     #+begin_src emacs-lisp
> (sort)
>   #+end_src
>
>   The "#+end_src" line got misaligned.
>
> So, my question is the following: is there a way to edit my text as shown in
> the first example and edit/export it ignoring the "margin" spaces?
>
> Any help is welcome.
>
> Thanks a lot,
>  Francesco

-- 
Sebastien Vauban

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

* Re: Indentation of code blocks within lists
  2013-05-23 22:20     ` Sebastien Vauban
@ 2013-05-24 12:31       ` Nicolas Goaziou
       [not found]         ` <87sj1c7e60.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2013-05-24 21:26         ` Sebastien Vauban
  0 siblings, 2 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2013-05-24 12:31 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



Hello,

"Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:

> That won't help you, but I've already sent questions on this problem, last
> year (Org < 8). See my post on
> http://lists.gnu.org/archive/html/emacs-orgmode/2012-02/msg00247.html.
>
> Though, it's (for me) still unfixed as of today.
>
> The good news is that Nicolas seemed OK to look at it, and find a solution for
> it...

AFAICS, your problem was solved. Could you point to what is still wrong?

I also cannot reproduce OP's problem. It may be related to
`org-src-preserve-indentation' value.


Regards,

-- 
Nicolas Goaziou

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

* Re: Indentation of code blocks within lists
       [not found]         ` <87sj1c7e60.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-05-24 14:33           ` Francesco Pizzolante
  0 siblings, 0 replies; 10+ messages in thread
From: Francesco Pizzolante @ 2013-05-24 14:33 UTC (permalink / raw)
  To: Nicolas Goaziou
  Cc: public-emacs-orgmode-mXXj517/zsQ-wOFGN7rlS/M9smdsby/KFg,
	Sebastien Vauban



Hi Nicolas,

> I also cannot reproduce OP's problem. It may be related to
> `org-src-preserve-indentation' value.

Thanks for your answer.

I checked the `org-src-preserve-indentation' variable and saw that it was non
`nil'.

Setting this variable to `nil' fixes the demonstrated issue. But, even then, I
still have an indentation problem.

In the following example (with `org-src-preserve-indentation' set to `nil'):

- in the first headline, I have a code block in a list which is correctly
  exported ignoring the spaces due to the indentation of the Org list;

- in the second headline, I have the same source code but it is split in
  several code blocks in order to better document it. The last 2 blocks are
  not correctly exported as *all spaces before the code* (even those I
  manually added) are ignored.

--8<---------------cut here---------------start------------->8---
* First situation

My list:

- Example which works

  #+begin_src emacs-lisp
  (if complex-condition
      then-block
    else-block)
  #+end_src

* Second situation

My list:

- Example which does not work anymore

  #+begin_src emacs-lisp
  (if complex-condition
  #+end_src

  The "then" block does this:

  #+begin_src emacs-lisp
      then-block
  #+end_src

  The else-block does that:

  #+begin_src emacs-lisp
    else-block)
  #+end_src
--8<---------------cut here---------------end--------------->8---

I think that only the spaces due to the Org indentation (here the number of
spaces before the `#' which delimits the source block, hence 2 spaces) should
be ignored.

IOW, just the "margin" should be removed, and the margin is (IMO) defined as
the spaces from column 0 up to the `#' character.

Thanks for your help.

Regards,
 Francesco

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

* Re: Indentation of code blocks within lists
  2013-05-24 12:31       ` Nicolas Goaziou
       [not found]         ` <87sj1c7e60.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-05-24 21:26         ` Sebastien Vauban
  2013-05-25 12:39           ` Nicolas Goaziou
  1 sibling, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2013-05-24 21:26 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Nicolas,

Nicolas Goaziou wrote:
> "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes:
>
>> That won't help you, but I've already sent questions on this problem, last
>> year (Org < 8). See my post on
>> http://lists.gnu.org/archive/html/emacs-orgmode/2012-02/msg00247.html.
>>
>> Though, it's (for me) still unfixed as of today.
>>
>> The good news is that Nicolas seemed OK to look at it, and find a solution for
>> it...
>
> AFAICS, your problem was solved. Could you point to what is still wrong?
>
> I also cannot reproduce OP's problem. It may be related to
> `org-src-preserve-indentation' value.

Indeed. I have as well `org-src-preserve-indentation' set to `t', for the same
reason as pointed out: if I don't use it that way, then my code blocks which
have different relative depths are exported (in HTML) on the same level, as if
there was no indentation to respect.

So, yes, it does work if you don't need to preserve indentation, you're well
right. But, if not, the indentation is lost on export (and on source editing
with C-c ').

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Indentation of code blocks within lists
  2013-05-24 21:26         ` Sebastien Vauban
@ 2013-05-25 12:39           ` Nicolas Goaziou
       [not found]             ` <87zjvj5j3n.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2013-05-27 14:15             ` Sebastien Vauban
  0 siblings, 2 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2013-05-25 12:39 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



Hello,

"Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
writes:

> Indeed. I have as well `org-src-preserve-indentation' set to `t', for the same
> reason as pointed out: if I don't use it that way, then my code blocks which
> have different relative depths are exported (in HTML) on the same level, as if
> there was no indentation to respect.
>
> So, yes, it does work if you don't need to preserve indentation, you're well
> right. But, if not, the indentation is lost on export (and on source editing
> with C-c ').

I have pushed a fix on maint (at least for the export part, the source
editing one is another story). Could you confirm it behaves as expected?


Regards,

-- 
Nicolas Goaziou

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

* Re: Indentation of code blocks within lists
       [not found]             ` <87zjvj5j3n.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-05-27  8:23               ` Francesco Pizzolante
  0 siblings, 0 replies; 10+ messages in thread
From: Francesco Pizzolante @ 2013-05-27  8:23 UTC (permalink / raw)
  To: Nicolas Goaziou
  Cc: public-emacs-orgmode-mXXj517/zsQ-wOFGN7rlS/M9smdsby/KFg,
	Sebastien Vauban



Hi Nicolas,

> I have pushed a fix on maint (at least for the export part, the source
> editing one is another story). Could you confirm it behaves as expected?

Thanks a lot for your fix: it now works as expected.

Regards,
 Francesco

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

* Re: Indentation of code blocks within lists
  2013-05-25 12:39           ` Nicolas Goaziou
       [not found]             ` <87zjvj5j3n.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-05-27 14:15             ` Sebastien Vauban
  2013-05-27 14:46               ` Sebastien Vauban
  1 sibling, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2013-05-27 14:15 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Nicolas,

Nicolas Goaziou wrote:
> "Sebastien Vauban" writes:
>
>> Indeed. I have as well `org-src-preserve-indentation' set to `t', for the
>> same reason as pointed out: if I don't use it that way, then my code blocks
>> which have different relative depths are exported (in HTML) on the same
>> level, as if there was no indentation to respect.
>>
>> So, yes, it does work if you don't need to preserve indentation, you're
>> well right. But, if not, the indentation is lost on export (and on source
>> editing with C-c ').
>
> I have pushed a fix on maint (at least for the export part, the source
> editing one is another story). Could you confirm it behaves as expected?

I confirm that the export is respecting the indentation up to the virtual
margin (represented by the # character). Excellentissimo!

Thank you ve-ry much...

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: Indentation of code blocks within lists
  2013-05-27 14:15             ` Sebastien Vauban
@ 2013-05-27 14:46               ` Sebastien Vauban
  0 siblings, 0 replies; 10+ messages in thread
From: Sebastien Vauban @ 2013-05-27 14:46 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Nicolas,

"Sebastien Vauban" wrote:
> Nicolas Goaziou wrote:
>> "Sebastien Vauban" writes:
>>
>>> Indeed. I have as well `org-src-preserve-indentation' set to `t', for the
>>> same reason as pointed out: if I don't use it that way, then my code blocks
>>> which have different relative depths are exported (in HTML) on the same
>>> level, as if there was no indentation to respect.
>>>
>>> So, yes, it does work if you don't need to preserve indentation, you're
>>> well right. But, if not, the indentation is lost on export (and on source
>>> editing with C-c ').
>>
>> I have pushed a fix on maint (at least for the export part, the source
>> editing one is another story). Could you confirm it behaves as expected?
>
> I confirm that the export is respecting the indentation up to the virtual
> margin (represented by the # character). Excellentissimo!

I wanted to add that I tested your patch against my LP'ed .emacs file
(~10K lines)... which was then some sort of baptism of fire for it...

Best regards,
  Seb

-- 
Sebastien Vauban

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

end of thread, other threads:[~2013-05-27 14:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-13 12:11 Indentation of code blocks within lists Francesco Pizzolante
     [not found] ` <87ehdb13lo.fsf-oHC15RC7JGTNLxjTenLetw@public.gmane.org>
2013-05-21  8:25   ` Francesco Pizzolante
2013-05-23 22:20     ` Sebastien Vauban
2013-05-24 12:31       ` Nicolas Goaziou
     [not found]         ` <87sj1c7e60.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-05-24 14:33           ` Francesco Pizzolante
2013-05-24 21:26         ` Sebastien Vauban
2013-05-25 12:39           ` Nicolas Goaziou
     [not found]             ` <87zjvj5j3n.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-05-27  8:23               ` Francesco Pizzolante
2013-05-27 14:15             ` Sebastien Vauban
2013-05-27 14:46               ` Sebastien Vauban

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