escreen instead of elscreen for screen-like features in emacs

Emacs
Linux
Author

Vinh Nguyen

Published

March 7, 2011

I've been using elscreen for screen-like features in emacs the last couple of years. However, I have a few complaints. Elscreen has issues when used with emacsclient -c: a new frame might not be created from the -c argument, which messes up my current screen in emacs, and the "Opening Server Files Always in a New Frame" tip on this did not resolve this issue perfectly with elscreen. Also, when used with emacs' Desktop mode, I get an error when launching emacs with an Rnw file (Rweave, or Sweave) is in the file list; the launch actually does not load all files, and I have to exit and delete my desktop file (which I'll lose the list of files).

I discovered escreen from this post a long time ago, and thought escreen was pretty lightweight and worked pretty well. However, I never switched to it because it didn't have "tabs" for me to know which screen I was at. I didn't realize the very same post had customizations that would show which screen you are at. I've copied his customizations, and added a few more of my own, which I'll list here:

;; escreen is simpler than elscreen...but elscreen spawns new 0-9 set of screens for a new frame whereas escreen does not
;; it is better than elscreen because: elscreen has issues when using with emacsclient -c (does not always create new frame, messes up existing frame); in escreen, each screen has its own ring of recently visited files (good!)
;; http://blog.tapoueh.org/news.dim.html#%20Escreen%20integration
;; http://www.splode.com/~friedman/software/emacs-lisp/#ui
(load "escreen")
(escreen-install)
(setq escreen-prefix-char "\C-z") ;; http://www.macs.hw.ac.uk/~hwloidl/cool-el.html
(global-set-key escreen-prefix-char 'escreen-prefix)
;; add C-\ l to list screens with emphase for current one
(defun escreen-get-active-screen-numbers-with-emphasis ()
 "what the name says"
 (interactive)
 (let ((escreens (escreen-get-active-screen-numbers))
 (emphased ""))

 (dolist (s escreens)
 (setq emphased
 (concat emphased (if (= escreen-current-screen-number s)
 (propertize (number-to-string s)
 ;;'face 'custom-variable-tag) " ")
 'face 'info-title-3)
 ;;'face 'font-lock-warning-face)
 ;;'face 'secondary-selection)
 (number-to-string s))
 " ")))
 (message "escreen: active screens: %s" emphased)))

(global-set-key (kbd "C-\\ l") 'escreen-get-active-screen-numbers-with-emphasis)

(defun escreen-goto-last-screen-dim ()
 (interactive)
 (escreen-goto-last-screen)
 (escreen-get-active-screen-numbers-with-emphasis))

(defun escreen-goto-prev-screen-dim (&optional n)
 (interactive "p")
 (escreen-goto-prev-screen n)
 (escreen-get-active-screen-numbers-with-emphasis))

(defun escreen-goto-next-screen-dim (&optional n)
 (interactive "p")
 (escreen-goto-next-screen n)
 (escreen-get-active-screen-numbers-with-emphasis))

(define-key escreen-map escreen-prefix-char 'escreen-goto-last-screen-dim)

(defun escreen-create-screen-dim ()
 (interactive)
 (escreen-create-screen)
 (escreen-get-active-screen-numbers-with-emphasis))

(defun escreen-kill-screen-dim ()
 (interactive)
 (escreen-kill-screen)
 (escreen-get-active-screen-numbers-with-emphasis))

(add-hook 'escreen-goto-screen-hook 'escreen-get-active-screen-numbers-with-emphasis)

(define-key escreen-map "c" 'escreen-create-screen-dim)
(define-key escreen-map "k" 'escreen-kill-screen-dim)

;; (global-set-key (kbd "C-]") 'escreen-goto-next-screen)
;; (keyboard-translate ?\C-[ ?\H-[)
;; (global-set-key (kbd "H-[") 'escreen-goto-prev-screen)
(global-set-key (kbd "C-]") 'escreen-goto-next-screen-dim)
(keyboard-translate ?\C-[ ?\H-[)
(global-set-key (kbd "H-[") 'escreen-goto-prev-screen-dim)

Whenever I create/kill/visit a screen, the minibuffer will always show the list of screens available, with emphasis on the current screen. I like escreen because it does not have the issues I listed before with elscreen. Also, in escreen, each screen has its own ring of recently visited files, so that if I move to a different screen and edit a buffer, move back to my original screen, kill the buffer, the recent buffer from the other screen will not be the default screen on this current screen.

I like escreen!