emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* begin_src Indentation in org 9.4.4, 9.4.5
@ 2021-05-07 21:01 Nathaniel W Griswold
  2021-05-07 21:03 ` Nathaniel W Griswold
  0 siblings, 1 reply; 10+ messages in thread
From: Nathaniel W Griswold @ 2021-05-07 21:01 UTC (permalink / raw)
  To: emacs-orgmode

If i launch emacs with emacs -Q /tmp/blah.org

M-x org-insert-structure-template<RET>s<RET>sh<RET>echo hi<RET>echo hi<RET>

It looks like this:

omw

--
#+begin_src sh                                                                                                            
    echo hi                                                                                                              
  echo hi                                                                                                                
                                                                                                                         
#+end_src 
--                                                                                                               

Is this supposed to be the default behavior or am i doing something wrong?

Nate

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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-07 21:01 begin_src Indentation in org 9.4.4, 9.4.5 Nathaniel W Griswold
@ 2021-05-07 21:03 ` Nathaniel W Griswold
  2021-05-07 22:14   ` Nathaniel W Griswold
  0 siblings, 1 reply; 10+ messages in thread
From: Nathaniel W Griswold @ 2021-05-07 21:03 UTC (permalink / raw)
  To: emacs-orgmode

I messed up the paste, it's supposed to be:

--
#+begin_src sh
    echo hi
  echo hi

#+end_src
--

> On May 7, 2021, at 4:01 PM, Nathaniel W Griswold <nate@manicmind.earth> wrote:
> 
> If i launch emacs with emacs -Q /tmp/blah.org
> 
> M-x org-insert-structure-template<RET>s<RET>sh<RET>echo hi<RET>echo hi<RET>
> 
> It looks like this:
> 
> omw
> 
> --
> #+begin_src sh                                                                                                            
>    echo hi                                                                                                              
>  echo hi                                                                                                                
> 
> #+end_src 
> --                                                                                                               
> 
> Is this supposed to be the default behavior or am i doing something wrong?
> 
> Nate



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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-07 21:03 ` Nathaniel W Griswold
@ 2021-05-07 22:14   ` Nathaniel W Griswold
  2021-05-08  2:22     ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Nathaniel W Griswold @ 2021-05-07 22:14 UTC (permalink / raw)
  To: emacs-orgmode

Sorry i think i scared my email client. I looked at my raw message and some wacky stuff got inserted. I'm rewriting the original message here:

I am wondering if other people experience odd formatting when doing the following in org 9.4.4 and org 9.4.5:

# emacs -Q /tmp/blah.org

M-x org-insert-structure-template<RET>s<RET>sh<RET>echo hi<RET>echo hi<RET>



The formatting i get looks strange:

#+begin_src sh
    echo hi
  echo hi
#+end_src


Thank you


> On May 7, 2021, at 4:03 PM, Nathaniel W Griswold <nate@manicmind.earth> wrote:
> 
> I messed up the paste, it's supposed to be:
> 
> --
> #+begin_src sh
>    echo hi
>  echo hi
> 
> #+end_src
> --
> 



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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-07 22:14   ` Nathaniel W Griswold
@ 2021-05-08  2:22     ` Ihor Radchenko
  2021-05-15 11:50       ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2021-05-08  2:22 UTC (permalink / raw)
  To: Nathaniel W Griswold; +Cc: emacs-orgmode

Nathaniel W Griswold <nate@manicmind.earth> writes:
> The formatting i get looks strange:
>
> #+begin_src sh
>     echo hi
>   echo hi
> #+end_src

Confirmed on master.


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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-08  2:22     ` Ihor Radchenko
@ 2021-05-15 11:50       ` Bastien
  2021-05-15 11:51         ` Nathaniel W Griswold
  2021-05-17  9:02         ` Sébastien Miquel
  0 siblings, 2 replies; 10+ messages in thread
From: Bastien @ 2021-05-15 11:50 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Nathaniel W Griswold, emacs-orgmode

Hi Nathaniel,

Ihor Radchenko <yantar92@gmail.com> writes:

> Nathaniel W Griswold <nate@manicmind.earth> writes:
>> The formatting i get looks strange:
>>
>> #+begin_src sh
>>     echo hi
>>   echo hi
>> #+end_src
>
> Confirmed on master.

Fixed in the maint branch, thanks.

-- 
 Bastien


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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-15 11:50       ` Bastien
@ 2021-05-15 11:51         ` Nathaniel W Griswold
  2021-05-17  9:02         ` Sébastien Miquel
  1 sibling, 0 replies; 10+ messages in thread
