emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* misaligned tab and spaces in src block
@ 2021-05-24 16:07 Michael Dauer
  2021-05-25  1:51 ` Tim Cross
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Dauer @ 2021-05-24 16:07 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

#+begin_src elisp :results output
(aaa
 bbb (
#x09#x09#x09ccc))
      ccc
#+end_src
looks like this in the editor
(aaa
 bbb (
        ccc))
          ccc

Line 1-3 were indented automatically by pressing Tab. In line 4 I inserted
6 spaces manually. This is what I would expect to find in line 3 too. But
at my surprise there are 3 tab chars in line 3. Line 2 was indented
automatically with 1 space.

1. So why is line 3 indented with 3 tabs instead of 6 spaces?
2. How can I prevent this?
3. Why does a tab have a width between 1 and 2 spaces?
4. How can I prevent this misalignment?

org-block face has fixed-pitch.

Org mode version 9.4.6 (9.4.6-gcf30f7
(setq-default tab-width 2)
(setq org-src-fontify-natively t
org-src-window-setup 'current-window
org-src-strip-leading-and-trailing-blank-lines t
org-src-preserve-indentation t
org-src-tab-acts-natively t)

Thanks,
Michael

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

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

* Re: misaligned tab and spaces in src block
  2021-05-24 16:07 misaligned tab and spaces in src block Michael Dauer
@ 2021-05-25  1:51 ` Tim Cross
  2021-06-17 15:40   ` Michael Dauer
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Cross @ 2021-05-25  1:51 UTC (permalink / raw)
  To: emacs-orgmode


Michael Dauer <mick.dauer@gmail.com> writes:

> Hi,
>
> #+begin_src elisp :results output
> (aaa
>  bbb (
> #x09#x09#x09ccc))
>       ccc
> #+end_src
> looks like this in the editor
> (aaa
>  bbb (
>         ccc))
>           ccc
>
> Line 1-3 were indented automatically by pressing Tab. In line 4 I inserted 6 spaces manually. This is what I would expect to find in line 3 too. But at my
> surprise there are 3 tab chars in line 3. Line 2 was indented automatically with 1 space.
>
> 1. So why is line 3 indented with 3 tabs instead of 6 spaces?
> 2. How can I prevent this?
> 3. Why does a tab have a width between 1 and 2 spaces?
> 4. How can I prevent this misalignment?
>
>I don't understand what  org-block face has fixed-pitch.
>
> Org mode version 9.4.6 (9.4.6-gcf30f7
> (setq-default tab-width 2)
> (setq org-src-fontify-natively t
> org-src-window-setup 'current-window
> org-src-strip-leading-and-trailing-blank-lines t
> org-src-preserve-indentation t
> org-src-tab-acts-natively t)
>

Are you editing the source block using org-edit-special (C-c ,)? If not,
then you are not editing the source block with the correct syntax for
elisp and this will throw out auto formatting.

Your example block is invalid elisp code which is 
#+begin_src elisp :results output
  (aaa
   bbb (
        #x09#x09#x09ccc))
  ccc
#+end_src

but I don't see how you can get any output as it is not valid elisp. It
is not clear to me what you are trying to do. You have 3 tab characters
(#x09), so don't see why you would expect them to be spaces? 

If what you want is for hitting tab to insert only spaces, have a look
at the variable indent-tab-mode. You can, for example, do

(setq-default indent-tab-mode nil)

to force use of spaces instead of tabs. However, be careful about doing
this globally if you also want to contribute to projects where tabs are
used as this will cause havoc with diffs and git. You can also set this
on a per language (via mode hooks) or per project (via local variables).

To get a better feel for how language modes align code etc, you really
need to make sure the code you are trying to align is syntactically
valid and you are using the correct coding style for the language. 
--
Tim Cross


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

* Re: misaligned tab and spaces in src block
  2021-05-25  1:51 ` Tim Cross
@ 2021-06-17 15:40   ` Michael Dauer
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Dauer @ 2021-06-17 15:40 UTC (permalink / raw)
  To: Tim Cross; +Cc: emacs-orgmode

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

Hi Tim,

indent-tabs-mode was exactly what I was looking for.

Thank you,
Michael

Am Di., 25. Mai 2021 um 04:39 Uhr schrieb Tim Cross <theophilusx@gmail.com>:

>
> Michael Dauer <mick.dauer@gmail.com> writes:
>
> > Hi,
> >
> > #+begin_src elisp :results output
> > (aaa
> >  bbb (
> > #x09#x09#x09ccc))
> >       ccc
> > #+end_src
> > looks like this in the editor
> > (aaa
> >  bbb (
> >         ccc))
> >           ccc
> >
> > Line 1-3 were indented automatically by pressing Tab. In line 4 I
> inserted 6 spaces manually. This is what I would expect to find in line 3
> too. But at my
> > surprise there are 3 tab chars in line 3. Line 2 was indented
> automatically with 1 space.
> >
> > 1. So why is line 3 indented with 3 tabs instead of 6 spaces?
> > 2. How can I prevent this?
> > 3. Why does a tab have a width between 1 and 2 spaces?
> > 4. How can I prevent this misalignment?
> >
> >I don't understand what  org-block face has fixed-pitch.
> >
> > Org mode version 9.4.6 (9.4.6-gcf30f7
> > (setq-default tab-width 2)
> > (setq org-src-fontify-natively t
> > org-src-window-setup 'current-window
> > org-src-strip-leading-and-trailing-blank-lines t
> > org-src-preserve-indentation t
> > org-src-tab-acts-natively t)
> >
>
> Are you editing the source block using org-edit-special (C-c ,)? If not,
> then you are not editing the source block with the correct syntax for
> elisp and this will throw out auto formatting.
>
> Your example block is invalid elisp code which is
> #+begin_src elisp :results output
>   (aaa
>    bbb (
>         #x09#x09#x09ccc))
>   ccc
> #+end_src
>
> but I don't see how you can get any output as it is not valid elisp. It
> is not clear to me what you are trying to do. You have 3 tab characters
> (#x09), so don't see why you would expect them to be spaces?
>
> If what you want is for hitting tab to insert only spaces, have a look
> at the variable indent-tab-mode. You can, for example, do
>
> (setq-default indent-tab-mode nil)
>
> to force use of spaces instead of tabs. However, be careful about doing
> this globally if you also want to contribute to projects where tabs are
> used as this will cause havoc with diffs and git. You can also set this
> on a per language (via mode hooks) or per project (via local variables).
>
> To get a better feel for how language modes align code etc, you really
> need to make sure the code you are trying to align is syntactically
> valid and you are using the correct coding style for the language.
> --
> Tim Cross
>
>
> --
> Confidentiality Notice:This email and any attachments it may contain are
> intended for the individual or entity above and may be confidential and
> protected by legal privilege. SmartPM Technologies, Inc. makes no
> warranties, express or implied, concerning the accuracy of the information
> contained herein, which is subject to change without notice. Unintended
> recipients should be aware that use of this e-mail or any of its
> attachments in any way is forbidden.
>

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

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

end of thread, other threads:[~2021-06-17 15:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-24 16:07 misaligned tab and spaces in src block Michael Dauer
2021-05-25  1:51 ` Tim Cross
2021-06-17 15:40   ` Michael Dauer

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