all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Trying to use only tabs for indenting c# files - csharp-mode error?
@ 2012-01-08 13:01 Guido Van Hoecke
  2012-01-08 14:58 ` Óscar Fuentes
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Guido Van Hoecke @ 2012-01-08 13:01 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Óscar Fuentes

Hi,

Objective: use only tabs for indenting c# files

I start with an 'emacs -Q' session.

	C-x C-f MyClass.cs

(This file has been created with MonoDevelop, and uses only tabs for
indentation, and - in MonoDevelop - the tab width is set to 4.)

As expected, MyClass.cs is shown in fundamental mode.

We want to see the whitespace, so

	M-x whitespace-mode

This shows clearly that only tabs are used for indentation.

So lets load csharp-mode and select that mode:

	M-x load-file csharp-mode.el
	M-X csharp-mode

That removes the whitespace visualisation, so reactivate it:

	M-x whitespace-mode

Tell emacs that it should use tabs for indenting:

	M-x set-variable [enter] indent-tabs-mode [enter] t [enter]

Ultimately, I want the tab-width set to 4, but for now I just want to
leave or set it to 8:

	M-x set-variable [enter] tab-width [enter] 8 [enter]

I will use following legend when showing file content:
# represents a leading tab
+ represents a leading empty space (following a preceding tab)
= represents a leading space character

Here's the source file:

namespace Application
{
#+++++++public class MyClass
#+++++++{
#+++++++#+++++++public MyClass ()
#+++++++#+++++++{
#+++++++#+++++++}
#+++++++}
}

Deleting the first tab changes it to:

namespace Application
{
=======public class MyClass
#+++++++{
#+++++++#+++++++public MyClass ()
#+++++++#+++++++{
#+++++++#+++++++}
#+++++++}
}

Hitting tab key while point is the 'public class' line changes it to:

namespace Application
{
==public class MyClass
#+++++++{
#+++++++#+++++++public MyClass ()
#+++++++#+++++++{
#+++++++#+++++++}
#+++++++}
}

I can't help but feeling that this is in error!

The tab-width is 8,
indent-tabs-mode is t
and still, it uses spaces to indent, and only two of them.

For the record, the emacs and csharp-mode versions:

GNU Emacs 23.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.36)
 of 2011-12-13 on bob.porkrind.org

 ;;; csharp-mode.el --- C# mode derived mode

;; Author     : Dylan R. E. Moonfire (original)
;; Maintainer : Dino Chiesa <dpchiesa@hotmail.com>
;; Created    : Feburary 2005
;; Modified   : May 2011
;; Version    : 0.8.6
;; Keywords   : c# languages oop mode
;; X-URL      : http://code.google.com/p/csharpmode/
;; Last-saved : <2011-May-21 20:28:30>

So one more test: insert a 'public string MyString' line
before the 'public Myclass()' line by positioning point after the second
{ and just typing:

namespace Application
{
==public class MyClass
#+++++++{
#+++++++==public string MyString;
#+++++++#+++++++public MyClass ()
#+++++++#+++++++{
#+++++++#+++++++}
#+++++++}
}

The leading tab is respected and replicated, but the new line is then
indented by two spaces rather than by an extra tab!?

And finally"

	M-<
	C-SPC
	M->
	<tab>

produces following result:


namespace Application
{
==public class MyClass
=={
====public string MyString;
====public MyClass ()
===={
====}
==}
}

So obviously neither tab-width nor indent-tabs-mode are obeyed nor
respected!

Please advise,

TIA,


Guido

--
If I had only known, I would have been a locksmith.
		-- Albert Einstein

http://vanhoecke.org ... and go2 places!



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

* Re: Trying to use only tabs for indenting c# files - csharp-mode error?
  2012-01-08 13:01 Trying to use only tabs for indenting c# files - csharp-mode error? Guido Van Hoecke
@ 2012-01-08 14:58 ` Óscar Fuentes
  2012-01-08 15:49   ` Guido Van Hoecke
  2012-01-08 17:29 ` PJ Weisberg
  2012-01-08 19:06 ` Óscar Fuentes
  2 siblings, 1 reply; 7+ messages in thread
From: Óscar Fuentes @ 2012-01-08 14:58 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: help-gnu-emacs

Hello Guido.

I have no time right now to delve into this problem, but this may be
interesting:

C-h f csharp-mode

<snipped documentation...>
    (setq indent-tabs-mode nil) ;; tabs are evil
<...snipped documentation>

I don't know if this has something to do with a limitation or known bug
on csharp-mode or it simply is a personal preference of the author (like
some other he hard-coded into csharp-mode.el), but it would good to
contact him.

OTOH, a quick look at the begining of your message points to a
difference on how we tested the issue: in my case I activated
indent-tabs-mode after activating csharp-mode, while on yours it was the
reverse. Sorry if you tried both ways.



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

* Re: Trying to use only tabs for indenting c# files - csharp-mode error?
  2012-01-08 14:58 ` Óscar Fuentes
