diff options
author | Chris Feng <chris.w.feng@gmail.com> | 2015-08-26T11·35+0800 |
---|---|---|
committer | Chris Feng <chris.w.feng@gmail.com> | 2015-08-26T11·35+0800 |
commit | bb4ebde55b3bdd903cfc3bcaba3001957763c83d (patch) | |
tree | 13cdaea95779593e15b6720337f9bc71939fd29c /exwm-workspace.el | |
parent | b50a6e6dd9f5a34e91fd544e3ead0c81a7217777 (diff) |
Fix `exwm-workspace-rename-buffer`
Ensure buffer names are unique.
Diffstat (limited to 'exwm-workspace.el')
-rw-r--r-- | exwm-workspace.el | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/exwm-workspace.el b/exwm-workspace.el index cf8caa8691e7..27e317956686 100644 --- a/exwm-workspace.el +++ b/exwm-workspace.el @@ -202,16 +202,17 @@ The optional FORCE option is for internal use only." (defun exwm-workspace-rename-buffer (newname) "Rename a buffer." - (if (/= ?\s (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))) + (let ((hidden (= ?\s (aref newname 0))) + (basename (replace-regexp-in-string "<[0-9]+>$" "" newname)) + (counter 1) + tmp) + (when hidden (setq basename (substring basename 1))) + (setq newname basename) + (while (and (setq tmp (or (get-buffer newname) + (get-buffer (concat " " newname)))) + (not (eq tmp (current-buffer)))) + (setq newname (format "%s<%d>" basename (cl-incf counter)))) + (rename-buffer (concat (and hidden " ") newname)))) (defun exwm-workspace--init () "Initialize workspace module." |