all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* indentation - always a pita
@ 2003-06-24 22:28 Harry Putnam
  0 siblings, 0 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-24 22:28 UTC (permalink / raw)


Maybe its just because I only have 3 brain cells to rub together. But
it always seems like a massive undertaking to do anything about
indentation in some of the scripting or language modes.

In the instant case its Shell-script (bash)
Pressing Ctrl-Alt \ to format the entire buffer.

Gives me something like:

if [ ];then
    if [ ];then
	case $opt in
	    t) cmd
		if  [ ];then 
		    cmd
		fi
		;;
	    h) cmd
		if [ ];then
		    case $otheropt in
			a) cmd
			    if [ ];then
				cmd
			    fi
			    ;;
			b) cmd
                            ::
	            esac
                fi
        esac
	if [];then
	    cmd
	fi
    fi
fi

Admittedly a bit contrived but this seems a little extreme to me.  Now
to do something about this, I dimmly recall starting to before and
quickly discovering its quite complicated.

I'd like something closer to what cperl does.  Also I'd like there to
be NO TABS whatever.  Using tabs in code is guaranteed to cause a
problem sooner or later, when one is forced to edit with something
besides emacs.

So what is the simplist route to getting something like
if [ ];then
  if [ ];then
    if [];then
      cmd
    fi
  fi
fi

Two spaces per clause and 2 spaces for actions inside clause.
No tabs at all.

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

* Re: indentation - always a pita
       [not found] <mailman.8589.1056493977.21513.help-gnu-emacs@gnu.org>
@ 2003-06-25  6:14 ` Kai Großjohann
  2003-06-25 13:30   ` Harry Putnam
  0 siblings, 1 reply; 11+ messages in thread
From: Kai Großjohann @ 2003-06-25  6:14 UTC (permalink / raw)


Harry Putnam <reader@newsguy.com> writes:

> Two spaces per clause and 2 spaces for actions inside clause.
> No tabs at all.

I just had a quick look, but maybe you could check

(setq sh-indentation 2)
(setq-default indent-tabs-mode nil)

(The variable indent-tabs-mode is buffer-local by default.  With
setq-default, most modes will avoid tabs for indentation.  If you
only want to tweak this for shell script mode, then you can do it
with a mode hook.)
-- 
~/.signature

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

* Re: indentation - always a pita
  2003-06-25  6:14 ` Kai Großjohann
@ 2003-06-25 13:30   ` Harry Putnam
  2003-06-25 14:15     ` Harry Putnam
  2003-06-25 17:13     ` Kai Großjohann
  0 siblings, 2 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-25 13:30 UTC (permalink / raw)


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

kai.grossjohann@gmx.net (Kai Großjohann) writes:
> I just had a quick look, but maybe you could check
> 
> (setq sh-indentation 2)
> (setq-default indent-tabs-mode nil)
> 
> (The variable indent-tabs-mode is buffer-local by default.  With
> setq-default, most modes will avoid tabs for indentation.  If you
> only want to tweak this for shell script mode, then you can do it
> with a mode hook.)

I just tried this, but not sure its a fair test:

1) Put the two lines you suggest as sole entries in lisp.el then start
   a fresh emacs. (emacs -q -no-site-file -bg midnightblue -l ./lisp.el -l ./vi-list.el)
(vi-list.el is some plaguerized code that allows one to display a
   buffer as if vi's `list' command had been run on it. (showing
   ^I = tab $= newline)

   Set background different than usual so I could keep track of which
   emacs has the new code.

2) Started a second emacs (emacs -q -no-site-file -l ./vi-list.el)
   (without the new code)

Ran C-x h then C-M \ on both  Then saved the results as:
shellt1.sh (new code)
shellt2.sh (no new code) 

Both files are attached.
invoking vi-list shows the tabs are gone, but strangely the code is
formatted almost the same.  The deepest indentation being only 2 spcs
different. I would have expected to gain quite a lot more.

