From 967dc742f866005da2e61fbd548bfdbf32d788fe Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sun, 10 Dec 2017 20:32:43 +0000 Subject: Only try to kill the buffer we've created If buf (the buffer containing the symbol definition) is nil, we end up killing the current buffer. The current buffer is the buffer that we're trying to write into. Fixes #58 --- helpful.el | 10 ++++++---- test/unit-test.el | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/helpful.el b/helpful.el index 6e1d690..5b551bb 100644 --- a/helpful.el +++ b/helpful.el @@ -429,10 +429,12 @@ for killing the newly created buffer." "Return the path where SYM is defined." (-let* ((initial-buffers (buffer-list)) ((buf . _) (helpful--definition sym callable-p)) - (path (when buf (buffer-file-name buf)))) - ;; If we've just created this buffer, close it. - (unless (-contains-p initial-buffers buf) - (kill-buffer buf)) + (path)) + (when buf + (setq path (buffer-file-name buf)) + ;; If we've just created this buffer, close it. + (unless (-contains-p initial-buffers buf) + (kill-buffer buf))) path)) (defun helpful--source-pos (sym callable-p) diff --git a/test/unit-test.el b/test/unit-test.el index cf50f35..a0641e0 100644 --- a/test/unit-test.el +++ b/test/unit-test.el @@ -40,10 +40,12 @@ "We should not crash on a function without a docstring." (should (null (helpful--docstring #'test-foo-no-docstring t)))) -(ert-deftest helpful--interacively-defined-fn () +(ert-deftest helpful--interactively-defined-fn () "We should not crash on a function without source code." (eval '(defun test-foo-defined-interactively () 42)) - (helpful-function #'test-foo-defined-interactively)) + (with-temp-buffer + (helpful-function #'test-foo-defined-interactively) + (should (equal (buffer-name) "*helpful function: test-foo-defined-interactively*")))) (defun test-foo-usage-docstring () "\n\n(fn &rest ARGS)" -- cgit v1.0