Xah Lee, , …,
When coding in Python or viewing directories in dired, mono-spaced font is necessary. However, proportional font works great in coding too. Try it. You may be surprised.
Proportional font is easier to read, and shows 20 or more characters per line. I got used to using proportional fonts for HTML, XML, Perl, lisp. Even if you don't like proportional font for coding, it is quite useful for reading documentation, email, irc.
One problem is that it is cumbersome to switch font in emacs. Here's a elisp code that cycle fonts.
(defun cycle-font (num) "Change font in current frame. Each time this is called, font cycles thru a predefined set of fonts. If NUM is 1, cycle forward. If NUM is -1, cycle backward. Warning: tested on Windows Vista only." (interactive "p") ;; this function sets a property “state”. It is a integer. Possible values are any index to the fontList. (let (fontList fontToUse currentState nextState ) (setq fontList (list "Courier New-10" "DejaVu Sans Mono-9" "Lucida Console-10" "DejaVu Sans-10" "Lucida Sans Unicode-10" "Arial Unicode MS-10" )) ;; fixed-width "Courier New" "Unifont" "FixedsysTTF" "Miriam Fixed" "Lucida Console" "Lucida Sans Typewriter" ;; variable-width "Code2000" (setq currentState (if (get 'cycle-font 'state) (get 'cycle-font 'state) 0)) (setq nextState (% (+ currentState (length fontList) num) (length fontList))) (setq fontToUse (nth nextState fontList)) (set-frame-parameter nil 'font fontToUse) (redraw-frame (selected-frame)) (message "Current font is: %s" fontToUse ) (put 'cycle-font 'state nextState) ) )
(defun cycle-font-forward () "Switch to the next font, in the current frame. See `cycle-font'." (interactive) (cycle-font 1) ) (defun cycle-font-backward () "Switch to the previous font, in the current frame. See `cycle-font'." (interactive) (cycle-font -1) )
Modify the section on fontList:
(setq fontList (list
"Courier New-10" "DejaVu Sans Mono-9" "Lucida Console-10"
"DejaVu Sans-10" "Lucida Sans Unicode-10" "Arial Unicode MS-10"
))
so that you can use this function to cycle among the fonts of your choice.
You can also reduce the font list to just 2 fonts. One for fixed-width and one for variable-width. So, the command becomes a toggle between fixed/variable-width font.
You can set F6 and F7 to swich to the prev/next font. See: Defining Your Own Keyboard Shortcuts.
Also, if you are not using emacs 23, you should upgrade, because emacs 23 switched its internal char encoding to Unicode (utf-8), and has a new font engine that supports operating system's fonts and anti-aliasing. (➲ New Features in Emacs 23)
In my work, i often have files with lots unicode math symbols. But also a lot coding in HTML, elisp, Python, but also a lot reading of documents.
The best font i found is DejaVu Sans Mono for fixed-width and Lucida Sans Unicode for variable-width. Variable-width is my normal font. I switch to mono for python, dired, calender, etc.
For best fonts and download location, see: Best Fonts for Unicode.
Oscar Carlsson wrote to say there's a “variable-pitch-mode”. That's fantastic. To return to fixed-width font, just call it again. Give it a hotkey for easy toggling.
This is nice but uses a face mechanism that's different from font switching. In particular:
Overall, i don't use this much. Because everytimes i open/close a file, i have to toggle font. Also, i still prefer the font i've chosen.
A optimal solution is to always open dired, Python, etc files with fixed-width font and otherwise variable-width font, but i haven't explored elisp code for that.
When reading a document, you may want to have extra space between lines, for easy reading. Here's a command that toggles line height.
(defun toggle-line-spacing () "Toggle line spacing between no extra space to extra half line height." (interactive) (if (eq line-spacing nil) (setq-default line-spacing 0.5) ; add 0.5 height between lines (setq-default line-spacing nil) ; no extra heigh between lines ))
If you are using emacs 23, the command “toggle-word-wrap” is useful. When on, long lines are wrapped at white space. Otherwise, words are simply cut in the middle at the edge of window.