4

My emacs installation has over time grown so that the startup has started taking multiple seconds. The only feasible way to run emacs then is in daemon mode and then connecting with emacsclient. In my init.el I have the following snippet:

(lambda ()
 (when (display-graphic-p)
 (set-scroll-bar-mode 'right)
 (menu-bar-mode -1)
 (tool-bar-mode -1)))

This runs once on startup and and removes the toolbars atop graphical emacs, along with putting the scroll bar on the right hand side of the window. But in terminal emacs set-scroll-bar-mode is undefined, hence the surrounding if-statement.

The problem then is that this code runs on emacs startup, not when a client connects to the emacs daemon. Where do I hook up this function so that it's run for every new emacsclient that connects.

3
  • You can use the -e flag to run elisp code with emacsclient. Example: emacsclient -c -e "(menu-bar-mode -1)(tool-bar-mode -1)"
    – Nsukami _
    Feb 16, 2015 at 10:59
  • Does anyone know why scroll-bar-mode is defined in terminal mode but set-scroll-bar-mode is not? It seems odd that you can enable/disable scroll bars but not set which side they will be on. Possibly a bug?
    – dshepherd
    Feb 16, 2015 at 11:17
  • Client/server is great (keep using it), but if you also want to reduce your server start-up time, you should be able to do that too. Slow start times are usually a consequence of forcibly loading (e.g. with require) libraries up front, before they are actually needed. Emacs provides the autoload and eval-after-load mechanisms which enable you to avoid loading libraries unnecessarily. Start learning about those if you're interested in a faster start time.
    – phils
    Feb 16, 2015 at 22:09

1 Answer 1

7

It looks like you can run functions each time a new frame is created with after-make-frame-functions (see this question for a bit more information).

The code would look something like

(defun set-my-scrollbars (_)
  (set-scroll-bar-mode 'right))
(add-to-list 'after-make-frame-functions #'set-my-scrollbars)

(I only briefly tested it). The dummy argument is needed because functions in after-make-frame-functions are given the frame as an argument.

5
  • I'm curious as to what the hash sign before 'set-my-scrollbars does.
    – Rovanion
    Feb 16, 2015 at 11:26
  • 1
    It's a "sharp quote" or "function quote", it tells the byte-compiler that the quoted thing is a function which allows undefined functions to be detected automatically. It's not really important for cases like this but I've gotten into the habit of doing it everywhere. More information here and here.
    – dshepherd
    Feb 16, 2015 at 11:37
  • 1
    It's common practice to use _ for dummy arguments BTW.
    – wasamasa
    Feb 16, 2015 at 12:06
  • Yeah I use it in other languages but I wasn't sure if it is common in lisps, changed it.
    – dshepherd
    Feb 16, 2015 at 12:07
  • 1
    I would add a (server-running-p) check so it only runs when it's actually a server.
    – PythonNut
    Feb 16, 2015 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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