Edited at

Elscreenに機能追加する

More than 5 years have passed since last update.

elscreenにほしかった以下の2つの機能を追加しました


screenの順番を手軽に変更

現在開いてるscreenの順番を入れ変える機能がほしくて探してみたとこ、

elscreen-swapしかないようでした。

elscreen-swapは、左隣りのscreenにしか入れ変えできず不便だったので

左右のscreenと入れ変えできるようelscreen-swap-next、elscreen-swap-previousを用意しました。

これで現在選択中のscreenを左右好きな順番へ手軽にズラすことができます

(defun elscreen-swap-previous()

"Interchange screens selected currently and previous."
(interactive)
(cond
((elscreen-one-screen-p)
(elscreen-message "There is only one screen, cannot swap"))
(t
(let* ((screen-list (sort (elscreen-get-screen-list) '>))
(previous-screen
(or (nth 1 (memq (elscreen-get-current-screen) screen-list))
(car screen-list)))
(current-screen (elscreen-get-current-screen))
(current-screen-property
(elscreen-get-screen-property current-screen))
(previous-screen-property
(elscreen-get-screen-property previous-screen)))
(elscreen-set-screen-property current-screen previous-screen-property)
(elscreen-set-screen-property previous-screen current-screen-property)
(elscreen-goto-internal (elscreen-get-current-screen)))))
(elscreen-previous))

(defun elscreen-swap-next()
"Interchange screens selected currently and next."
(interactive)
(cond
((elscreen-one-screen-p)
(elscreen-message "There is only one screen, cannot swap"))
(t
(let* ((screen-list (sort (elscreen-get-screen-list) '<))
(next-screen
(or (nth 1 (memq (elscreen-get-current-screen) screen-list))
(car screen-list)))
(current-screen (elscreen-get-current-screen))
(current-screen-property
(elscreen-get-screen-property current-screen))
(next-screen-property
(elscreen-get-screen-property next-screen)))
(elscreen-set-screen-property current-screen next-screen-property)
(elscreen-set-screen-property next-screen current-screen-property)
(elscreen-goto-internal (elscreen-get-current-screen)))))
(elscreen-next))

(global-set-key (kbd "C-M-<right>") 'elscreen-swap-next) ; screenの配置位置ずらし(右)
(global-set-key (kbd "C-M-<left>") 'elscreen-swap-previous) ; screen配置位置ずらし(左)


kill-bufferした時は、直近のバッファを表示する

screen上でkill-bfferでバッファを削除すると、scratchバッファが

次のバッファとして選択されるようだったので直近で開いてたバッファ

を選択できるようにしました

;; 直近バッファ選定時の無視リスト

(defvar elscreen-ignore-buffer-list
'("*scratch*" "*Backtrace*" "*Colors*" "*Faces*" "*Compile-Log*" "*Packages*" "*vc-" "*Minibuf-" "*Messages" "*WL:Message"))
;; elscreen用バッファ削除
(defun kill-buffer-for-elscreen ()
(interactive)
(kill-buffer)
(let* ((next-buffer nil)
(re (regexp-opt elscreen-ignore-buffer-list))
(next-buffer-list (mapcar (lambda (buf)
(let ((name (buffer-name buf)))
(when (not (string-match re name))
name)))
(buffer-list))))
(dolist (buf next-buffer-list)
(if (equal next-buffer nil)
(setq next-buffer buf)))
(switch-to-buffer next-buffer)))
(global-set-key (kbd "M-k") 'kill-buffer-for-elscreen) ; カレントバッファを閉じる