2011-09-26 9 views
5

कभी-कभी एक अलग रेखा पर अनुच्छेद में प्रत्येक वाक्य को शुरू करना वांछनीय होता है। उदाहरण के लिए, इससे बड़े टेक्स्ट दस्तावेज़ों को अलग करना आसान हो जाता है, क्योंकि एक वाक्य में परिवर्तन पूरे पैराग्राफ को प्रभावित नहीं करेगा। कुछ मार्कअप सिस्टम (उदा। * रफ) को प्रत्येक वाक्य को एक नई लाइन पर शुरू करने की भी आवश्यकता होती है।क्या वाक्य के अंत में 'भरने-पैराग्राफ' स्टॉप बनाने का कोई तरीका है?

वहाँ एक रास्ता है, उदाहरण के लिए paragraph-separate और paragraph-start का विवेकपूर्ण परिभाषा द्वारा, वाक्य के बीच fill-paragraph स्टॉप बनाने के लिए?

(ध्यान दें: मैं Emacs 23.3.1 का उपयोग)


अद्यतन: नमूना mdoc (* roff) मार्कअप:

The 
.Nm 
utility makes a series of passes with increasing block sizes. 
In each pass, it either reads or writes (or both) a number of 
non-consecutive blocks at increasing offsets relative to the ideal 
alignment, which is assumed to be multiples of the block size. 
The results are presented in terms of time elapsed, transactions per 
second and kB per second. 

इस तीन वाक्य के साथ एक ही पैरा है, जिनमें से प्रत्येक पिछली पंक्ति पर पहले शब्द (ओं) के लिए जगह है, भले ही एक अलग लाइन पर शुरू होता है। वर्तमान में, fill-paragraph इसे

The 
.Nm 
utility makes a series of passes with increasing block sizes. In each 
pass, it either reads or writes (or both) a number of non-consecutive 
blocks at increasing offsets relative to the ideal alignment, which is 
assumed to be multiples of the block size. The results are presented 
in terms of time elapsed, transactions per second and kB per second. 

जो मैं बचाना चाहता हूं उसे बदल दूंगा।


अपडेट: फिर से वाक्य और पैराग्राफ

मैं, देखते हैं कि मेरे सवाल का एक सा स्पष्ट नहीं है, क्योंकि मैं शब्द "पैरा" का इस्तेमाल किया क्या समाप्त होता है क्या Emacs एक पैराग्राफ कॉल करने के लिए और करने के लिए दोनों का उल्लेख करने में जो भी प्रोसेसर मैं उपयोग करता हूं (ग्रॉफ, लेटेक्स इत्यादि) के आउटपुट में पाठ के निरंतर ब्लॉक के रूप में। स्पष्टीकरण के लिए,

  • मुझे वाक्यों को उनके बीच किसी रिक्त रेखा के बिना रखने की आवश्यकता है; ग्रॉफ को रिक्त रेखाएं पसंद नहीं हैं, जबकि लेटेक्स उन्हें अनुच्छेद विभाजक के रूप में देखता है।
  • मैं fill-paragraph की जरूरत अलग-अलग वाक्य पर संचालित करने के लिए, यानी मैं कुछ है कि या तो एक रिक्त पंक्ति या पिछले पैराग्राफ के अंत के बाद शुरू होता है के रूप में एक पैराग्राफ को फिर से परिभाषित करने के लिए चाहते हैं, और एक अवधि के लिए या तो एक नई पंक्ति चरित्र से या कम से कम का पालन के साथ समाप्त होता दो सफेद जगह अक्षर।
  • मैं fill-paragraph है करने के लिए प्यार होता है व्यक्ति वाक्य में अलग पाठ का कोई खंड को तोड़ने, लेकिन मुझे नहीं लगता कि यह आसानी से किया जा सकता है।
उदाहरण के लिए

, अगर मैं निम्न लिखें:

:

The 
.Nm 
utility makes a series of passes with increasing block sizes. 
In each pass, it either reads or writes (or both) a number of non-consecutive blocks at increasing offsets relative to the ideal alignment, which is assumed to be multiples of the block size. 
The results are presented in terms of time elapsed, transactions per second and kB per second. 

तो लाइन है कि "प्रत्येक पास में" के साथ शुरू होता करने के लिए बिंदु को स्थानांतरित और M-q दबाते हैं, तो मैं निम्नलिखित मिलना चाहिए

The 
.Nm 
utility makes a series of passes with increasing block sizes. 
In each pass, it either reads or writes (or both) a number of 
non-consecutive blocks at increasing offsets relative to the ideal 
alignment, which is assumed to be multiples of the block size. 
The results are presented in terms of time elapsed, transactions per second and kB per second. 

ध्यान दें कि अंतिम वाक्य अछूता है।

उत्तर

1

paragraph-start कह किसी भी लाइन है कि बड़े अक्षर से शुरू होता है देखने के लिए के बारे में कैसे:

"\f\\|[  ]*$\\|^[A-Z]" 

ध्यान दें कि नया हिस्सा है \\^[A-Z]

कि ज्यादातर मामलों के लिए काम करना चाहिए, आप केवल होगा उन दुर्लभ मामलों को देखने के लिए जहां आपके पास पूंजी मध्य-वाक्य है, और यह वाक्य उस मध्य-वाक्य के शब्द से पहले तोड़ने के लिए काफी लंबा होता है।

संपादित करें: आप शायद खरोज के लिए भी खाते हैं:

"\f\\|[  ]*$\\|^[ ]*[A-Z]" 

वर्ग कोष्ठक के बीच की जगह एक जगह और एक टैब में शामिल है।

संपादित करें: आपको काम करने के लिए case-fold-search बंद करने की आवश्यकता है, अन्यथा राजधानियां और निचले केस अक्षरों को मैच में अलग नहीं किया जाता है!

संपादित करें: यदि आप केवल इस फ़ंक्शन के लिए केस-फ़ोल्ड-सर्च बंद करना चाहते हैं, तो M-q (जिसे आप स्थानीय रूप से या वैश्विक रूप से कर सकते हैं, जैसा कि आप फिट देखते हैं) को बाध्य करें।

(defun my-fill-paragraph() 
    (interactive) 
    (let ((case-fold-search nil)) 
    (fill-paragraph))) 
+0

हम्म, यदि Emacs का regexp वाक्यविन्यास शून्य-चौड़ाई चर-लंबाई के पीछे-पीछे के दावों का समर्थन करता है, तो यह एक regexp बनाना संभव होना चाहिए जो पर्ल पुनः '/\.(?:\n|\s{2 के अनुरूप है, }) \ के \ एस/एस', जो एक अवधि के बाद पहले गैर-व्हाइटस्पेस चरित्र से मेल खाता है, उसके बाद एक न्यूलाइन चरित्र या कम से कम दो व्हाइटस्पेस वर्ण होते हैं। – DES

+0

आपने मुझे खो दिया है। मेरे द्वारा पोस्ट किया गया regexp कब विफल रहता है? मुझे लगता है कि आप प्रत्येक वाक्य के बाद मैन्युअल रूप से वापसी करते हैं, ताकि आप उन्हें दर्ज कर सकें, ताकि Emacs को आपके लिए अनुच्छेदों को विभाजित करने की आवश्यकता न हो, इसे भरने पर केवल वाक्य सीमाओं का सम्मान करने की आवश्यकता है। – Tyler

+0

मुझे नहीं लगता कि Emacs assertions का समर्थन करता है, या तो। – Tyler

1

क्या यह डीटीआरटी है?