From: Nathaniel W Griswold @ 2021-05-15 11:51 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Ihor Radchenko

!!!

Great!

> On May 15, 2021, at 6:50 AM, Bastien <bzg@gnu.org> wrote:
> 
> Hi Nathaniel,
> 
> Ihor Radchenko <yantar92@gmail.com> writes:
> 
>> Nathaniel W Griswold <nate@manicmind.earth> writes:
>>> The formatting i get looks strange:
>>> 
>>> #+begin_src sh
>>>    echo hi
>>>  echo hi
>>> #+end_src
>> 
>> Confirmed on master.
> 
> Fixed in the maint branch, thanks.
> 
> -- 
> Bastien



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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-15 11:50       ` Bastien
  2021-05-15 11:51         ` Nathaniel W Griswold
@ 2021-05-17  9:02         ` Sébastien Miquel
  2021-05-18  6:37           ` Bastien
  1 sibling, 1 reply; 10+ messages in thread
From: Sébastien Miquel @ 2021-05-17  9:02 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Hi Bastien,

The commit `bfda3cc7df31fa79222efb4c190618c3c85a3d04` breaks automatic
(electric) indentation  in src blocks for all configurations.

Here's what happens with the original issue.

When you press `RET` after the first ~hello hi~, the result is that
the first line is indented by two spaces, and the second (where the
point is) isn't.
  - since ~electric-indent-mode~ is on, ~org-return~ is called with
    `indent` set to `t`.
  - Since ~org-src-tab-acts-natively~ is `t`, indentation is done by
    calling `tab` in a src edit buffer, which by itself, does nothing.
  - The observed indentation comes from ~org-src--contents-for-write-back~.
    Since ~org-src--content-indentation~ is 2 and 
~org-src--preserve-indentation~
    is ~nil~, this functions further indents each *non blank* line by 2.

At this point, the first line is indented, cursor is at bol. Note
that you cannot indent your current empty line with `tab`. You can
either indent it manually, or call ~org-edit-special~.

When you write your second line, then press `RET`,
~org-src--contents-for-write-back~ will add an additional two spaces,
producing the reported result.

I think a reasonable fix is to have ~org-src--contents-for-write-back~
also indent blank lines. To do this, you need only remove following
line from its definition.