The source file looks like:
Cat shell-script.sh
if [ ];then
if [ ];then
case $opt in
t) cmd
lf  [ ];then 
cmd
fi
;;
h) cmd
if [ ];then
case $otheropt in
a) cmd
if [ ];then
cmd
fi
;;
b) cmd
::
esac
fi
 esac
if [];then
cmd
ii
fi
fi


[-- Attachment #2: with new code --]
[-- Type: application/x-sh, Size: 493 bytes --]

[-- Attachment #3: without new code --]
[-- Type: application/x-sh, Size: 276 bytes --]

[-- Attachment #4: Type: text/plain, Size: 151 bytes --]

_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: indentation - always a pita
  2003-06-25 13:30   ` Harry Putnam
@ 2003-06-25 14:15     ` Harry Putnam
  2003-06-25 17:13     ` Kai Großjohann
  1 sibling, 0 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-25 14:15 UTC (permalink / raw)


Harry Putnam <reader@newsguy.com> writes:


> formatted almost the same.  The deepest indentation being only 2 spcs
> different. I would have expected to gain quite a lot more.

My bad.  They are formatted the same.  Deepest indentation is 24 spcs
in both cases.  I was looking at the wrong number on mode line.

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

* Re: indentation - always a pita
  2003-06-25 13:30   ` Harry Putnam
  2003-06-25 14:15     ` Harry Putnam
@ 2003-06-25 17:13     ` Kai Großjohann
  2003-06-26  4:13       ` Harry Putnam
       [not found]       ` <mailman.8648.1056600891.21513.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 11+ messages in thread
From: Kai Großjohann @ 2003-06-25 17:13 UTC (permalink / raw)


Harry Putnam <reader@newsguy.com> writes:

> 1) Put the two lines you suggest as sole entries in lisp.el then start
>    a fresh emacs. (emacs -q -no-site-file -bg midnightblue -l ./lisp.el -l ./vi-list.el)
> (vi-list.el is some plaguerized code that allows one to display a
>    buffer as if vi's `list' command had been run on it. (showing
>    ^I = tab $= newline)

Hm.  When you are editing the shell script snippet, does C-h v say
that the two variables have the right values?
-- 
~/.signature

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

* Re: indentation - always a pita
  2003-06-25 17:13     ` Kai Großjohann
@ 2003-06-26  4:13       ` Harry Putnam
       [not found]       ` <mailman.8648.1056600891.21513.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-26  4:13 UTC (permalink / raw)


kai.grossjohann@gmx.net (Kai Großjohann) writes:

> Harry Putnam <reader@newsguy.com> writes:
>
>> 1) Put the two lines you suggest as sole entries in lisp.el then start
>>    a fresh emacs. (emacs -q -no-site-file -bg midnightblue -l ./lisp.el -l ./vi-list.el)
>> (vi-list.el is some plaguerized code that allows one to display a
>>    buffer as if vi's `list' command had been run on it. (showing
>>    ^I = tab $= newline)
>
> Hm.  When you are editing the shell script snippet, does C-h v say
> that the two variables have the right values?

Yup, they check out.  The only noticable change is that the tabs are
missing.

C-h v <ret>  sh-indentation <ret>
sh-indentation's value is 2

C-h v <ret> indent-tabs-mode <ret>
indent-tabs-mode's value is nil
Automatically becomes buffer-local when set in any fashion.

I thought I remembered this being a big pita and I guess it is...

Actual formatted sample with those vars in place:
======================================
if [ ];then
    if [ ];then
        case $opt in
            t) cmd
            lf  [ ];then 
        cmd
    fi
    ;;
            h) cmd
            if [ ];then
                case $otheropt in
                    a) cmd
                    if [ ];then
                        cmd
                    fi
                    ;;
                    b) cmd
                    ::
                esac
            fi
        esac
        if [];then
            cmd
            ii
        fi
