Emacs Notes

emacs logo
  1. Build Emacs
  2. Dired Commands
  3. Recursive Search and Replace
  4. Rectangular regions (columns)
  5. Using Tags
  6. Miscellaneous Bindings
  7. Build Emacs

    Build from source. It's easy and more up to date. Make sure to check that all the libraries are in place in the configure output before building.

    Dired Commands

    In a directory (dired) buffer:

    Binding Command Notes
    m select file
    u unselct selected file
    t select all files
    %-m dired-mark-files-regexp Pick files by regex (e.g. .[ch]$' selects all *.h and *.c files
    M-x - dired-do-query-replace-regexp replace all regex matchs with string with query

    Recursive Search and Replace

    First give the base directory to recurse through. Then a pattern (glob) to select files. Use "t" to select all these files. "Q" will prompt for a regexp query string, followed by the text to replace matches with.

    Use ibuffer "*u" to select the buffers that have been changed, and "S" to save them all at once. "D" will delete them all afterwards.

    Binding Command Notes
    M-x - find-dired e.g. '-name "*.lisp"'
    t select all files
    Q query regex search and replace
    M-x - ibuffer launch ibuffer
    *u mark all unsaved buffers with changes
    S save marked buffers
    D delete marked buffers

    Rectangular regions (columns)

    Mark rectangle from one corner with C-Space to the opposite corner followed by command. Key commands work for most. Function commands are preceded by M-x. Undo (C-x u) works.

    Binding Command Notes
    C-x r M-w copy-rectangle-as-kill saves rectangle to buffer
    C-x r k kill-rectangle cuts rectangle to buffer
    C-x r y yank-rectangle pastes upper-left corner of rectangle at cursor
    C-x r c clear-rectangle clears rectangle with spaces
    C-x r o open-rectangle inserts blank rectangle the size of marked rectangle
    C-x r N rectangle-number-lines inserts numbers ahead of selected rectangle - pushing right
    C-x r t string-rectangle replace rectangle with string on each line
    string-insert-rectangle insert string in front of each line of rectangle
    delete-whitespace-rectangle deletes whitespace within rectangle

    Using Tags

    Run tags from a shell in current directory on code extensions. If just one directory, etags *.c *.h is sufficient (in C). For a source tree, do something like this:

    find . -name '*.cpp' -o -name '*.h' -o -name '*.c' -print0 
        | xargs $(ETAGS) --extra=+q --fields=+fksaiS --c++-kinds=+px --append

    Then emacs responds to the following commands:

    Binding Command Notes
    M-. undo Go to symbol definition.
    M-0 M-. dabbrev-completion Go to next match.
    M-* fill-paragraph Return to your starting point.
    M-. M-x tags-search Initiate a tags search.
    M-, M-x tags-search Go to next match.

    Miscellaneous Bindings

    Binding Command Notes
    C-_ undo Undoes very deep yank buffer, one step at a time.
    M-/ dabbrev-completion Autocompletion from tokens list for current buffers.
    M-q fill-paragraph Autoformats paragraph text. It's fairly smart about preserving prefixes, which is useful when replying to with indented quoted sections '>', '>>'. You have to manually put blank lines between prefixed paragraphs, before formatting, otherwise Emacs thinks it's all one paragraph. Also usually does the right thing with numbered/bulletted paragraphs.

    Note: you may have to run e16keyedit to turn off some of the bindings enlightenment captures first.