From ce28a67e28591987e9ca0a13ada4710e8950ffb4 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 14 May 2014 05:05:49 +0900 Subject: [PATCH] checking if the buffer exists (#256). --- elisp/ghc-check.el | 8 ++++---- elisp/ghc-func.el | 8 ++++++++ elisp/ghc-process.el | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/elisp/ghc-check.el b/elisp/ghc-check.el index aa5170b..975be72 100644 --- a/elisp/ghc-check.el +++ b/elisp/ghc-check.el @@ -80,9 +80,9 @@ nil does not display errors/warnings. (buf ghc-process-original-buffer)) (ghc-check-highlight-original-buffer file buf infos))) (t - (with-current-buffer ghc-process-original-buffer + (ghc-with-current-buffer ghc-process-original-buffer (remove-overlays (point-min) (point-max) 'ghc-check t)))) - (with-current-buffer ghc-process-original-buffer + (ghc-with-current-buffer ghc-process-original-buffer (let ((len (length infos))) (if (= len 0) (setq mode-line-process "") @@ -91,7 +91,7 @@ nil does not display errors/warnings. (wlen (- len elen))) (setq mode-line-process (format " %d:%d" elen wlen)))))))) (t - (with-current-buffer ghc-process-original-buffer + (ghc-with-current-buffer ghc-process-original-buffer (setq mode-line-process " failed"))))) (defun ghc-to-info (errs) @@ -114,7 +114,7 @@ nil does not display errors/warnings. (ghc-add infos info))))))) (defun ghc-check-highlight-original-buffer (ofile buf infos) - (with-current-buffer buf + (ghc-with-current-buffer buf (remove-overlays (point-min) (point-max) 'ghc-check t) (save-excursion (goto-char (point-min)) diff --git a/elisp/ghc-func.el b/elisp/ghc-func.el index 7884783..9fe7d69 100644 --- a/elisp/ghc-func.el +++ b/elisp/ghc-func.el @@ -205,4 +205,12 @@ expr (concat "(" expr ")")))) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defmacro ghc-with-current-buffer (buf &rest body) + ;; (declare (indent 1)) + `(if (get-buffer ,buf) + (with-current-buffer ,buf + ,@body))) + (provide 'ghc-func) diff --git a/elisp/ghc-process.el b/elisp/ghc-process.el index a686eb4..2d2dffc 100644 --- a/elisp/ghc-process.el +++ b/elisp/ghc-process.el @@ -36,7 +36,7 @@ (buf (get-buffer-create (concat " ghc-modi:" name))) (file (buffer-file-name)) (cpro (get-process name))) - (with-current-buffer buf + (ghc-with-current-buffer buf (unless ghc-process-running (setq ghc-process-running t) (setq ghc-process-original-buffer cbuf) @@ -69,7 +69,7 @@ pro)) (defun ghc-process-filter (process string) - (with-current-buffer (process-buffer process) + (ghc-with-current-buffer (process-buffer process) (goto-char (point-max)) (insert string) (forward-line -1) @@ -110,7 +110,7 @@ ;; (discard-input) avoids getting stuck. (discard-input)) (quit - (with-current-buffer (process-buffer pro) + (ghc-with-current-buffer (process-buffer pro) (setq ghc-process-running nil))))) ghc-process-results)