Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce popwin-mode.

Now use display-buffer-alist instead of display-buffer-function,
which is deprecated since GNU Emacs 24.3.
  • Loading branch information...
commit b6ac46b65acb15894ae9ae34686945369d798e93 1 parent f37958e
Tomohiro Matsuyama authored
Showing with 107 additions and 71 deletions.
  1. +9 −16 Makefile
  2. +22 −0 NEWS.md
  3. +1 −1  README.md
  4. +73 −53 popwin.el
  5. +2 −1  test/popwin-test.el
View
25 Makefile
@@ -1,25 +1,18 @@
EMACS=emacs
-EMACS23=emacs23
-.PHONY: compile clean test test-nw test-emacs23 test-emacs23-nw
+.PHONY: byte-compile clean test test-nw
-compile: popwin.el
- $(EMACS) --batch -f batch-byte-compile popwin.el
+byte-compile: popwin.el
+ $(EMACS) -Q --batch -f batch-byte-compile popwin.el
clean:
- rm -f popwin.elc
+ rm -f popwin.elc test/ert.el
-test: compile
- $(EMACS) -Q -L . -l test/popwin-test.el
+test: byte-compile test/ert.el
+ $(EMACS) -Q -l popwin.el -l test/ert.el -l test/popwin-test.el
-test-nw: compile
- $(EMACS) -Q -nw -L . -l test/popwin-test.el
-
-test-emacs23: compile test/ert.el
- $(EMACS23) -Q -L . -l test/ert.el -l test/popwin-test.el
-
-test-emacs23-nw: compile test/ert.el
- $(EMACS23) -Q -nw -L . -l test/ert.el -l test/popwin-test.el
+test-nw: byte-compile
+ $(EMACS) -Q -nw -l popwin.el -l test/ert.el -l test/popwin-test.el
test/ert.el:
- wget http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/emacs-lisp/ert.el -O $@
+ wget https://raw.github.com/ohler/ert/c619b56c5bc6a866e33787489545b87d79973205/lisp/emacs-lisp/ert.el -O $@
View
22 NEWS.md
@@ -1,3 +1,25 @@
+v0.7.0
+======
+
+Highlight
+---------
+
+- Introduce popwin-mode. You can now toggle the mode by `M-x
+ popwin-mode`.
+
+Compatibility
+-------------
+
+- Using `display-buffer-function` is deprecated since GNU Emacs 24.3.
+ You should fix the configuration in `.emacs` like
+
+ (setq display-buffer-function 'popwin:display-buffer)
+
+ to
+
+ (popwin-mode 1)
+
+
v0.6.2
======
View
2  README.md
@@ -42,7 +42,7 @@ Install `popwin.el` into your `load-path` directory. If you have
And then add the following code into your `.emacs`:
(require 'popwin)
- (setq display-buffer-function 'popwin:display-buffer)
+ (popwin-mode 1)
popwin is tested under GNU Emacs 22 or later.
View
126 popwin.el
@@ -4,7 +4,7 @@
;; Author: Tomohiro Matsuyama <tomo@cx4a.org>
;; Keywords: convenience
-;; Version: 0.6.2
+;; Version: 0.7.0alpha
;; 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
@@ -27,7 +27,7 @@
;; To use popwin, just add the following code into your .emacs:
;;
;; (require 'popwin)
-;; (setq display-buffer-function 'popwin:display-buffer)
+;; (popwin-mode 1)
;;
;; Then try to show some buffer, for example *Help* or
;; *Completeions*. Unlike standard behavior, their buffers may be
@@ -61,7 +61,7 @@
(eval-when-compile (require 'cl))
-(defconst popwin:version "0.6")
+(defconst popwin:version "0.7.0alpha")
@@ -665,7 +665,15 @@ be closed by `popwin:close-popup-window'."
(defmacro popwin:without-special-displaying (&rest body)
"Evaluate BODY without special displaying."
- `(let (display-buffer-function) ,@body))
+ (if (boundp 'display-buffer-alist)
+ `(with-no-warnings
+ (let ((display-buffer-function nil)
+ (display-buffer-alist
+ (remove '(popwin:display-buffer-condition
+ popwin:display-buffer-action)
+ display-buffer-alist)))
+ ,@body))
+ `(with-no-warnings (let ((display-buffer-function nil)) ,@body))))
(defcustom popwin:special-display-config
'(;; Emacs
@@ -825,6 +833,24 @@ special displaying."
(popwin:original-pop-to-buffer (car popwin:popup-last-config))
(error "No popup buffer ever")))
+(defun* popwin:match-config (buffer)
+ (when (stringp buffer) (setq buffer (get-buffer buffer)))
+ (loop with name = (buffer-name buffer)
+ with mode = (buffer-local-value 'major-mode buffer)
+ for config in popwin:special-display-config
+ for (pattern . keywords) = (popwin:listify config)
+ if (cond ((eq pattern t) t)
+ ((and (stringp pattern) (plist-get keywords :regexp))
+ (string-match pattern name))
+ ((stringp pattern)
+ (string= pattern name))
+ ((symbolp pattern)
+ (eq pattern mode))
+ ((functionp pattern)
+ (funcall pattern buffer))
+ (t (error "Invalid pattern: %s" pattern)))
+ return (cons pattern keywords)))
+
(defun* popwin:display-buffer-1 (buffer-or-name
&key
default-config-keywords
@@ -839,55 +865,23 @@ value is :create, create a new buffer named BUFFER-OR-NAME. If
the value is :error, report an error. The default value
is :create. DEFAULT-CONFIG-KEYWORDS is a property list which
specifies default values of the config."
- (loop with buffer = (popwin:get-buffer buffer-or-name if-buffer-not-found)
- with name = (buffer-name buffer)
- with mode = (buffer-local-value 'major-mode buffer)
- with win-width = popwin:popup-window-width
- with win-height = popwin:popup-window-height
- with win-position = popwin:popup-window-position
- with win-noselect
- with win-dedicated
- with win-stick
- with win-tail
- with found
- until found
- for config in (if if-config-not-found
- popwin:special-display-config
- `(,@popwin:special-display-config t))
- for (pattern . keywords) = (popwin:listify config) do
- (destructuring-bind (&key regexp width height position noselect dedicated stick tail)
- (append keywords default-config-keywords)
- (let ((matched (cond ((eq pattern t) t)
- ((and (stringp pattern) regexp)
- (string-match pattern name))
- ((stringp pattern)
- (string= pattern name))
- ((symbolp pattern)
- (eq pattern mode))
- ((functionp pattern)
- (funcall pattern buffer))
- (t (error "Invalid pattern: %s" pattern)))))
- (when matched
- (setq found t
- win-width (or width win-width)
- win-height (or height win-height)
- win-position (or position win-position)
- win-noselect noselect
- win-dedicated dedicated
- win-stick stick
- win-tail tail))))
- finally return
- (if (not found)
- (funcall if-config-not-found buffer)
- (popwin:popup-buffer buffer
- :width win-width
- :height win-height
- :position win-position
- :noselect (or (popwin:minibuffer-window-selected-p)
- win-noselect)
- :dedicated win-dedicated
- :stick win-stick
- :tail win-tail))))
+ (let* ((buffer (popwin:get-buffer buffer-or-name if-buffer-not-found))
+ (pattern-and-keywords (popwin:match-config buffer)))
+ (unless pattern-and-keywords
+ (if if-config-not-found
+ (return-from popwin:display-buffer-1
+ (funcall if-config-not-found buffer))
+ (setq pattern-and-keywords '(t))))
+ (destructuring-bind (&key regexp width height position noselect dedicated stick tail)
+ (append (cdr pattern-and-keywords) default-config-keywords)
+ (popwin:popup-buffer buffer
+ :width (or width popwin:popup-window-width)
+ :height (or height popwin:popup-window-height)
+ :position (or position popwin:popup-window-position)
+ :noselect (or (popwin:minibuffer-window-selected-p) noselect)
+ :dedicated dedicated
+ :stick stick
+ :tail tail))))
;;;###autoload
(defun popwin:display-buffer (buffer-or-name &optional not-this-window)
@@ -1001,6 +995,32 @@ original window configuration."
+;;; Minor Mode
+
+(defun popwin:display-buffer-condition (buffer action)
+ (and (popwin:match-config buffer) t))
+
+(defun popwin:display-buffer-action (buffer alist)
+ (let ((not-this-window (plist-get 'inhibit-same-window alist)))
+ (popwin:display-buffer buffer not-this-window)))
+
+(define-minor-mode popwin-mode
+ ""
+ :init-value nil
+ :global t
+ (if (boundp 'display-buffer-alist)
+ (let ((pair '(popwin:display-buffer-condition popwin:display-buffer-action)))
+ (if popwin-mode
+ (push pair display-buffer-alist)
+ (setq display-buffer-alist (delete pair display-buffer-alist))))
+ (with-no-warnings
+ (unless (or (null display-buffer-function)
+ (eq display-buffer-function 'popwin:display-buffer))
+ (warn "Overwriting display-buffer-function variable to enable/disable popwin-mode"))
+ (setq display-buffer-function (if popwin-mode 'popwin:display-buffer nil)))))
+
+
+
;;; Keymaps
(defvar popwin:keymap
View
3  test/popwin-test.el
@@ -1,7 +1,8 @@
(require 'popwin)
(require 'ert)
-(setq display-buffer-function 'popwin:display-buffer)
+;(setq display-buffer-function 'popwin:display-buffer)
+(popwin-mode 1)
(setq popwin:popup-window-position 'bottom)
(defun popwin-test:front-buffer-p (buffer)
Please sign in to comment.
Something went wrong with that request. Please try again.