プロジェクト

全般

プロフィール

Vote #63661

未完了

Tab Width

Admin Redmine さんがほぼ4年前に追加. ほぼ4年前に更新.

ステータス:
Reopend
優先度:
低め
担当者:
-
カテゴリ:
SCM_3
対象バージョン:
-
開始日:
2008/07/28
期日:
進捗率:

0%

予定工数:
category_id:
3
version_id:
0
issue_org_id:
1689
author_id:
758
assigned_to_id:
0
comments:
17
status_id:
8
tracker_id:
2
plus1:
1
affected_version:
closed_on:
affected_version_id:
ステータス-->[Reopend]

説明

There should be a setting (somewhere) to allow the site administrator, or even better, individual project owners, to change the tab width as displayed in the repository source browser. Right now it's set at something crazy like 6 or 8 characters, some prefer it at 2, others at 4, still others at 5. The ability to change the tab width would let people control the code display. If this could be snuck into 0.8 that'd be awesome. If not, oh well, there's always hope for 0.9!


journals

For those of us using vim modelines it would be great if they were parsed, allowing a per-file display configuration. Looking for __tabstop=*X*__ in the first few lines of the file doesn't seem too hard.

--------------------------------------------------------------------------------
Grzegorz Adam Hankiewicz wrote:
> For those of us using vim modelines it would be great if they were parsed, allowing a per-file display configuration. Looking for __tabstop=*X*__ in the first few lines of the file doesn't seem too hard.

Get yer own feature request! @;-)@ Yeah, that's cool, but I think that'd be a completely different feature request. I'm just asking for a little drop-down combo box in the project settings page to set a tab width. You want a feature that looks for Vim stuff, which is a bit different than my request.
--------------------------------------------------------------------------------
The target version field has to be set when it will *actually* part of the target release.
--------------------------------------------------------------------------------
Well, 0.8 came and went, can we please try for 0.9?

I use a tabstop of 4 in all my projects, so at very least tell me where the tabstop is defined so I can make a temporary fix by manually changing it for my installation!
--------------------------------------------------------------------------------
Hey, you see? I can play with statuses too... <pre>-_-</pre>
--------------------------------------------------------------------------------
Thomas Lecavelier wrote:
> Hey, you see? I can play with statuses too... [...]

That's not nice...
--------------------------------------------------------------------------------
+1 for setting tab-width.
I think this feature is not implemented yet.

