Centering text in an emacs window

Within just one single emacs frame, I often switch between 70-column editing text files (LaTeX) and 120-column programs (.h / .cpp files). I would like to continue to use only one emacs frame, without resizing it or creating additional frames.

Here is the problem. The width of my window is approximately suitable for editing 120-column programs, but during extended text editing sessions, 70 columns are displayed on the left side of the window. At the end of the day in front of the laptop, my neck seems to have acquired a semi-permanent tilt to the left.

Do you know about the method to make the text look centered and the text files still jagged on the right?

+4
source share
3 answers

You can try to narrow the frame by increasing the size of the fringe. For instance:

(set-fringe-style '(200 . 200)) 

shaving 200 pixels on each side of the main text area, leaving the work area 400 pixels narrower, but still centered. To get back to normal

 (set-fringe-style 'default) 

returns the edge to its normal size.

And you can wrap this inside some tips that might work for you if you use only one window:

 (defadvice switch-to-buffer (after switch-to-buffer-adjust-fringe activate) "depending on major mode, switch fringe style" (if (memq major-mode '(latex-mode)) (set-fringe-style '(200 . 200)) (set-fringe-style 'default))) 

Note. Refresh the list (latex-mode) to include all modes in which you want to have large bands.

+5
source

EmacsWiki has a page on compressed frames . You can use the libraries and code they reference to automatically compress and enlarge the Emacs frame as needed.

0
source
 ;; Add left and right margins, when file is markdown or text. (defun center-window (window) "" (let* ((current-extension (file-name-extension (or (buffer-file-name) "foo.unknown"))) (max-text-width 80) (margin (max 0 (/ (- (window-width window) max-text-width) 2)))) (if (and (not (string= current-extension "md")) (not (string= current-extension "txt"))) ;; Do nothing if this isn't an .md or .txt file. () (set-window-margins window margin margin)))) ;; Adjust margins of all windows. (defun center-windows () "" (walk-windows (lambda (window) (center-window window)) nil 1)) ;; Listen to window changes. (add-hook 'window-configuration-change-hook 'center-windows) 

Add the file extensions above, below "md" and "txt".

0
source

Source: https://habr.com/ru/post/1384230/


All Articles