fi

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

* Re: indentation - always a pita
       [not found]       ` <mailman.8648.1056600891.21513.help-gnu-emacs@gnu.org>
@ 2003-06-26  9:13         ` Jens Schmidt
  2003-06-26 18:21           ` Harry Putnam
                             ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jens Schmidt @ 2003-06-26  9:13 UTC (permalink / raw)


Harry Putnam <reader@newsguy.com> writes:

> C-h v <ret>  sh-indentation <ret>
> sh-indentation's value is 2

Try `sh-basic-offset' instead.  That's what I use.  I tried to
format your example with the following result:

if [ ];then
  if [ ];then
    case $opt in
      t) cmd
        lf  [ ];then 
    cmd
  fi
  ;;
      h) cmd
        if [ ];then
          case $otheropt in
            a) cmd
              if [ ];then
                cmd
              fi
              ;;
            b) cmd
              ::
          esac
        fi
    esac
    if [];then
      cmd
      ii
    fi
fi

Jens

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

* Re: indentation - always a pita
  2003-06-26  9:13         ` Jens Schmidt
@ 2003-06-26 18:21           ` Harry Putnam
  2003-06-26 18:35           ` Harry Putnam
       [not found]           ` <mailman.8693.1056654403.21513.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-26 18:21 UTC (permalink / raw)


Jens Schmidt <Jens.Schmidt27@epost.de> writes:

> Try `sh-basic-offset' instead.  That's what I use.  I tried to
> format your example with the following result:

Yeah, now we're talking.  combine this with Kai's suggestion
(setq-default indent-tabs-mode nil)
Gets rid of tabs

(setq sh-basic-offset 2)
Gets rid of the radical indentation.

Even the deepest offset is 16 spc instead of 24.
I think this is a more sensible setup.  But of course haven't tested
it thoroughly.

Think I might try submitting a bug report to the maintainers and see
if there is a good reason why the default is so radical.

PS- The example sh code I posted as legitamate format was actually
ridled with syntax errors.  Here is a better example:

if [ ];then
if [ ];then
case $option
t)cmd
if[];then
cmd
fi
;;
h)cmd
if[];then
case $otheroption
a) cmd
if[];then
cmd
fi
;;
b) cmd
;;
esac
;;
esac
fi
if[];then
cmd
fi
fi
fi

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

* Re: indentation - always a pita
  2003-06-26  9:13         ` Jens Schmidt
  2003-06-26 18:21           ` Harry Putnam
@ 2003-06-26 18:35           ` Harry Putnam
       [not found]           ` <mailman.8693.1056654403.21513.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-26 18:35 UTC (permalink / raw)



> Try `sh-basic-offset' instead.  That's what I use.  I tried to
> format your example with the following result:

Thanks Jens, that does look a lot better. 
But one of the things I was after was so I could open the same files
with vim and not see radical changes.

I may have missed the boat on that.  In fact after testing a little
bit more it appears the only way both editors display the code ok is
if I leave emacs defaults in place.  But it seems like awfully deep
indentaition. 

I may never have actually left a shell script in default format.  So
what I was seeing in vim may have been of my own creation.

I wondered if you have a chance, if you might test out your settings
by formatting the enclosed code with emacs.  Then open the file in
vim. (vanilla) and see if it looks ok.  I suspect you may have more
customization in place than I do.  I might want to plaguerize some.

On my setup, using your suggestion and Kais about tabs does look much
nicer but displays bad in vim.  So leaving tabs alone and just using
your suggestion on offset.  Its closer but still displays bad in vim.
Leaving emacs entirely vanilla on those vars produces a file that vim
displays well.  But seems to have unnecessarily deep indentation.
So I may have been beating myself up for nothing.  Maybe just leaving
it alone will be the best solution.  Maybe emacs maintainers had the
right idea to start with.

