Installing packages

  Install a package from MELPA/ELPA (useful for installing language modes)

  M-x package-install package-name

multiple-cursors

- install with melpa
- allows editing of groups of lines at once
- load multiple-cursors-mode in a buffer
- highlight something and add via M-x mc/mark-next-like-this
- edit
- C-g (possibly twice) to end

  These weird bindings are to work around terminal breakage
  
  C-S-c C-S-c       mc/edit-lines
  C-]               mc/mark-next-like-this
  C-c C-]           mc/mark-previous-like-this
  C-c C-c C-]       mc/mark-all-like-this

Code Folding

  use hide/show minor mode (hs-minor-mode)
  M-x hs-minor-mode

  add the minor mode to all programming modes
  (add-hook 'prog-mode-hook #'hs-minor-mode)

  C-c h
  C-c h C-s   show
  C-c h C-h   hide
  C-c h M-s   show all
  C-c h M-h   hide all
  C-c h C-C   toggle

Window Splitting and Buffers

  C-x b     switch to buffer, enter for default
  C-x C-b   list buffers

  C-x 1     delete other window  (or C-x 0)
  C-x 2     split window horizontal
  C-x 3     split window vertical
  C-x o     switch window

goto an offset in the file

  M-g M-g       goto-line
  M-g c         goto-char
  C-x 7         display-line-numbers-mode, custom binding

  M-x display-line-numbers-mode   toggles left column line numbers
  

eval a lisp expression in the current buffer and print the value in the minibuffer

  M-:
for example
  M-: major-mode
to show the current major mode

force a mode on a file, put at end of text

  // Local Variables:
  // mode: c++
  // End:

register commands

  point-to-register: C-x r SPC
  register-to-point: C-x j <register id>
  copy-to-register:  C-x r x
  insert-register:   C-x r g
  view-register: -

highlight or remove useless whitespace

To show trailing whitespace
(setq-default trailing-whitespace t)
in .emacs file.
  To turn off whitespace-mode for specific modes
  
(add-hook 'term-mode-hook (lambda () (setq show-trailing-whitespace nil)))
Added the following key bindings:

  C-x 8    toggle whitespace-mode, custom binding
  C-x 9    toggle show-trailing-whitespace, custom binding

  To remove tailing whitespace in a buffer, type
  M-x delete-trailing-whitespace
  M-x whitespace-mode will turn on and off highlighting of all whitespace

.emacs file

;; this is for shells that set either delete or backspace
;; as ctrl h use M-x help to get to help instead
(global-set-key "\C-h" 'backward-delete-char)
;; set the tab width slightly smaller
(setq default-tab-width 4)
(setq-default tab-width 4)
(setq-default c-basic-offset 4)

;; do not display a splash screen on startup for emacs 22
(setq inhibit-splash-screen t)

;; turn off menu bar in terminal
(if (not window-system)
    (menu-bar-mode -1))

;; don't use tabs to indent, may or may not want this
;; to insert a tab C-q
(setq-default indent-tabs-mode nil)

;; show trailing whitespace and add some keybindings
(setq-default show-trailing-whitespace t)
(global-set-key (kbd "C-x 7") 'display-line-numbers-mode)
(global-set-key (kbd "C-x 8") 'whitespace-mode)
(global-set-key (kbd "C-x 9") '(lambda () (interactive)
                                 (setq show-trailing-whitespace (not show-trailing-whitespace))
                                 (force-mode-line-update)
                                 (cond (show-trailing-whitespace (message "show-trailing-whitespace is True"))
                                       (t    (message "show-trailing-whitespace is False")))))

;; make sure octave files are opened in octave mode and not obj-c mode
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))

;; add code folding hs-minor-mode to all programming modes
(add-hook 'prog-mode-hook #'hs-minor-mode)
;; if you want line numbers on the lefthand side of programming modes
;;(add-hook 'prog-mode-hook 'display-line-numbers-mode)


;; https://github.com/magnars/multiple-cursors.el/blob/master/README.md
;; many terminals do not do not send C-> or C-. due to the term emulation
;; xterm does (along with C-S-c, 'S' is shift)
;; the weird bindings here are to get around terminal breakage
(require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C-]") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c C-]") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-c C-]") 'mc/mark-all-like-this)


;; remap the prefix for the hide/show to something easier
(setq hs-minor-mode-map
      (let ((map (make-sparse-keymap)))
        ;; These bindings roughly imitate those used by Outline mode.
        (define-key map (kbd "C-c h C-h") 'hs-hide-block)
        (define-key map (kbd "C-c h C-s") 'hs-show-block)
        (define-key map (kbd "C-c h M-h") 'hs-hide-all)
        (define-key map (kbd "C-c h M-s") 'hs-show-all)
        (define-key map (kbd "C-c h C-l") 'hs-hide-level)
        (define-key map (kbd "C-c h C-c") 'hs-toggle-hiding)
        (define-key map [(shift mouse-3)] 'hs-toggle-hiding)
        map))

;; python stuff
(add-hook 'python-mode-hook
          (lambda ()
            (setq indent-tabs-mode nil)
            (setq tab-width 4)
            (setq python-indent 4)
            ))


- to make the elisp debugger window go away hit 'q' in the buffer

tramp: allows you to edit files remotely through ssh as well as other methods. you can just open a file using the normal scp path syntax.

fill-paragraph

M-q is 'fill-paragraph' reflows text to justify it

turn off color

Do not use colors even if the terminal is capable (still allows the buffer mode to do syntax highlighting with bold text, etc):
emacs --color=no
Disable (all) major-mode syntax highlighting:
(global-font-lock-mode -1)
People suggest using the following in a loop over all font faces:
(set-face-attribute face nil :foreground nil :background nil)
M-x customize-face can be used over a particular keyword in a buffer to change syntax highlighting properties

M-x customize-themes to choose a color theme (includes dark themes). Consider fxn/monochrome-theme.el

Desktop Emacs Keybindings

under gnome 3

gsettings set org.gnome.desktop.interface gtk-key-theme "Emacs"

under xfce

xfconf-query -c xsettings -p /Gtk/KeyThemeName -s Emacs

may need to add --create --type string to above