Skip to content

Instantly share code, notes, and snippets.

@tam17aki
Created August 27, 2013 14:20
Show Gist options
  • Save tam17aki/6354138 to your computer and use it in GitHub Desktop.
Save tam17aki/6354138 to your computer and use it in GitHub Desktop.
(require 'cl-lib)
(cl-defun ido-choose-visible-window ()
"ウィンドウ切り替えをido補完で.選択中のウィンドウは切り替え候補から外す."
(interactive)
(let ((alist (mapcar (lambda (win)
(cons (buffer-name (window-buffer win))
win))
(remove (selected-window)
(window-list))))
result)
(unless alist
(cl-return-from choose-visible-window))
(dolist (cons alist)
(when (> (cl-count
(car cons)
(mapcar 'car alist)
:test 'string-equal)
1)
(cl-loop for item in (cl-remove
(car cons) alist :key 'car :test-not 'equal)
for counter = 1 then (1+ counter)
do (setcar item (concat (car item) "_"
(number-to-string counter))))))
(setq result
(if (= 1 (length alist))
(caar alist)
(ido-completing-read "Choose buffer: "
(mapcar 'car alist) nil t)))
(when result
(select-window (cdr (assoc result alist)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment