I just realized that I let myself be distracted by all kinds of not-so-useful stuff instead of finally getting to type the text I already wanted to transcribe from stenografic at the beginning of … last week.
Let’s take a break for a screenshot of the final version, because that’s what we really want to gain from this article: a distraction-free screenshot as distraction from the text :)
As you can see, the distractions are removed — the screenshot is completely full screen and only the text is left. If you switch to the minibuffer (i.e. via M-x), the status bar (modeline) is shown.
To remove the distractions I looked again at WriteRoom and DarkRoom and similar which show just the text I want to write. More exactly: I thought about looking at them again, but at second thought I decided to see if I could not just customize emacs to do the same, backed with all the power you get from several decades of being THE editor for many great hackers.
It took some googling and reading emacs wiki, and then some Lisp-hacking, but finally it’s 4 o’clock in the morning and I’m writing this in my own darkroom mode1, toggled on and off by just hitting F11.
The whole code just takes 76 lines of code plus 26 lines comments and whitespace:
;;;; Activate distraction free editing with F11 ; hide mode line, from http://dse.livejournal.com/66834.html / http://webonastick.com (autoload 'hide-mode-line "hide-mode-line" nil t) ; word counting (require 'wc) (defun count-words-and-characters-buffer () "Display the number of words and characters in the current buffer." (interactive) (message (concat "The current buffer contains " (number-to-string (wc-non-interactive (point-min) (point-max))) " words and " (number-to-string (- (point-max) (point-min))) " letters."))) ; fullscreen, taken from http://www.emacswiki.org/emacs/FullScreen#toc26 ; should work for X und OSX with emacs 23.x (TODO find minimum version). ; for windows it uses (w32-send-sys-command #xf030) (#xf030 == 61488) (defvar babcore-fullscreen-p t "Check if fullscreen is on or off") (setq babcore-stored-frame-width nil) (setq babcore-stored-frame-height nil) (defun babcore-non-fullscreen () (interactive) (if (fboundp 'w32-send-sys-command) ;; WM_SYSCOMMAND restore #xf120 (w32-send-sys-command 61728) (progn (set-frame-parameter nil 'width (if babcore-stored-frame-width babcore-stored-frame-width 82)) (set-frame-parameter nil 'height (if babcore-stored-frame-height babcore-stored-frame-height 42)) (set-frame-parameter nil 'fullscreen nil)))) (defun babcore-fullscreen () (interactive) (setq babcore-stored-frame-width (frame-width)) (setq babcore-stored-frame-height (frame-height)) (if (fboundp 'w32-send-sys-command) ;; WM_SYSCOMMAND maximaze #xf030 (w32-send-sys-command 61488) (set-frame-parameter nil 'fullscreen 'fullboth))) (defun toggle-fullscreen () (interactive) (setq babcore-fullscreen-p (not babcore-fullscreen-p)) (if babcore-fullscreen-p (babcore-non-fullscreen) (babcore-fullscreen))) (global-set-key [f11] 'toggle-fullscreen) ; simple darkroom with fullscreen, fringe, mode-line, menu-bar and scroll-bar hiding. (defvar darkroom-enabled nil) ; TODO: Find out if menu bar is enabled when entering darkroom. If yes: reenable. (defvar darkroom-menu-bar-enabled nil) (defun toggle-darkroom () (interactive) (if (not darkroom-enabled) (setq darkroom-enabled t) (setq darkroom-enabled nil)) (hide-mode-line) (if darkroom-enabled (progn (toggle-fullscreen) ; if the menu bar was enabled, reenable it when disabling darkroom (if menu-bar-mode (setq darkroom-menu-bar-enabled t) (setq darkroom-menu-bar-enabled nil)) ; save the frame configuration to be able to restore to the exact previous state. (if darkroom-menu-bar-enabled (menu-bar-mode -1)) (scroll-bar-mode -1) (let ((fringe-width (* (window-width (get-largest-window)) (/ (- 1 0.61803) (1+ (count-windows))))) (char-width-pixels 6)) ; 8 pixels is the default, 6 is the average char width in pixels ; for some fonts: ; http://www.gnu.org/software/emacs/manual/html_node/emacs/Fonts.html (set-fringe-mode (truncate (* fringe-width char-width-pixels)))) (add-hook 'after-save-hook 'count-words-and-characters-buffer)) (progn (if darkroom-menu-bar-enabled (menu-bar-mode)) (scroll-bar-mode t) (set-fringe-mode nil) (remove-hook 'after-save-hook 'count-words-and-characters-buffer) (toggle-fullscreen)))) ; Activate with M-F11 -> enhanced fullscreen :) (global-set-key [M-f11] 'toggle-darkroom) (provide 'activate-darkroom)
Also I now activated cua-mode to make it easier to interact with other programs: C-c and C-x now copy/cut when the mark is active. Otherwise they are the usual prefix keys. To force them to be the prefix keys, I can use control-shift-c/-x. I thought this would disturb me, but it does not.
To make it faster, I also told cua-mode to have a maximum delay of 50ms, so I don’t feel the delay. Essentially I just put this in my ~/.emacs:
(cua-mode t) (setq cua-prefix-override-inhibit-delay 0.005)
Well, did this get me to transcribe the text? Not really, since I spent the time building my own DarkRoom/WriteRoom, but I enjoyed the little hacking and it might help me get it done tomorrow - and get far more other stuff done.
And it is really fun to write in DarkRoom mode ;)
PS: If you like the simple darkroom, please leave a comment!
I hereby declare that anyone is allowed to use this post and the screenshot under the same licensing as if it had been written in emacswiki.
The European Copyright directive threatens online communication in Europe.
But thanks to massive shared action earlier this year, the European parliament can still prevent the problems. For each of the articles there are proposals which fix them. The parliamentarians (MEPs) just have to vote for them. And since they are under massive pressure from large media companies, that went as far as defaming those who took action as fake people, the MEPs need to hear your voice to know that your are real.
If you care about the future of the Internet in the EU, please Call your MEPs.