summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-09-20 03:20:27 +0100
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-09-20 03:20:27 +0100
commite6876951b23e7a49192a5c4aa129700c782b59fe (patch)
tree89889c9fd186a339d45cb0fa68e8e2929e0caab6
parent7588f5e93cbb7b629d3fd35b392f14c46065fab2 (diff)
Move popup logic to cider-popup.el
-rw-r--r--cider-doc.el4
-rw-r--r--cider-interaction.el103
-rw-r--r--cider-popup.el119
-rw-r--r--cider-stacktrace.el2
-rw-r--r--cider-test.el2
5 files changed, 129 insertions, 101 deletions
diff --git a/cider-doc.el b/cider-doc.el
index 3a2a53d2..b9723688 100644
--- a/cider-doc.el
+++ b/cider-doc.el
@@ -26,6 +26,7 @@
;;; Code:
(require 'cider-util)
+(require 'cider-popup)
(require 'org-table)
(require 'button)
(require 'dash)
@@ -200,6 +201,9 @@
(cider-grimoire-web-lookup cider-docview-symbol)
(error "%s cannot be looked up on Grimoire" cider-docview-symbol)))
+(defconst cider-doc-buffer "*cider-doc*")
+(add-to-list 'cider-ancillary-buffers cider-doc-buffer)
+
;;; Font Lock and Formatting
diff --git a/cider-interaction.el b/cider-interaction.el
index f8db926b..6308c3e9 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -31,6 +31,7 @@
;;; Code:
(require 'cider-client)
+(require 'cider-popup)
(require 'cider-util)
(require 'cider-stacktrace)
(require 'cider-test)
@@ -49,9 +50,9 @@
(require 'spinner)
(defconst cider-read-eval-buffer "*cider-read-eval*")
-(defconst cider-doc-buffer "*cider-doc*")
(defconst cider-result-buffer "*cider-result*")
(defconst cider-nrepl-session-buffer "*cider-nrepl-session*")
+(add-to-list 'cider-ancillary-buffers cider-nrepl-session-buffer)
(defcustom cider-prefer-local-resources nil
"Prefer local resources to remote (tramp) ones when both are available."
@@ -1596,106 +1597,6 @@ evaluation command. Honor `cider-auto-jump-to-error'."
(cider-current-connection)
(cider-current-session))))
-
-;;;; Popup buffers
-(define-minor-mode cider-popup-buffer-mode
- "Mode for CIDER popup buffers"
- nil
- (" cider-tmp")
- '(("q" . cider-popup-buffer-quit-function)))
-
-(defvar-local cider-popup-buffer-quit-function 'cider-popup-buffer-quit
- "The function that is used to quit a temporary popup buffer.")
-
-(defun cider-popup-buffer-quit-function (&optional kill-buffer-p)
- "Wrapper to invoke the function `cider-popup-buffer-quit-function'.
-KILL-BUFFER-P is passed along."
- (interactive)
- (funcall cider-popup-buffer-quit-function kill-buffer-p))
-
-(defun cider-popup-buffer (name &optional select mode ancillary)
- "Create new popup buffer called NAME.
-If SELECT is non-nil, select the newly created window.
-If major MODE is non-nil, enable it for the popup buffer.
-If ANCILLARY is non-nil, the buffer is added to `cider-ancillary-buffers'
-and automatically removed when killed."
- (-> (cider-make-popup-buffer name mode ancillary)
- (cider-popup-buffer-display select)))
-
-(defun cider-popup-buffer-display (buffer &optional select)
- "Display BUFFER.
-If SELECT is non-nil, select the BUFFER."
- (let ((window (get-buffer-window buffer)))
- (when window
- (with-current-buffer buffer
- (set-window-point window (point))))
- ;; If the buffer we are popping up is already displayed in the selected
- ;; window, the below `inhibit-same-window' logic will cause it to be
- ;; displayed twice - so we early out in this case. Note that we must check
- ;; `selected-window', as async request handlers are executed in the context
- ;; of the current connection buffer (i.e. `current-buffer' is dynamically
- ;; bound to that).
- (unless (eq window (selected-window))
- ;; Non nil `inhibit-same-window' ensures that current window is not covered
- (if select
- (pop-to-buffer buffer `(nil . ((inhibit-same-window . ,pop-up-windows))))
- (display-buffer buffer `(nil . ((inhibit-same-window . ,pop-up-windows)))))))
- buffer)
-
-(defun cider-popup-buffer-quit (&optional kill)
- "Quit the current (temp) window and bury its buffer using `quit-restore-window'.
-If prefix argument KILL is non-nil, kill the buffer instead of burying it."
- (interactive)
- (quit-restore-window (selected-window) (if kill 'kill 'append)))
-
-(defvar-local cider-popup-output-marker nil)
-
-(defvar cider-ancillary-buffers
- (list cider-error-buffer
- cider-doc-buffer
- cider-test-report-buffer
- cider-nrepl-session-buffer
- nrepl-message-buffer-name))
-
-(defun cider-make-popup-buffer (name &optional mode ancillary)
- "Create a temporary buffer called NAME using major MODE (if specified).
-If ANCILLARY is non-nil, the buffer is added to `cider-ancillary-buffers'
-and automatically removed when killed."
- (with-current-buffer (get-buffer-create name)
- (kill-all-local-variables)
- (setq buffer-read-only nil)
- (erase-buffer)
- (when mode
- (funcall mode))
- (cider-popup-buffer-mode 1)
- (setq cider-popup-output-marker (point-marker))
- (setq buffer-read-only t)
- (when ancillary
- (add-to-list 'cider-ancillary-buffers name)
- (add-hook 'kill-buffer-hook
- (lambda () (setq cider-ancillary-buffers (remove name cider-ancillary-buffers)))
- nil 'local))
- (current-buffer)))
-
-(defun cider-emit-into-popup-buffer (buffer value &optional face)
- "Emit into BUFFER the provided VALUE."
- ;; Long string output renders emacs unresponsive and users might intentionally
- ;; kill the frozen popup buffer. Therefore, we don't re-create the buffer and
- ;; silently ignore the output.
- (when (buffer-live-p buffer)
- (with-current-buffer buffer
- (let ((inhibit-read-only t)
- (buffer-undo-list t)
- (moving (= (point) cider-popup-output-marker)))
- (save-excursion
- (goto-char cider-popup-output-marker)
- (let ((value-str (format "%s" value)))
- (when face (add-face-text-property 0 (length value-str) face nil value-str))
- (insert value-str))
- (indent-sexp)
- (set-marker cider-popup-output-marker (point)))
- (when moving (goto-char cider-popup-output-marker))))))
-
(defun cider-emit-into-color-buffer (buffer value)
"Emit into color BUFFER the provided VALUE."
(with-current-buffer buffer
diff --git a/cider-popup.el b/cider-popup.el
new file mode 100644
index 00000000..f097b0e1
--- /dev/null
+++ b/cider-popup.el
@@ -0,0 +1,119 @@
+;;; cider-popup.el --- Creating and quitting popup buffers -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2015 Artur Malabarba
+
+;; Author: Artur Malabarba <bruce.connor.am@gmail.com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'nrepl-client)
+(require 'dash)
+
+(define-minor-mode cider-popup-buffer-mode
+ "Mode for CIDER popup buffers"
+ nil
+ (" cider-tmp")
+ '(("q" . cider-popup-buffer-quit-function)))
+
+(defvar-local cider-popup-buffer-quit-function #'cider-popup-buffer-quit
+ "The function that is used to quit a temporary popup buffer.")
+
+(defun cider-popup-buffer-quit-function (&optional kill-buffer-p)
+ "Wrapper to invoke the function `cider-popup-buffer-quit-function'.
+KILL-BUFFER-P is passed along."
+ (interactive)
+ (funcall cider-popup-buffer-quit-function kill-buffer-p))
+
+(defun cider-popup-buffer (name &optional select mode ancillary)
+ "Create new popup buffer called NAME.
+If SELECT is non-nil, select the newly created window.
+If major MODE is non-nil, enable it for the popup buffer.
+If ANCILLARY is non-nil, the buffer is added to `cider-ancillary-buffers'
+and automatically removed when killed."
+ (-> (cider-make-popup-buffer name mode ancillary)
+ (cider-popup-buffer-display select)))
+
+(defun cider-popup-buffer-display (buffer &optional select)
+ "Display BUFFER.
+If SELECT is non-nil, select the BUFFER."
+ (let ((window (get-buffer-window buffer)))
+ (when window
+ (with-current-buffer buffer
+ (set-window-point window (point))))
+ ;; If the buffer we are popping up is already displayed in the selected
+ ;; window, the below `inhibit-same-window' logic will cause it to be
+ ;; displayed twice - so we early out in this case. Note that we must check
+ ;; `selected-window', as async request handlers are executed in the context
+ ;; of the current connection buffer (i.e. `current-buffer' is dynamically
+ ;; bound to that).
+ (unless (eq window (selected-window))
+ ;; Non nil `inhibit-same-window' ensures that current window is not covered
+ (if select
+ (pop-to-buffer buffer `(nil . ((inhibit-same-window . ,pop-up-windows))))
+ (display-buffer buffer `(nil . ((inhibit-same-window . ,pop-up-windows)))))))
+ buffer)
+
+(defun cider-popup-buffer-quit (&optional kill)
+ "Quit the current (temp) window and bury its buffer using `quit-restore-window'.
+If prefix argument KILL is non-nil, kill the buffer instead of burying it."
+ (interactive)
+ (quit-restore-window (selected-window) (if kill 'kill 'append)))
+
+(defvar-local cider-popup-output-marker nil)
+
+(defvar cider-ancillary-buffers (list nrepl-message-buffer-name))
+
+(defun cider-make-popup-buffer (name &optional mode ancillary)
+ "Create a temporary buffer called NAME using major MODE (if specified).
+If ANCILLARY is non-nil, the buffer is added to `cider-ancillary-buffers'
+and automatically removed when killed."
+ (with-current-buffer (get-buffer-create name)
+ (kill-all-local-variables)
+ (setq buffer-read-only nil)
+ (erase-buffer)
+ (when mode
+ (funcall mode))
+ (cider-popup-buffer-mode 1)
+ (setq cider-popup-output-marker (point-marker))
+ (setq buffer-read-only t)
+ (when ancillary
+ (add-to-list 'cider-ancillary-buffers name)
+ (add-hook 'kill-buffer-hook
+ (lambda () (setq cider-ancillary-buffers (remove name cider-ancillary-buffers)))
+ nil 'local))
+ (current-buffer)))
+
+(defun cider-emit-into-popup-buffer (buffer value &optional face)
+ "Emit into BUFFER the provided VALUE."
+ ;; Long string output renders emacs unresponsive and users might intentionally
+ ;; kill the frozen popup buffer. Therefore, we don't re-create the buffer and
+ ;; silently ignore the output.
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (let ((inhibit-read-only t)
+ (buffer-undo-list t)
+ (moving (= (point) cider-popup-output-marker)))
+ (save-excursion
+ (goto-char cider-popup-output-marker)
+ (let ((value-str (format "%s" value)))
+ (when face (add-face-text-property 0 (length value-str) face nil value-str))
+ (insert value-str))
+ (indent-sexp)
+ (set-marker cider-popup-output-marker (point)))
+ (when moving (goto-char cider-popup-output-marker))))))
+
+(provide 'cider-popup)
+;;; cider-popup.el ends here
diff --git a/cider-stacktrace.el b/cider-stacktrace.el
index 008fb522..82845b3f 100644
--- a/cider-stacktrace.el
+++ b/cider-stacktrace.el
@@ -26,6 +26,7 @@
;;; Code:
(require 'cl-lib)
+(require 'cider-popup)
(require 'button)
(require 'dash)
(require 'easymenu)
@@ -88,6 +89,7 @@ cyclical data structures."
(defvar-local cider-stacktrace-cause-visibility nil)
(defconst cider-error-buffer "*cider-error*")
+(add-to-list 'cider-ancillary-buffers cider-error-buffer)
;; Faces
diff --git a/cider-test.el b/cider-test.el
index 32f95d05..073c0cd2 100644
--- a/cider-test.el
+++ b/cider-test.el
@@ -29,6 +29,7 @@
;;; Code:
(require 'cider-util)
+(require 'cider-popup)
(require 'cider-stacktrace)
(require 'button)
(require 'dash)
@@ -61,6 +62,7 @@
(defconst cider-test-report-buffer "*cider-test-report*"
"Buffer name in which to display test reports.")
+(add-to-list 'cider-ancillary-buffers cider-test-report-buffer)
;;; Faces