0

I thought it would be handy to be able to change the font height of a buffer on the fly by invoking a key press and giving the font height you would want, e.g. C-t 130 would set the local buffer font size to 130. I've been able to write a function that can change the font size to a preset value like thus:

(defun set-font-low ()
 "Lowers the font of this buffer to 70.  call `set-font-high` for reverse."
 (interactive)
 (setq buffer-face-mode-face '( :height 70))
 (buffer-face-mode))

A modified version would include the possibility of setting this font height interactively:

(defun set-font-height (size)
  "set font height for local buffer"
  (interactive "sheight:")
    (message size)
    (setq buffer-face-mode-face '( :height (size)))
    (buffer-face-mode))

However, this code doesn't work. The message shows the correct size, and the font size isn't changed. substituting size with 70 will still produce no change. What's more, regardless of the specific argument used, after this function is executed moving the cursor up or down in that buffer becomes impossible, e.g. C-p results in a wrong type argument: stringp, nil error.

I'd guess my problem is that I'm trying to set the attribute to a variable rather than to a number. in jmibanez's answer to this question he seems to be able to do just that, but I can't figure out what the correct syntax is in this problem.

I'm running GNU Emacs 26.0.90 (build 1, x86_64-w64-mingw32) on windows 10.

0

Your interactive spec gives you a string for your size argument, and emacs wants a number for :height. What you want is

(interactive "nheight: ")

To set :height attribute in buffer-face-mode-face to a variable (currently you're setting it to a list with one element, the symbol size):

(setq buffer-face-mode-face (list :height size))

PS. You can change buffer face height using built-in command text-scale-adjust bound to C-x C-+.

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.