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.
I build on hide-mode-line (livejournal post or webonastick) as well as the full-screen info in the emacs wiki.
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.
Actually there already is a darkroom mode, but it only works for windows. If you use that platform, you might enjoy it anyway. So you might want to call this mode “simple darkroom”, or darkroom x11 :) ↩
Anhang | Größe |
---|---|
2011-01-22-emacs-darkroom.png | 97.37 KB |
Use Node:
⚙ Babcom is trying to load the comments ⚙
This textbox will disappear when the comments have been loaded.
If the box below shows an error-page, you need to install Freenet with the Sone-Plugin or set the node-path to your freenet node and click the Reload Comments button (or return).
If you see something like Invalid key: java.net.MalformedURLException: There is no @ in that URI! (Sone/search.html)
, you need to setup Sone and the Web of Trust
If you had Javascript enabled, you would see comments for this page instead of the Sone page of the sites author.
Note: To make a comment which isn’t a reply visible to others here, include a link to this site somewhere in the text of your comment. It will then show up here. To ensure that I get notified of your comment, also include my Sone-ID.
Link to this site and my Sone ID: sone://6~ZDYdvAgMoUfG6M5Kwi7SQqyS-gTcyFeaNN1Pf3FvY
This spam-resistant comment-field is made with babcom.
Tried to Flattr this article, but something seems to be broken
Flattering other articles works.
Thanks for the darkroom-mode. I set it up on OSX with a emacs 24.0.50 build to make fullscreen mode work. (http://citizen428.net/archives/432). I keep the modeline, since it is not that much of a distraction for me.
Had to shuffle the lines a bit to make the toggeling correct:
Additionally choosing a nice color-theme like Solarized or ZenBurn helps to get into deep thought mode.
Thanks again!
-jsl
Thanks for your comment! I
Thanks for your comment!
I now submitted the thing by hand to flattr, so it should be flattrable ( :) ) now.
Essentially you ns-toggle-fullscreen after changing the other frame values (and used smaller fringes), right?