3

How can I auto run a function when open a new buffer, say text-scale-adjust.

Truong Ha
  • 10,468
  • 11
  • 40
  • 45

2 Answers2

5

A slightly more detailed version of abo-abo's answer:

(add-hook 'find-file-hook
          '(lambda () (text-scale-adjust 1)))

This will run for all files you visit. You can look at mode-specific hooks if you want to tailor which types of files/buffers get this treatment.

Dan
  • 5,209
  • 1
  • 25
  • 37
  • Placing a quote in front of `(lambda . . .` on a recent version of Emacs will create an error message (when starting Emacs or loading the file) stating that there is an extra quote. `lambda` is self-quoting, so the quote should be removed. – lawlist Feb 28 '14 at 15:16
  • Does not help with non-file buffers. – Drew Feb 28 '14 at 15:22
  • agree @Drew, it doesnt help with non-file buffers – Truong Ha Feb 28 '14 at 15:33
3

You could take a look at these hooks, as well:

  • after-change-major-mode-hook
  • change-major-mode-hook
  • change-majory-mode-after-body-hook
  • first-change-hook
  • window-configuration-change-hook

But can you clarify what the aim really is?

If you just want to make all buffers display with larger or smaller text, then it is enough to do one of the following:

  • Choose from the menu bar: Options > Set Default Font....

  • Put this in your init file: (set-frame-font "THE FONT YOU WANT, WITH THE PROPER SIZE" nil t)

  • Set the default font size for all frames to what you want, at the outset, simply by customizing default-frame-alist wrt frame parameter font.

IOW, set the font size for your frames, rather than scaling the text of all buffers.

Drew
  • 29,895
  • 7
  • 74
  • 104