2012-06-15 17 views
12

जब कोई त्रुटि नहीं है और कोई चेतावनी नहीं है, तो मैं संकलन बफर को बंद करना चाहता हूं, लेकिन चेतावनी होने पर मैं इसे दिखाना चाहता हूं। कोई मुझे मदद कर सकता है? emacswiki से यह कोड केवल पहली आवश्यकता है। इसे कैसे बदलें?emacs संकलित बफर ऑटो बंद?

;; Helper for compilation. Close the compilation window if 
    ;; there was no error at all. 
    (defun compilation-exit-autoclose (status code msg) 
    ;; If M-x compile exists with a 0 
    (when (and (eq status 'exit) (zerop code)) 
     ;; then bury the *compilation* buffer, so that C-x b doesn't go there 
     (bury-buffer) 
     ;; and delete the *compilation* window 
     (delete-window (get-buffer-window (get-buffer "*compilation*")))) 
    ;; Always return the anticipated result of compilation-exit-message-function 
    (cons msg code)) 
    ;; Specify my function (maybe I should have done a lambda function) 
    (setq compilation-exit-message-function 'compilation-exit-autoclose) 
+0

आप क्या संकलित कर रहे हैं? – Thomas

+0

@ थॉमस यह महत्वपूर्ण समस्या नहीं है – Iceman

+1

यह जानना उपयोगी हो सकता है कि आप कौन से कंपाइलर चल रहे हैं क्योंकि आप त्रुटियों या चेतावनियों की जांच करने के लिए 'msg' पैरामीटर का उपयोग करने में सक्षम हो सकते हैं। – Thomas

उत्तर

15

मैं संकलन के लिए निम्नलिखित का उपयोग करता हूं। चेतावनियां या त्रुटियां होने पर यह संकलन बफर रखता है, और इसे अन्यथा (1 सेकंड के बाद) देता है।

(defun bury-compile-buffer-if-successful (buffer string) 
"Bury a compilation buffer if succeeded without warnings " 
(when (and 
     (buffer-live-p buffer) 
     (string-match "compilation" (buffer-name buffer)) 
     (string-match "finished" string) 
     (not 
      (with-current-buffer buffer 
      (goto-char (point-min)) 
      (search-forward "warning" nil t)))) 
    (run-with-timer 1 nil 
        (lambda (buf) 
         (bury-buffer buf) 
         (switch-to-prev-buffer (get-buffer-window buf) 'kill)) 
        buffer))) 
(add-hook 'compilation-finish-functions 'bury-compile-buffer-if-successful) 
+0

अच्छा, यह काम करता है, शायद मैं टाइमर को हटा दूंगा। – Iceman

+0

यह अच्छा है, लेकिन संकलन बफर बंद होने के बाद यह विंडो को क्यों खुलता है? जब तक मैं कर्सर को स्थानांतरित नहीं करता तब तक यह विंडो तब तक खुला रहता है, फिर यह अचानक बंद हो जाता है। इस व्यवहार का कारण क्या है? – johnbakers

+0

@ जोहानबकर्स: क्योंकि यह सब खिड़की में बफर को स्विच करता है, जिससे विंडो लेआउट अपरिवर्तित हो जाता है। मैं आम तौर पर अपने खिड़की के लेआउट को बदलने के लिए Emacs पसंद नहीं है। 'स्विच-टू-प्री-बफर' के बजाय 'हटाएं-विंडोज-ऑन' के साथ खेलने का प्रयास करें। – jpkotta

2

jpkotta, यह ज्यादातर बार काम करता है। कभी-कभी, यहां तक ​​कि अगर कोई चेतावनी है, तो यह संकलन बफर पर स्विच नहीं करता है। इसलिए मैंने आपके फॉर्म में बदलाव किया & यह अब काम करता है:

(defun bury-compile-buffer-if-successful (buffer string) 
    "Bury a compilation buffer if succeeded without warnings " 
    (if (and 
     (string-match "compilation" (buffer-name buffer)) 
     (string-match "finished" string) 
     (not 
     (with-current-buffer buffer 
      **(goto-char 1)** 
      (search-forward "warning" nil t)))) 
     (run-with-timer 1 nil 
         (lambda (buf) 
         (bury-buffer buf) 
         (switch-to-prev-buffer (get-buffer-window buf) 'kill)) 
         buffer))) 
(add-hook 'compilation-finish-functions 'bury-compile-buffer-if-successful) 
+0

धन्यवाद, मैंने अपना जवाब अपडेट कर लिया है। – jpkotta

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