: (unless (eolp)        ;ignore blank lines

With this done and `bfda3cc7df31fa79222efb4c190618c3c85a3d04`
reverted, the original issue is fixed, and the behaviour is better:
when you press `RET` to enter a newline in a src block, it is
automatically indented.

The downside is that, unless ~org-src--preserve-indentation~ is `t`,
when editing a src block, every empty line will be indented with
spaces (according to ~org-edit-src-content-indentation~ + the
indentation of the #+begin_src line). I think this is reasonable, but
perhaps some might disagree.

Regards,

-- 
Sébastien Miquel



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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-17  9:02         ` Sébastien Miquel
@ 2021-05-18  6:37           ` Bastien
  2021-05-18 13:43             ` Sébastien Miquel
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2021-05-18  6:37 UTC (permalink / raw)
  To: Sébastien Miquel; +Cc: emacs-orgmode

Hi Sébastien,

Sébastien Miquel <sebastien.miquel@posteo.eu> writes:

> The commit `bfda3cc7df31fa79222efb4c190618c3c85a3d04` breaks automatic
> (electric) indentation  in src blocks for all configurations.

Yes, this was intentional: there are many variables interfering in
this area, and preventing electric indentation for src code blocks
seemed acceptable to me.

Before I revert the commit and try your suggestion, can you share a
patch that add both changes (the revert and your fix) manually so I
can test it?  If this fixes the original issue while preserving
electric indentation, I'm okay with it.

Also, do you want to become the maintainer for org-src.el?  We need
more people taking charge of specific areas in Org's code.

Thanks,

-- 
 Bastien


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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-18  6:37           ` Bastien
@ 2021-05-18 13:43             ` Sébastien Miquel
  2021-05-18 14:08               ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Sébastien Miquel @ 2021-05-18 13:43 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

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

Hi Bastien,

Bastien writes:
> Before I revert the commit and try your suggestion, can you share a
> patch that add both changes (the revert and your fix) manually so I
> can test it?  If this fixes the original issue while preserving
> electric indentation, I'm okay with it.
Here's such a patch.

> Also, do you want to become the maintainer for org-src.el?  We need
> more people taking charge of specific areas in Org's code.
I do intend to keep monitoring this list and help around for the
foreseeable future, and I would certainly agree to whatever sort of
maintainer position eventually, but I hold no particular interest (or
deep understanding) in this specific file.

Regards,

-- 
Sébastien Miquel


[-- Attachment #2: 0001-org.el-org-src-contents-for-write-back-Indent-blank-.patch --]
[-- Type: text/x-patch, Size: 2585 bytes --]

From 1be7fa790e68d1fc2d198eee81c0d3bb72156d08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Miquel?= <sebastien.miquel@posteo.eu>
Date: Tue, 18 May 2021 14:39:33 +0200
Subject: [PATCH] org.el (org-src--contents-for-write-back): Indent blank lines

* lisp/org.el (org-src--contents-for-write-back): Indent blank lines.
* lisp/org-src.el (org-return): Revert part of commit bfda3cc7df.
---
 lisp/org-src.el | 9 ++++-----
 lisp/org.el     | 6 +-----
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 5604e6568..79f002e56 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -453,15 +453,14 @@ Assume point is in the corresponding edit buffer."
       (insert (org-no-properties contents))
       (goto-char (point-min))
       (when (functionp write-back) (save-excursion (funcall write-back)))
-      ;; Add INDENTATION-OFFSET to every non-empty line in buffer,
+      ;; Add INDENTATION-OFFSET to every line in buffer,
       ;; unless indentation is meant to be preserved.
       (when (> indentation-offset 0)
 	(while (not (eobp))
 	  (skip-chars-forward " \t")
-	  (unless (eolp)		;ignore blank lines
-	    (let ((i (current-column)))
-	      (delete-region (line-beginning-position) (point))
-	      (indent-to (+ i indentation-offset))))
+	  (let ((i (current-column)))
+	    (delete-region (line-beginning-position) (point))
+	    (indent-to (+ i indentation-offset)))
 	  (forward-line))))))
 
 (defun org-src--edit-element
diff --git a/lisp/org.el b/lisp/org.el
index ae09f3e99..0add9bc2e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18018,10 +18018,6 @@ object (e.g., within a comment).  In these case, you need to use
 	     (delete-and-extract-region (point) (line-end-position))))
 	(org--newline indent arg interactive)
 	(save-excursion (insert trailing-data))))
-     ;; FIXME: In a source block, don't try to indent as it may result
-     ;; in weird results due to `electric-indent-mode' being `t'.
-     ((eq element-type 'src-block)
-      (org--newline nil nil nil))
      (t
       ;; Do not auto-fill when point is in an Org property drawer.
       (let ((auto-fill-function (and (not (org-at-property-p))
@@ -19167,7 +19163,7 @@ Also align node properties according to `org-property-format'."
 		       (line-beginning-position 2))))
 	     nil)
 	    ((and (eq type 'src-block)
-                  org-src-tab-acts-natively
+		  org-src-tab-acts-natively
 		  (> (line-beginning-position)
 		     (org-element-property :post-affiliated element))
 		  (< (line-beginning-position)
-- 
2.31.1


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

* Re: begin_src Indentation in org 9.4.4, 9.4.5
  2021-05-18 13:43             ` Sébastien Miquel
@ 2021-05-18 14:08               ` Bastien
  0 siblings, 0 replies; 10+ messages in thread
From: Bastien @ 2021-05-18 14:08 UTC (permalink / raw)
  To: Sébastien Miquel; +Cc: emacs-orgmode

Hi Sébastien,

Sébastien Miquel <sebastien.miquel@posteo.eu> writes:

> Here's such a patch.

Applied, thanks a lot.

>> Also, do you want to become the maintainer for org-src.el?  We need
>> more people taking charge of specific areas in Org's code.
> I do intend to keep monitoring this list and help around for the
> foreseeable future, and I would certainly agree to whatever sort of
> maintainer position eventually, but I hold no particular interest (or
> deep understanding) in this specific file.

Sure, I understand.  Thanks for your time in helping with this!

Best,

-- 
 Bastien


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

end of thread, other threads:[~2021-05-18 14:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 21:01 begin_src Indentation in org 9.4.4, 9.4.5 Nathaniel W Griswold
2021-05-07 21:03 ` Nathaniel W Griswold
2021-05-07 22:14   ` Nathaniel W Griswold
2021-05-08  2:22     ` Ihor Radchenko
2021-05-15 11:50       ` Bastien
2021-05-15 11:51         ` Nathaniel W Griswold
2021-05-17  9:02         ` Sébastien Miquel
2021-05-18  6:37           ` Bastien
2021-05-18 13:43             ` Sébastien Miquel
2021-05-18 14:08               ` Bastien

Code repositories for project(s) associated with this 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).