Allow to switch to all empty buffers (read-only as well)

* ace-window.el (aw-window-list): Stop filtering out empty read-only
  buffers.
(aw-empty-buffers-list): New defvar, store empty buffers here.
(aw--done): Return empty buffers to their empty state (they had a single
space inserted in order for overlay to work).
(aw--lead-overlay): Insert a space into an empty buffer.
(aw-select): Move inserting a space into `aw--lead-overlay'.
old-master
Oleh Krehel 11 years ago
parent dd84ff6054
commit 243ee467fc
  1. 33
      ace-window.el

@ -136,15 +136,11 @@ This will make `ace-window' act different from `other-window' for
(sort (sort
(cl-remove-if (cl-remove-if
(lambda (w) (lambda (w)
(let ((f (window-frame w)) (let ((f (window-frame w)))
(b (window-buffer w)))
(or (not (and (frame-live-p f) (or (not (and (frame-live-p f)
(frame-visible-p f))) (frame-visible-p f)))
(string= "initial_terminal" (terminal-name f)) (string= "initial_terminal" (terminal-name f))
(aw-ignored-p w) (aw-ignored-p w))))
(with-current-buffer b
(and buffer-read-only
(= 0 (buffer-size b)))))))
(cl-case aw-scope (cl-case aw-scope
(global (global
(cl-mapcan #'window-list (frame-list))) (cl-mapcan #'window-list (frame-list)))
@ -165,6 +161,10 @@ This will make `ace-window' act different from `other-window' for
(nconc minor-mode-alist (nconc minor-mode-alist
(list '(ace-window-mode ace-window-mode)))) (list '(ace-window-mode ace-window-mode))))
(defvar aw-empty-buffers-list nil
"Store the read-only empty buffers which had to be modified.
Modify them back eventually.")
(defun aw--done () (defun aw--done ()
"Clean up mode line and overlays." "Clean up mode line and overlays."
;; mode line ;; mode line
@ -172,13 +172,24 @@ This will make `ace-window' act different from `other-window' for
;; background ;; background
(mapc #'delete-overlay aw-overlays-back) (mapc #'delete-overlay aw-overlays-back)
(setq aw-overlays-back nil) (setq aw-overlays-back nil)
(avy--remove-leading-chars)) (avy--remove-leading-chars)
(dolist (b aw-empty-buffers-list)
(with-current-buffer b
(when (string= (buffer-string) " ")
(let ((inhibit-read-only t))
(delete-region (point-min) (point-max))))))
(setq aw-empty-buffers-list nil))
(defun aw--lead-overlay (path leaf) (defun aw--lead-overlay (path leaf)
"Create an overlay using PATH at LEAF. "Create an overlay using PATH at LEAF.
LEAF is (PT . WND)." LEAF is (PT . WND)."
(let ((wnd (cdr leaf)))
(with-selected-window wnd
(when (= 0 (buffer-size))
(push (current-buffer) aw-empty-buffers-list)
(let ((inhibit-read-only t))
(insert " ")))
(let* ((pt (car leaf)) (let* ((pt (car leaf))
(wnd (cdr leaf))
(ol (make-overlay pt (1+ pt) (window-buffer wnd))) (ol (make-overlay pt (1+ pt) (window-buffer wnd)))
(old-str (or (old-str (or
(ignore-errors (ignore-errors
@ -206,7 +217,7 @@ LEAF is (PT . WND)."
(overlay-put ol 'face 'aw-leading-char-face) (overlay-put ol 'face 'aw-leading-char-face)
(overlay-put ol 'window wnd) (overlay-put ol 'window wnd)
(overlay-put ol 'display new-str) (overlay-put ol 'display new-str)
(push ol avy--overlays-lead))) (push ol avy--overlays-lead)))))
(defun aw--make-backgrounds (wnd-list) (defun aw--make-backgrounds (wnd-list)
"Create a dim background overlay for each window on WND-LIST." "Create a dim background overlay for each window on WND-LIST."
@ -289,10 +300,6 @@ Amend MODE-LINE to the mode line for the duration of the selection."
(t (t
(let ((candidate-list (let ((candidate-list
(mapcar (lambda (wnd) (mapcar (lambda (wnd)
;; can't jump if the buffer is empty
(with-current-buffer (window-buffer wnd)
(when (= 0 (buffer-size))
(insert " ")))
(cons (aw-offset wnd) wnd)) (cons (aw-offset wnd) wnd))
wnd-list))) wnd-list)))
(aw--make-backgrounds wnd-list) (aw--make-backgrounds wnd-list)

Loading…
Cancel
Save