diff options
author | Chris Feng <chris.w.feng@gmail.com> | 2015-07-26T08·04+0800 |
---|---|---|
committer | Chris Feng <chris.w.feng@gmail.com> | 2015-07-26T08·04+0800 |
commit | f4416a10e3f87ceddc70ae02f065f14c5e6dc3fd (patch) | |
tree | f9c2010212042411d7c5a903e67509b1886ed109 /exwm-workspace.el | |
parent | 36e8361b9bd581e89d593b32002404bbf4811b62 (diff) |
Fix potential naming conflicts
Buffers may share a same name (without the possible leading space) when created in different workspaces.
Diffstat (limited to 'exwm-workspace.el')
-rw-r--r-- | exwm-workspace.el | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el index bab2612f4f4c..b46b2e8d9946 100644 --- a/exwm-workspace.el +++ b/exwm-workspace.el @@ -119,9 +119,9 @@ The optional FORCE option is for internal use only " (dolist (i exwm--id-buffer-alist) (with-current-buffer (cdr i) (let ((name (replace-regexp-in-string "^\\s-*" "" (buffer-name)))) - (rename-buffer (if (eq (selected-frame) exwm--frame) - name - (concat " " name)))))) + (exwm-workspace-rename-buffer (if (eq (selected-frame) exwm--frame) + name + (concat " " name)))))) ;; Update demands attention flag (set-frame-parameter (selected-frame) 'exwm--urgency nil) ;; Update switch workspace history @@ -151,7 +151,7 @@ The optional FORCE option is for internal use only " (let ((frame (elt exwm-workspace--list index))) (with-current-buffer (exwm--id->buffer id) (setq exwm--frame frame) - (rename-buffer + (exwm-workspace-rename-buffer (concat " " (replace-regexp-in-string "^\\s-*" "" (buffer-name)))) (if exwm--floating-frame ;; Move the floating frame is enough @@ -172,6 +172,19 @@ The optional FORCE option is for internal use only " (xcb:flush exwm--connection) (exwm-workspace--update-switch-history))) +(defun exwm-workspace-rename-buffer (newname) + "Rename a buffer." + (if (/= ? (aref newname 0)) + (rename-buffer newname t) + ;; If a buffer name is prefixed with a space, Emacs append a random + ;; number before renaming it. This is not desired behavior. + (let ((name (replace-regexp-in-string "<[0-9]+>$" "" newname)) + (counter 1)) + (while (and (get-buffer newname) + (not (eq (get-buffer newname) (current-buffer)))) + (setq newname (format "%s<%d>" name (cl-incf counter))))) + (rename-buffer newname))) + (defun exwm-workspace--init () "Initialize workspace module." (cl-assert (and (< 0 exwm-workspace-number) (>= 10 exwm-workspace-number))) |