Is there any global variable in Ruby for specifying how tabs ("\t")
should
be translated into spaces?
On Apr 27, 2012, at 11:51 , Intransition wrote:
Is there any global variable in Ruby for specifying how tabs ("\t") should be
translated into spaces?
Huh?
Where would this global be used, exactly?
On Sat, Apr 28, 2012 at 05:22:47AM +0900, Ryan D. wrote:
On Apr 27, 2012, at 11:51 , Intransition wrote:
Is there any global variable in Ruby for specifying how tabs ("\t") should be
translated into spaces?Huh?
Where would this global be used, exactly?
I think the variable is
$NUMBER_OF_SPACES_PER_TAB_FOR_TRANSLATION_SUBSTITUTIONS.
Here is the usage:
$NUMBER_OF_SPACES_PER_TAB_FOR_TRANSLATION_SUBSTITUTIONS = 4
string.gsub(/\t/, ’ ’ *
$NUMBER_OF_SPACES_PER_TAB_FOR_TRANSLATION_SUBSTITUTIONS)
Hope that helps!
On Apr 27, 2012 3:29 PM, “Aaron P.” [email protected]
wrote:
On Sat, Apr 28, 2012 at 05:22:47AM +0900, Ryan D. wrote:
On Apr 27, 2012, at 11:51 , Intransition wrote:
Is there any global variable in Ruby for specifying how tabs (“\t”)
should be translated into spaces?Huh?
Where would this global be used, exactly?
I think the variable is
$NUMBER_OF_SPACES_PER_TAB_FOR_TRANSLATION_SUBSTITUTIONS.Here is the usage:
$NUMBER_OF_SPACES_PER_TAB_FOR_TRANSLATION_SUBSTITUTIONS = 4
string.gsub(/\t/, ’ ’ *
$NUMBER_OF_SPACES_PER_TAB_FOR_TRANSLATION_SUBSTITUTIONS)Hope that helps!
–
Aaron P.
http://tenderlovemaking.com/
LOL.
Intransition: the amount of space shown by a tab is totally dependent on
the terminal used to display the text, and (unlike some terminal
parameters) there is no way for Ruby or any language to change it. I
guess
the best thing you could do would be to implement a writer stream that
converted tabs to spaces.
On Friday, April 27, 2012 5:01:37 PM UTC-4, Eric C. wrote:
Intransition: the amount of space shown by a tab is totally dependent on
the terminal used to display the text, and (unlike some terminal
parameters) there is no way for Ruby or any language to change it. I guess
the best thing you could do would be to implement a writer stream that
converted tabs to spaces.
I guess I worded that poorly. I was just wondering if there is some
setting
to be read --not change. I’m not even sure … is there such a setting
in
shell/bash?
My use case is string unindention. Say I have a string with each line is
prefixed with two “\t” characters and I want to unindent it by upto 2
spaces. Then I need to translate the tabs to spaces. The unindent method
can have an option for it, but I was wondering if there is some system
setting I can look at for deciding a default.
Thomas S. wrote in post #1058752:
My use case is string unindention. Say I have a string with each line is
prefixed with two “\t” characters and I want to unindent it by upto 2
spaces. Then I need to translate the tabs to spaces. The unindent method
can have an option for it, but I was wondering if there is some system
setting I can look at for deciding a default.
I’m afraid not, it’s entirely application-specific. For example, I
believe vim and emacs let you embed a magic comment in the text file
which says how many spaces to display a tab as.
For the shell utility, look at the expand(1) manpage. On OSX this says:
-t tab1,tab2,...,tabn
Set tab stops at column positions tab1, tab2, ..., tabn.
If only
a single number is given, tab stops are set that number of
column
positions apart instead of the default number of 8.
So in the absence of any better info, I’d go with 8.
Am 28.04.2012 05:37, schrieb Intransition:
> >
I guess I worded that poorly. I was just wondering if there is some
setting to be read --not change. I’m not even sure … is there such a
setting in shell/bash?My use case is string unindention. Say I have a string with each line is
prefixed with two “\t” characters and I want to unindent it by upto 2
spaces. Then I need to translate the tabs to spaces. The unindent method
can have an option for it, but I was wondering if there is some system
setting I can look at for deciding a default.
Sure you’re not writing a Python parser, eh?
– Matthias
On Sunday, April 29, 2012 5:48:14 AM UTC-4, Brian C. wrote:
If only
a single number is given, tab stops are set that number of
column
positions apart instead of the default number of 8.So in the absence of any better info, I’d go with 8.
Ok, thanks. I might go with 2 b/c it’s Ruby indention tradition. OTOH,
maybe unindent method should ignore tabs altogether.