After a few trials and errors, I finally managed to find a series of customization for my Emacs to be the almost perfect distraction free environment. However, I don't want these settings to load every time I open Emacs, I want to be able to press a button (like F10) and have a chain of commands executed, like the following:

M-x load-theme solarized-dark
M-x org-mode
M-x olivetti-mode
M-x olivetti-set-width 120
M-x wc-goal-count

And I would like to revert the commands and their effect, once I'm done with writing (obviously without quitting Emacs).

An acceptable course of action (maybe more elegant) would be to execute all this when loading olivetti-mode, since I'll use this mode exclusively in distraction free environment, but I would like to be able to revert all those settings too. I'm sure it's possible, but I can't figure it out yet.

I'm obviously a n00b, so any idea, setting, hint, link that would simplify my workflow is welcomed.


Just create a new function and bind it to a key:

(defun no-distraction ()
   "Switch to no distraction env"
   (load-theme 'tango)
   (olivetti-set-width 120)
(global-set-key (kbd "<f5>") 'no-distraction)

Save this into your .emacs file.

Semi-tested only (I don't have olivetti-mode installed). Might need further tweaking.

  • 1
    I haven't inspected the five (5) functions at issue, but sometimes functions test for whether they are interactively called, and it may be necessary to use call-interactively or else the function might behave differently than expected. The original poster is also requesting an undo / restore function -- i.e., go there with one function, and put everything back the way it was with another function. – lawlist Apr 24 '17 at 16:19
  • @Drew: It's on the first line. – choroba Apr 24 '17 at 16:22
  • @choroba: It works as intended, it executes a series of commands and it seems to do it properly. It doesn't have the undo/restore command, but I don't mine. Thank you! – Claudiu Apr 24 '17 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.