@ 2012-01-08 15:49   ` Guido Van Hoecke
  0 siblings, 0 replies; 7+ messages in thread
From: Guido Van Hoecke @ 2012-01-08 15:49 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: help-gnu-emacs

Hi Óscar,

On Sun, Jan 8, 2012 at 15:58, Óscar Fuentes <ofv@wanadoo.es> wrote:
> <snipped documentation...>
>    (setq indent-tabs-mode nil) ;; tabs are evil
> <...snipped documentation>
>
> I don't know if this has something to do with a limitation or known bug
> on csharp-mode or it simply is a personal preference of the author (like
> some other he hard-coded into csharp-mode.el), but it would good to
> contact him.

I normally do not use tabs in my coding. But I am collaborating here in
C# projects where the technical lead dictates tab for indenting (and
sets their width to 4).

> OTOH, a quick look at the begining of your message points to a
> difference on how we tested the issue: in my case I activated
> indent-tabs-mode after activating csharp-mode, while on yours it was the
> reverse. Sorry if you tried both ways.

Well I tried it now and I'm sorry that it does not make any difference.


Guido

--
Piping down the valleys wild,
Piping songs of pleasant glee,
On a cloud I saw a child,
And he laughing said to me:
"Pipe a song about a Lamb!"
So I piped with merry cheer.
"Piper, pipe that song again;"
So I piped: he wept to hear.
		-- William Blake, "Songs of Innocence"

http://vanhoecke.org ... and go2 places!



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

* Trying to use only tabs for indenting c# files - csharp-mode error?
  2012-01-08 13:01 Trying to use only tabs for indenting c# files - csharp-mode error? Guido Van Hoecke
  2012-01-08 14:58 ` Óscar Fuentes
@ 2012-01-08 17:29 ` PJ Weisberg
  2012-01-08 19:06 ` Óscar Fuentes
  2 siblings, 0 replies; 7+ messages in thread
From: PJ Weisberg @ 2012-01-08 17:29 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: Óscar Fuentes, help-gnu-emacs@gnu.org

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

On Sunday, January 8, 2012, Guido Van Hoecke <guivho@gmail.com> wrote:
> I can't help but feeling that this is in error!
>
> The tab-width is 8,
> indent-tabs-mode is t
> and still, it uses spaces to indent, and only two of them.

I know nothing about csharp-mode, but you have a misperception here.  If
Emacs feels that the proper place for that line to start is column 2, and
the tab width is 8, then spaces *must* be used, because no combination of
tabs can get you to column 2.  I know some modes have knobs you can adjust
to get different indentation styles, but I don't know what's available in
csharp-mode.

Given what Oscar pointed out, I wouldn't be surprised if the indentation
function contains some implicit assumption that will result in spaces
always being used, anyway.

-- 

-PJ

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

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

* Re: Trying to use only tabs for indenting c# files - csharp-mode error?
  2012-01-08 13:01 Trying to use only tabs for indenting c# files - csharp-mode error? Guido Van Hoecke
  2012-01-08 14:58 ` Óscar Fuentes
  2012-01-08 17:29 ` PJ Weisberg
@ 2012-01-08 19:06 ` Óscar Fuentes
  2012-01-08 19:19   ` Guido Van Hoecke
  2 siblings, 1 reply; 7+ messages in thread
