Skip to content

Commit

Permalink
Merge pull request #152 from Zulu-Inuoe/fix-over-consing
Browse files Browse the repository at this point in the history
Fix over consing
  • Loading branch information
bmag committed Jun 28, 2019
2 parents 548676f + fbbb370 commit f642196
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
17 changes: 9 additions & 8 deletions window-purpose-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ regexp REGEXP."
"Return the purpose of buffer BUFFER-OR-NAME, as determined by the
regexps matched by its name.
REGEXP-CONF is a hash table mapping name regexps to purposes."
(car (remove nil
(purpose--iter-hash
#'(lambda (regexp purpose)
(purpose--buffer-purpose-name-regexp-1 buffer-or-name
regexp
purpose))
regexp-conf))))
(catch 'found
(maphash
#'(lambda (regexp purpose)
(when (purpose--buffer-purpose-name-regexp-1 buffer-or-name
regexp
purpose)
(throw 'found purpose)))
regexp-conf)))

(defun purpose-buffer-purpose (buffer-or-name)
"Get the purpose of buffer BUFFER-OR-NAME.
Expand Down Expand Up @@ -168,7 +169,7 @@ If no purpose was determined, return `default-purpose'."

(defun purpose-buffers-with-purpose (purpose)
"Return a list of all existing buffers with purpose PURPOSE."
(cl-remove-if-not #'(lambda (buffer)
(cl-delete-if-not #'(lambda (buffer)
(and (eql purpose (purpose-buffer-purpose buffer))
(not (minibufferp buffer))))
(buffer-list)))
Expand Down
4 changes: 1 addition & 3 deletions window-purpose-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ Example:
for each entry in hash-table TABLE."
(let (results)
(maphash #'(lambda (key value)
(setq results
(append results
(list (funcall function key value)))))
(push (funcall function key value) results))
table)
results))

Expand Down
16 changes: 12 additions & 4 deletions window-purpose-x.el
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,21 @@ This function removes the buffer denoted by BUFFER-OR-NAME from all
window-local buffer lists."
(interactive "bBuffer to replace: ")
(let* ((buffer (window-normalize-buffer buffer-or-name))
(purpose (purpose-buffer-purpose buffer))
(other-buffers (delete buffer (purpose-buffers-with-purpose purpose))))
;; Delay calculating other-buffers until we need it
;; This prevents unnecessary calculations on temporary
;; buffers created by `with-temp-buffer' and other likewise
;; non-displayed buffers
(other-buffers-calculated nil)
(other-buffers nil))
(dolist (window (window-list-1 nil nil t))
(if (eq (window-buffer window) buffer)
(unless (window--delete window t t)
(let ((dedicated (purpose-window-purpose-dedicated-p window))
(deletable (window-deletable-p window)))
(let* ((purpose (purpose-buffer-purpose buffer))
(dedicated (purpose-window-purpose-dedicated-p window))
(deletable (window-deletable-p window)))
(unless other-buffers-calculated
(setq other-buffers (delete buffer (purpose-buffers-with-purpose purpose))
other-buffers-calculated t))
(cond
((and dedicated other-buffers)
;; dedicated, so replace with a buffer with the same purpose
Expand Down

0 comments on commit f642196

Please sign in to comment.