Dear Chris Miller. hope you to check [[SubmittingBugs#Submitting-Feature-Request]]
Dear Thomas Lecavelier. if it is not invalid request, how about to reopen?
--------------------------------------------------------------------------------
No, it is not done, so it should be either "open" or "wontfix".

I did some research into it, and I believe that browsers hardcode a tab character in a @pre@ block to eight characters and it cannot be changed by any CSS or HTML attribute (I tried).

I believe the easiest way would be to replace every tab character with _n_ spaces in the method on line 25 in source:tags/0.8.0/app/helpers/repositories_helper.rb however, I am unsure how to do this, and I'm also very unsure how to:

# add a new field to the project model (an integer storing the desired tab width)
# add stuff in the view to display the new setting so it can be changed by project managers
# modify the method previously indicated to replace tabs with characters for display

I'm not a Ruby programmer, and I've attempted to learn Rails before only to come out of it massively confused, so I feel really helpless just standing here pointing and yelling "make magic things happen here!" If I did know how... I would give you a patch and not a feature request.
--------------------------------------------------------------------------------
Just an update...

I have found that by modifying the following lines of code:

source:tags/0.8.7/app/helpers/application_helper.rb#L192

<pre><code class="ruby">
def syntax_highlight(name, content)
type = CodeRay::FileType[name]
type ? CodeRay.scan(content, type).html(:tab_width => 4) : h(content.gsub("\t"," "*4))
end
</code></pre>

And

source:tags/0.8.7/lib/redmine/wiki_formatting/textile/formatter.rb#L58

<pre><code class="ruby">
CodeRay.scan($2, $1.downcase).html(:escape => false, :line_numbers => :inline, :tab_width => 4)
</code></pre>

I was able to hard-code my site to have a tab width of four characters. Mind you, this isn't a tab-stop - a lot of the time things don't quite line up, but at least they're only off by at most three characters! It's a far sight better than before!

If someone with more Ruby-fu could extract that to a kind of configurable variable we might have a worthwhile patch on our hands.
--------------------------------------------------------------------------------
I have found an even better way of converting tabs to spaces. This respects tab _stops_, which is the concept that a tab character doesn't necessarily expand to 4 (or 3, or 2, or 6, or whatever) spaces, but advances the line to a predetermined tab stop. Tabstops are generally at 4, 8, 12, 16, 20, etc.

Enough preaching about the Holy Tabstop. Here's how to make it work:

This uses the GNU CoreUtils @expand@ command. This works on files, so I just use Ruby's @Tempfile@ to create a temporary file, then delete it when we're done. You do need to add this line of code to the beginning of the file, however:

<pre><code class="ruby">
require 'tempfile'
</code></pre>

Now, add the instructions to your syntax highlighter to make it expand tabs to spaces:

<pre><code class="ruby">
def syntax_highlight(name, content)
type = CodeRay::FileType[name]
t = Tempfile.new("expandfile")
t.syswrite(content)
content = `expand -t 4 #{t.path}`
t.close
t.delete
type ? CodeRay.scan(content, type).html : h(content)
end
</code></pre>

Same thing applies to Wiki formatting. (don't forget to include the @require@ statement there, either!)

This also works quite well with the Ultraviolet plugin.
--------------------------------------------------------------------------------
Now, even more cool!

Add the following to @lib/redmine/core_ext/string/conversions.rb@

<pre><code class="ruby">
# Expand tabs to spaces
def expand(tab_width=4)
text = self.dup
out = ''
text.each_line do |line|
column = 0
line.each_char do |c|
if c == "\t"
next_tab_column = column + (tab_width - column % tab_width)
while column < next_tab_column
out << " "
column += 1
end
elsif c == "\b"
column += -1
else
column += 1
out << c
end
end
end
out
end
</code></pre>

Now, instead of all that tempfile nonsense, you can simply use @content.expand@ in @app/helpers/application_helper.rb@ (or @content.expand(4)@, or however many spaces you want your tabs to expand to).
--------------------------------------------------------------------------------
I'd say you just abandon tabs :)

But maybe a per-language setting would be okay. Ruby style is 2 spaces, C is 8, Python is 4, for example. Better than the current 8-for-all setting.
--------------------------------------------------------------------------------
Kornelius Kalnbach wrote:
> I'd say you just abandon tabs :)

Over my dead body.

> But maybe a per-language setting would be okay. Ruby style is 2 spaces, C is 8, Python is 4, for example. Better than the current 8-for-all setting.

I don't know what planet you live on, but I have yet to actually meet a living C programmer who uses a tab-width of 8. All the programmers I know use a tab width of 4, though I find that a tab stop of 2 for C is actually quite nice and compact while using smaller laptop screens.

Having a per-project per-language setting seems important to me. But this is a system that would require additional database tables and rot like that, so even if I do decide to take up a patch, it'll certainly be one of those things that would only ever be a candidate for a 0.x release, and never a 0.9.x release. I absolutely believe that it should be part of the Redmine system by default, as source code with badly aligned tabs can decrease readability quite dramatically.

--------------------------------------------------------------------------------
It this is such a hot topic, I'm happy to stay out of the discussion. CodeRay provides the option, so it's Redmine's decision how to implement it.

@Chris: Earth.
--------------------------------------------------------------------------------
There is a chance that this will be solved? I'd like to have the possibility to set tab at 4 without hacking the code.
--------------------------------------------------------------------------------
+Vote for this! I'm using tab size 2
--------------------------------------------------------------------------------
I've changed tab width at source code view. But, at diff view mode, it still shows me the tab width of 8. How can I change the tab width to 4 at diff view.
--------------------------------------------------------------------------------


related_issues

duplicates,Closed,3065,"Tab Size" setting
duplicates,Closed,4217,Allow Changing Tab-Length for Code View

Admin Redmine さんがほぼ4年前に更新

  • カテゴリSCM_3 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0