if [ ];then
if [ ];then
case $option
t)cmd
if[];then
cmd
fi
;;
h)cmd
if[];then
case $otheroption
a) cmd
if[];then
cmd
fi
;;
b) cmd
;;
esac
;;
esac
fi
if[];then
cmd
fi
fi
fi

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

* Re: indentation - always a pita
       [not found]           ` <mailman.8693.1056654403.21513.help-gnu-emacs@gnu.org>
@ 2003-06-27 10:21             ` Jens Schmidt
  2003-06-27 20:35               ` Harry Putnam
  0 siblings, 1 reply; 11+ messages in thread
From: Jens Schmidt @ 2003-06-27 10:21 UTC (permalink / raw)


Harry Putnam <reader@newsguy.com> writes:

> > Try `sh-basic-offset' instead.  That's what I use.  I tried to
> > format your example with the following result:
> 
> Thanks Jens, that does look a lot better. 
> But one of the things I was after was so I could open the same files
> with vim and not see radical changes.
>
> [...]
>
> On my setup, using your suggestion and Kais about tabs does look much
> nicer but displays bad in vim.  So leaving tabs alone and just using
> your suggestion on offset.  Its closer but still displays bad in vim.
> Leaving emacs entirely vanilla on those vars produces a file that vim
> displays well.

The main problem seems to be vim and not Emacs, I think.

If I format your example with `sh-basic-offset' set to 2 and
`indent-tabs-mode' set to nil I get the result shown below in
Emacs.  I confirmed that there are no TABs in it by doing C-s
TAB.  I saved the example to ~/tmp/xxx and opened that file with
the version of vi that I have (MKS NT vi).

Of course, I get the same results as in Emacs since a blank is a
blank in vi, too.

So the question is: What does look so radically different in your
vim?  Have you tried looking at the file using a simple less or
cat?  Does that look different from Emacs or vim?  How?  Are you
sure that your vim is really vanilla?

Jens

if [ ];then
  if [ ];then
    case $option
      t)cmd
      if[];then
        cmd
      fi
      ;;
      h)cmd
        if[];then
          case $otheroption
            a) cmd
            if[];then
              cmd
            fi
            ;;
            b) cmd
              ;;
          esac
          ;;
    esac
        fi
        if[];then
          cmd
        fi
  fi
fi

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

* Re: indentation - always a pita
  2003-06-27 10:21             ` Jens Schmidt
@ 2003-06-27 20:35               ` Harry Putnam
  0 siblings, 0 replies; 11+ messages in thread
From: Harry Putnam @ 2003-06-27 20:35 UTC (permalink / raw)


Jens Schmidt <Jens.Schmidt27@epost.de> writes:

> Of course, I get the same results as in Emacs since a blank is a
> blank in vi, too.

Yup, I must have done poor testing or something.  Probably got
confused what was in which file.  

My theory all along was that leaving out the tabs would be beneficial
to any other editor that came alone.  You test and now mind confirm
that.  Thanks.

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

end of thread, other threads:[~2003-06-27 20:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-24 22:28 indentation - always a pita Harry Putnam
     [not found] <mailman.8589.1056493977.21513.help-gnu-emacs@gnu.org>
2003-06-25  6:14 ` Kai Großjohann
2003-06-25 13:30   ` Harry Putnam
2003-06-25 14:15     ` Harry Putnam
2003-06-25 17:13     ` Kai Großjohann
2003-06-26  4:13       ` Harry Putnam
     [not found]       ` <mailman.8648.1056600891.21513.help-gnu-emacs@gnu.org>
2003-06-26  9:13         ` Jens Schmidt
2003-06-26 18:21           ` Harry Putnam
2003-06-26 18:35           ` Harry Putnam
     [not found]           ` <mailman.8693.1056654403.21513.help-gnu-emacs@gnu.org>
2003-06-27 10:21             ` Jens Schmidt
2003-06-27 20:35               ` Harry Putnam

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.