2012-11-15 16 views
6

मैं perltidy कैसे कॉन्फ़िगर लंबे फ़ॉर्मेट करने के लिए कर सकते हैं अगर इस तरह के बयानों:perltidy स्वरूपण जटिल अगर

if (
    ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or 
    ('hello world' =~ /world/ and 6 = 3 * 2 * 1) 
) { 
    print "hello\n"; 
} 

या इस

if (
    ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) 
    or ('hello world' =~ /world/ and 6 == 3 * 2 * 1) 
) { 
    print "hello\n"; 
} 

Edit1 की तरह: perltidyrc

--maximum-line-length=100 
--indent-columns=4 
--default-tabsize=4 
--continuation-indentation=4 
--closing-token-indentation=0 

--no-indent-closing-brace 

--paren-tightness=2 
--square-bracket-tightness=2 
--block-brace-tightness=0 

--trim-qw 

--nospace-terminal-semicolon 
--nospace-for-semicolon 

--indent-spaced-block-comments 
--ignore-side-comment-lengths 

--cuddled-else 

--no-opening-brace-on-new-line 
--no-opening-sub-brace-on-new-line 
--no-opening-anonymous-sub-brace-on-new-line 
--no-brace-left-and-indent 

--blanks-before-comments 
--blank-lines-before-subs=1 
--blanks-before-blocks 
--maximum-consecutive-blank-lines=1 

संपादित 2: विचार ( के बाद एक नई पंक्ति है और { के साथ एक नई लाइन पर होने के लिए अंतिम ) भी है। यदि यह संभव नहीं है, तो बेहतर स्वरूपण के लिए किसी भी अन्य सुझाव की सराहना की जाएगी।

उत्तर

4

perltidy की डिफ़ॉल्ट शैली Perl Style Guide जहां संभव हो, का पालन करना है। इस उत्पादन में कौन सा परिणाम:

if ( ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) 
    or ('hello world' =~ /world/ and 6 == 3 * 2 * 1)) 
{ 
    print "hello\n"; 
} 

आप चाहे वे एक नई लाइन या नहीं पर हैं घुंघराले ब्रेसिज़ नियंत्रित कर सकते हैं। आप कोष्ठक की मजबूती को नियंत्रित कर सकते हैं। हालांकि, कोड कोड में ब्रांड्स के लिए नई लाइनों को नियंत्रित नहीं कर सकते हैं।

डिफ़ॉल्ट शैली उतनी ही करीब है जितनी आप अपने वांछित आउटपुट पर जा रहे हैं।

+0

अगर कथन मल्टीलाइन है तो बाहरी ब्रैकेट के पहले/बाद में रिक्त स्थान जोड़ने का कोई तरीका है? (पी। मैंने अपने perltidyrc को जोड़ा है जिसमें मैं उन्हें हटा देता हूं) – bliof

+0

@bliof, नहीं, स्टाइल ब्लॉक के विकल्प काफी सीमित हैं। – titanofold

2

यदि यह अप्रिय लंबा है, एक विचार -l=n, जहां n प्रत्येक पंक्ति की अधिकतम लंबाई है साथ प्रत्येक पंक्ति की अधिकतम लंबाई सीमित करने के लिए हो सकता है:

$ cat perltidy_test.pl 
if (
    ('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or('hello world' =~ /world/ and 6 = 3 * 2 * 1) 
) { 
    print "hello\n"; 
} 

$ perltidy -l=60 perltidy_test.pl 
$ cat pertidy_test.pl.tdy 
if (
    (
     'this is an example' =~ /an.*example/ 
     and 1 * 2 * 3 == 6 
    ) 
    or ('hello world' =~ /world/ and 6 == 3 * 2 * 1) 
) 
{ 
    print "hello\n"; 
} 
0

कोशिश

$ perltidy - BLI -wba = 'या'

कि इस उदाहरण के लिए काम करता है perltidy_test.pl ...

+0

मुझे इतना यकीन नहीं है। 'ब्लि' घुंघराले ब्रैकेट को इंडेंट करता है और 'wba'' या 'के बाद नई लाइन जोड़ता है। मैं समस्या को निर्दिष्ट करने के लिए प्रश्न संपादित करूँगा .. – bliof

+0

** $ perltidy -anl -bbb tidy_test.pl ** :) '-anl' नई लाइनें जोड़ें ' -bbb' प्रमुख ब्लॉक के बीच खाली रेखा जोड़ें –

संबंधित मुद्दे