Emacs
Emacs
Setting up Emacs
A common issue with emacs and $\LaTeX$, at least when used with an OSX, is that the program has trouble finding the path to the $\TeX$ distribution. You'll have to tell emacs where all the $\TeX$ files are, by adding
(setq exec-path (append exec-path '("/Library/TeX/texbin")))
to the emacs' initiation file (typically at ~/.emacs).
Other issues that emacs has with the OSX is the default control (c) and meta (M) keys. While the standard keyboard has the control key in its bottom-left part (which makes it easy to press with the side of the hand while the fingers are in the letter keys), the Mac keyboard has the control key next to its bottom-left part, where the function key (fn) is. Something similar happens with the meta key, which in the Mac keyboard is replaced by the command key, but which emacs doesn't recognize as meta.
Thankfully, emacs allows a redefinition of the keys simply by adding a string in its initiation file:
- To set the left option key (alt in the Mac keyboard) as meta:
(setq mac-option-key-is-meta t)
- To set the command key as meta:
(setq mac-command-modifier 'meta)
- To disable the right option key (I think I needed this to be able to use the subscripts, brackets and the tilde with $\LaTeX$):
(setq mac-right-option-modifier nil)
- To set the function key (fn) as control:
(setq ns-function-modifier 'control)
Word Count
The easiest way to count the words from a region is:
- Select a region.
- Press M-=.
- See the count of lines, words, and characters, in the mode-line.
Spell check the text
To install the dictionary:
(require 'flymake) (setq ispell-program-name "aspell") (setq ispell-dictionary "english")
To activate the spell checker in all the text modes:
(add-hook 'text-mode-hook 'flyspell-mode) (add-hook 'text-mode-hook 'flyspell-buffer)
To spell check the whole buffer:
M-x ispell
Wrapping words in long sentences
To avoid lines with long lines of text add:
(add-hook 'text-mode-hook 'turn-on-auto-fill)
and, with the cursor in the paragraph that you want to wrap, use M-q.
Line numbers
To active the line number mode on every mode add:
(global-linum-mode t)
Turn off the alarms
Every time you do an illegal movement with the keyboard (such as striking a key that emacs doesn't recognize) or with the mouse (such as some of the gestures that the Apple mouse has incorporated), emacs rings an alarm bell. To prevent this add:
(setq ring-bell-function 'ignore)
Add a character to each line of a selected text
To do this to a region, use string-insert-rectangle. Set the mark (C-<SPC>) at the beginning of the first line you want to prefix, move the cursor to last line to be prefixed, and type M-x string-insert-rectangle <RET>. To do this for the whole buffer, type C-x h M-x string-insert-rectangle <RET>.
Remove the first 'x' characters of each line of a selected text
The best way to do this is to use the "rectangle" family of commands. For example, mark the beginning of the region. Go to the end of the region and place the point at column X. Run the command kill-rectangle using C-x r k.