add errors to debug-ignored-errors and some more cleanup

This commit is contained in:
deb0ch 2016-11-28 22:39:06 +01:00
parent d29c2bee0e
commit ddacef5a30

View file

@ -257,27 +257,51 @@ Such a structure allows for per-frame bidirectional fast access.")
'window-numbering--update) 'window-numbering--update)
(setq window-numbering--frames-table nil)) (setq window-numbering--frames-table nil))
(defun window-numbering--list-windows-in-frame (&optional f) ;; TODO bug: mode-line is sometimes not updated in all visible frames
"List windows in frame F using natural Emacs ordering." (defun window-numbering--update ()
(window-list f 0 (frame-first-window f))) "Update window numbers."
(setq window-numbering--remaining (window-numbering--get-available-numbers))
(defun window-numbering--get-window-vector ()
"Return the window vector used to get a window given a number.
This vector is not stored the same way depending on the value of
`window-numbering-scope'."
(if (eq window-numbering-scope 'frame-local) (if (eq window-numbering-scope 'frame-local)
(car (gethash (selected-frame) (puthash (selected-frame)
window-numbering--frames-table)) (cons (make-vector 10 nil) (make-hash-table :size 10))
window-numbering--window-vector)) window-numbering--frames-table)
(setq window-numbering--window-vector (make-vector 10 nil))
(clrhash window-numbering--numbers-table))
(when (and window-numbering-auto-assign-0-to-minibuffer
(active-minibuffer-window))
(window-numbering--assign (active-minibuffer-window) 0))
(let ((windows (window-numbering--window-list)))
(run-hook-with-args 'window-numbering-before-hook windows)
(when window-numbering-assign-func
(mapc (lambda (w)
(with-selected-window w
(with-current-buffer (window-buffer w)
(let ((num (funcall window-numbering-assign-func)))
(when num
(window-numbering--assign w num))))))
windows))
(dolist (w windows)
(window-numbering--assign w))))
(defun window-numbering--get-numbers-table () (defun window-numbering--assign (window &optional number)
"Return the numbers hashtable used to get a number given a window. "Assign to window WINDOW the number NUMBER.
This hashtable is not stored the same way depending on the value of If NUMBER is not specified, determine it first based on
`window-numbering-scope'" `window-numbering--remaining'.
(if (eq window-numbering-scope 'frame-local) Returns the assigned number, or nil on error."
(cdr (gethash (selected-frame) (if number
window-numbering--frames-table)) (if (aref (window-numbering--get-window-vector) number)
window-numbering--numbers-table)) (progn (message "Number %s assigned to two buffers (%s and %s)"
number window (aref window-numbering--window-vector number))
nil)
(setf (aref (window-numbering--get-window-vector) number) window)
(puthash window number (window-numbering--get-numbers-table))
(setq window-numbering--remaining (delq number window-numbering--remaining))
number)
;; else determine number and assign
(when window-numbering--remaining
(unless (gethash window (window-numbering--get-numbers-table))
(let ((number (car window-numbering--remaining)))
(window-numbering--assign window number))))))
(defun window-numbering--window-list () (defun window-numbering--window-list ()
"Return a list of interesting windows." "Return a list of interesting windows."
@ -305,25 +329,27 @@ This hashtable is not stored the same way depending on the value of
(t (t
(error "Invalid `window-numbering-scope': %S" window-numbering-scope))))) (error "Invalid `window-numbering-scope': %S" window-numbering-scope)))))
(defun window-numbering--assign (window &optional number) (defun window-numbering--list-windows-in-frame (&optional f)
"Assign to window WINDOW the number NUMBER. "List windows in frame F using natural Emacs ordering."
If NUMBER is not specified, determine it first based on (window-list f 0 (frame-first-window f)))
`window-numbering--remaining'.
Returns the assigned number, or nil on error." (defun window-numbering--get-window-vector ()
(if number "Return the window vector used to get a window given a number.
(if (aref (window-numbering--get-window-vector) number) This vector is not stored the same way depending on the value of
(progn (message "Number %s assigned to two buffers (%s and %s)" `window-numbering-scope'."
number window (aref window-numbering--window-vector number)) (if (eq window-numbering-scope 'frame-local)
nil) (car (gethash (selected-frame)
(setf (aref (window-numbering--get-window-vector) number) window) window-numbering--frames-table))
(puthash window number (window-numbering--get-numbers-table)) window-numbering--window-vector))
(setq window-numbering--remaining (delq number window-numbering--remaining))
number) (defun window-numbering--get-numbers-table ()
;; else determine number and assign "Return the numbers hashtable used to get a number given a window.
(when window-numbering--remaining This hashtable is not stored the same way depending on the value of
(unless (gethash window (window-numbering--get-numbers-table)) `window-numbering-scope'"
(let ((number (car window-numbering--remaining))) (if (eq window-numbering-scope 'frame-local)
(window-numbering--assign window number)))))) (cdr (gethash (selected-frame)
window-numbering--frames-table))
window-numbering--numbers-table))
(defun window-numbering--get-available-numbers (&optional windows) (defun window-numbering--get-available-numbers (&optional windows)
"Return a list of numbers currently available for assignment. "Return a list of numbers currently available for assignment.
@ -339,32 +365,6 @@ WINDOWS: a vector of currently assigned windows."
(decf i)) (decf i))
left)) left))
;; TODO bug: mode-line is sometimes not updated in all visible frames
(defun window-numbering--update ()
"Update window numbers."
(setq window-numbering--remaining (window-numbering--get-available-numbers))
(if (eq window-numbering-scope 'frame-local)
(puthash (selected-frame)
(cons (make-vector 10 nil) (make-hash-table :size 10))
window-numbering--frames-table)
(setq window-numbering--window-vector (make-vector 10 nil))
(clrhash window-numbering--numbers-table))
(when (and window-numbering-auto-assign-0-to-minibuffer
(active-minibuffer-window))
(window-numbering--assign (active-minibuffer-window) 0))
(let ((windows (window-numbering--window-list)))
(run-hook-with-args 'window-numbering-before-hook windows)
(when window-numbering-assign-func
(mapc (lambda (w)
(with-selected-window w
(with-current-buffer (window-buffer w)
(let ((num (funcall window-numbering-assign-func)))
(when num
(window-numbering--assign w num))))))
windows))
(dolist (w windows)
(window-numbering--assign w))))
(defun window-numbering--switch-to-window (window) (defun window-numbering--switch-to-window (window)
"Switch to the window WINDOW and switch input focus if on a different frame." "Switch to the window WINDOW and switch input focus if on a different frame."
(let ((frame (window-frame window))) (let ((frame (window-frame window)))
@ -376,6 +376,8 @@ WINDOWS: a vector of currently assigned windows."
(error "Got a dead window %S" window)))) (error "Got a dead window %S" window))))
(push "^No window numbered .$" debug-ignored-errors) (push "^No window numbered .$" debug-ignored-errors)
(push "^Got a dead window .$" debug-ignored-errors)
(push "^Invalid `window-numbering-scope': .$" debug-ignored-errors)
(provide 'window-numbering) (provide 'window-numbering)