(defun separate-sentences (&optional beg end) 
    "ensure each sentence ends with a new line. 
When no region specified, use current paragraph." 
    (interactive (when (use-region-p) 
        (list (region-beginning) (region-end)))) 
    (unless (and beg end) 
    (save-excursion 
     (forward-paragraph -1) 
     (setq beg (point)) 
     (forward-paragraph 1) 
     (setq end (point)))) 
    (setq end (if (markerp end) 
       end 
       (set-marker (make-marker) end))) 
    (save-excursion 
    (goto-char beg) 
    (while (re-search-forward (sentence-end) end t) 
     (unless (or (looking-at-p "[ \t]*$") 
        (looking-back "^[ \t]*")) 
     (insert "\n"))))) 

(defun fill-paragraph-sentence-groups (justify) 
    "Groups of sentences filled together. A sentence ending with newline marks end of group." 
    (save-excursion 
    (save-restriction 
     (narrow-to-region (progn (forward-paragraph -1) (point)) 
         (progn (forward-paragraph 1) (point))) 
     (goto-char (point-min)) 
     (skip-chars-forward " \t\n") 
     (while (not (or (looking-at-p paragraph-separate) 
         (eobp))) 
     (fill-region (point) 
        (progn 
         (loop do (forward-sentence 1) 
          until (looking-at "[ \t]*$")) 
         (point)) 
        justify) 
     (unless (looking-back "^[ \t]*") 
      (forward-line 1))) 
     t))) 

(defun fill-paragraph-sentence-individual (justify) 
    "Each sentence in paragraph is put on new line." 
    (save-excursion 
    (separate-sentences) 
    (fill-paragraph-sentence-groups justify))) 

;; deployment option 1: add to major-mode hook 

(add-hook 'text-mode-hook (lambda() 
          (set (make-local-variable fill-paragraph-function) 'fill-paragraph-sentence-individual))) 

;; deployment option 2: call my-fill-paragraph any where 

(defun my-fill-paragraph (arg) 
    (interactive "*P") 
    (let ((fill-paragraph-function 'fill-paragraph-sentence-individual)) 
    (fill-paragraph arg))) 

दो अनुच्छेद भरने के कार्य ऊपर प्रस्तुत किए गए हैं। एक समूह वाक्य जो एक साथ नई लाइन पर समाप्त नहीं होता है। एक और हर वाक्य को एक नई पंक्ति में तोड़ना।

मैं केवल दिखाता हूं कि व्यक्ति को कैसे तैनात किया जाए क्योंकि ओपी चाहता है। यदि आप चाहें तो समूह संस्करण को तैनात करने के लिए मॉडल का पालन करें।

+0

सवाल यह नहीं था कि पैराग्राफ को वाक्य में कैसे अलग किया जाए, लेकिन 'fill-paragraph' को फिर से जोड़ने से कैसे रोकें। – DES

+0

सवाल बहुत स्पष्ट नहीं है। क्या आप जो कुछ चाहते हैं उसके कुछ उदाहरण जोड़ सकते हैं? क्या आप वर्तमान अनुच्छेद आंदोलन व्यवहार भी रखना चाहते हैं? –

+0

नमूना मार्कअप जोड़ा गया। – DES

0

आप fill-region का उपयोग कर सकते हैं, जो आश्चर्यजनक रूप से, केवल वर्तमान क्षेत्र को भरता है। उस पर आधारित आप fill-sentence फ़ंक्शन को परिभाषित कर सकते हैं। मुझे लगता है कि इस तरह के वाक्य पता लगाने के लिए एक साधारण तरीका कहना है: लाइन एक ., ?, या ! साथ समाप्त होता है

  • , यह एक अंत के वाक्य लाइन है।

  • एक पंक्ति एक वाक्य शुरू होती है यदि उसकी पूर्ववर्ती रेखा या तो खाली या अंत वाक्य है।

हालांकि सभी मामलों में इसे सही तरीके से काम करने के लिए यह मुश्किल है।

+0

मैं उन पैरामीटरों के संयोजन की उम्मीद कर रहा था जो 'भरने-अनुच्छेद' डीटीआरटी बनाएंगे। – DES

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