PageRenderTime 27ms CodeModel.GetById 22ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/misc/fuel/fuel-popup.el

http://github.com/abeaumont/factor
Emacs Lisp | 69 lines | 43 code | 15 blank | 11 comment | 1 complexity | 084587bba6253cb3354af863de4d9baf MD5 | raw file
 1;;; fuel-popup.el -- popup windows
 2
 3;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
 4;; See http://factorcode.org/license.txt for BSD license.
 5
 6;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
 7;; Keywords: languages, fuel, factor
 8;; Start date: Sun Dec 21, 2008 14:37
 9
10;;; Comentary:
11
12;; A minor mode to pop up windows and restore configurations
13;; afterwards.
14
15;;; Code:
16
17(make-variable-buffer-local
18 (defvar fuel-popup--created-window nil))
19
20(make-variable-buffer-local
21 (defvar fuel-popup--selected-window nil))
22
23(defun fuel-popup--display (&optional buffer)
24  (when buffer (set-buffer buffer))
25  (let ((selected-window (selected-window))
26        (buffer (current-buffer)))
27    (unless (eq selected-window (get-buffer-window buffer))
28      (let ((windows))
29        (walk-windows (lambda (w) (push w windows)) nil t)
30        (prog1 (pop-to-buffer buffer)
31          (set (make-local-variable 'fuel-popup--created-window)
32               (unless (memq (selected-window) windows) (selected-window)))
33          (set (make-local-variable 'fuel-popup--selected-window)
34               selected-window))))))
35
36(defun fuel-popup--quit ()
37  (interactive)
38  (let ((selected fuel-popup--selected-window)
39        (created fuel-popup--created-window))
40    (bury-buffer)
41    (when (eq created (selected-window)) (delete-window created))
42    (when (window-live-p selected) (select-window selected))))
43
44(define-minor-mode fuel-popup-mode
45  "Mode for displaying read only stuff"
46  nil nil
47  '(("q" . fuel-popup--quit))
48  (setq buffer-read-only t))
49
50(defmacro fuel-popup--define (fun name mode)
51  `(defun ,fun ()
52     (or (get-buffer ,name)
53         (with-current-buffer (get-buffer-create ,name)
54           (funcall ,mode)
55           (fuel-popup-mode)
56           (current-buffer)))))
57
58(put 'fuel-popup--define 'lisp-indent-function 1)
59
60(defmacro fuel--with-popup (buffer &rest body)
61  `(with-current-buffer ,buffer
62     (let ((inhibit-read-only t))
63       ,@body)))
64
65(put 'fuel--with-popup 'lisp-indent-function 1)
66
67
68(provide 'fuel-popup)
69;;; fuel-popup.el ends here