Centre Emacs buffer within window

前端 未结 4 640
执笔经年
执笔经年 2021-02-09 00:52

I wrap all my code at 80 columns, and there are times where the Emacs window is wider than 80 columns and there is a lot of unused whitespace on the right side.

I would

4条回答
  •  我寻月下人不归
    2021-02-09 01:24

    Here is a function which should do what you want, using margins instead of fringes (since I tend to display buffer boundaries in the fringe and I find it becomes ugly if the fringe is too large).

    (defun my/center (width)
      (interactive "nBuffer width: ")
      (let* ((adj          (- (window-text-width)
                              width))
             (total-margin (+ adj
                              left-margin-width
                              right-margin-width)))
        (setq left-margin-width  (/ total-margin 2))
        (setq right-margin-width (- total-margin left-margin-width)))
      (set-window-buffer (selected-window) (current-buffer)))
    

提交回复
热议问题