From: Óscar Fuentes @ 2012-01-08 19:06 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: help-gnu-emacs

Guido Van Hoecke <guivho@gmail.com> writes:

[snip]

> namespace Application
> {
> ==public class MyClass
> =={
> ====public string MyString;
> ====public MyClass ()
> ===={
> ====}
> ==}
> }
>
> So obviously neither tab-width nor indent-tabs-mode are obeyed nor
> respected!

All your examples here makes me think that csharp-mode is indenting by
two spaces per level. As PJ says, tabs will not be used unless the line
is preceded by `tab-width' spaces (8 in your case). If you set tab-width
to 4, I expect to see tabs used for the most deeply indented lines on
the example quoted above.

Put this in your .emacs and see if it makes a difference:

(defun my-csharp-mode-fn ()
  (c-set-style "C#")
  (setq tab-width 4)
  (setq indent-tabs-mode t))

(add-hook 'csharp-mode-hook 'my-csharp-mode-fn)



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

* Re: Trying to use only tabs for indenting c# files - csharp-mode error?
  2012-01-08 19:06 ` Óscar Fuentes
@ 2012-01-08 19:19   ` Guido Van Hoecke
  0 siblings, 0 replies; 7+ messages in thread
From: Guido Van Hoecke @ 2012-01-08 19:19 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: help-gnu-emacs, Dino Chiesa

On Sun, Jan 8, 2012 at 20:06, Óscar Fuentes <ofv@wanadoo.es> wrote:
> Guido Van Hoecke <guivho@gmail.com> writes:
>
> [snip]
>
>> namespace Application
>> {
>> ==public class MyClass
>> =={
>> ====public string MyString;
>> ====public MyClass ()
>> ===={
>> ====}
>> ==}
>> }
>>
>> So obviously neither tab-width nor indent-tabs-mode are obeyed nor
>> respected!
>
> All your examples here makes me think that csharp-mode is indenting by
> two spaces per level. As PJ says, tabs will not be used unless the line
> is preceded by `tab-width' spaces (8 in your case). If you set tab-width
> to 4, I expect to see tabs used for the most deeply indented lines on
> the example quoted above.
>
> Put this in your .emacs and see if it makes a difference:
>
> (defun my-csharp-mode-fn ()
>  (c-set-style "C#")
>  (setq tab-width 4)
>  (setq indent-tabs-mode t))
>
> (add-hook 'csharp-mode-hook 'my-csharp-mode-fn)

It makes no difference.


Guido

--
I prefer the most unjust peace to the most righteous war.
		-- Cicero

Even peace may be purchased at too high a price.
		-- Poor Richard

http://vanhoecke.org ... and go2 places!



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

* Re: Trying to use only tabs for indenting c# files - csharp-mode error?
       [not found] <mailman.1451.1326027725.15002.help-gnu-emacs@gnu.org>
@ 2012-01-14 18:32 ` Uday Reddy
  0 siblings, 0 replies; 7+ messages in thread
From: Uday Reddy @ 2012-01-14 18:32 UTC (permalink / raw)
  To: Guido Van Hoecke; +Cc: help-gnu-emacs

On 1/8/2012 1:01 PM, Guido Van Hoecke wrote:

>
> I can't help but feeling that this is in error!
>
> The tab-width is 8,
> indent-tabs-mode is t
> and still, it uses spaces to indent, and only two of them.

Here is a nice article that clarifies the mystery of tabs.

   http://www.jwz.org/doc/tabs-vs-spaces.html

Cheers,
Uday



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

end of thread, other threads:[~2012-01-14 18:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-08 13:01 Trying to use only tabs for indenting c# files - csharp-mode error? Guido Van Hoecke
2012-01-08 14:58 ` Óscar Fuentes
2012-01-08 15:49   ` Guido Van Hoecke
2012-01-08 17:29 ` PJ Weisberg
2012-01-08 19:06 ` Óscar Fuentes
2012-01-08 19:19   ` Guido Van Hoecke
     [not found] <mailman.1451.1326027725.15002.help-gnu-emacs@gnu.org>
2012-01-14 18:32 ` Uday Reddy

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.