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

- 10,468
- 11
- 40
- 45
-
1There's a `find-file-hook` along with mode specific hooks. – abo-abo Feb 28 '14 at 07:19
-
@abo-abo: Does not help with non-file buffers. – Drew Feb 28 '14 at 15:23
2 Answers
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.

- 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
-
-
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 parameterfont
.
IOW, set the font size for your frames, rather than scaling the text of all buffers.

- 29,895
- 7
- 74
- 104