emacs.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sun, 01 Aug 2010 19:34:14 +0300
changeset 478 d602ea06bb76
parent 477 88bb97fd33c5
child 499 ab94e51efbc6
permissions -rw-r--r--
Emacs games.

-*- mode: outline; coding: utf-8 -*-

* Variables.

Select one of:

  (set 'variable value)
  (setq variable value)
  (defvar variable value "documentation")

or (replace <colon> with :)

  # Local variables<colon>
  # variable<colon> value
  # End<colon>

* Debugging.

** What functions and variables Emacs load and from which files?

See value of variable 'load-history' (by C-h v load-history RET).

** Using edebug.

Execute 'M-x edebug-defun' (also on 'C-u C-M-x') on defun in source code to
enable debugging for desired function. When next time this function invoked
you entered to its debugging (jumped to its source code).

To start debug execute code which used debugged function.

You can disable edebug on a function by evaluating the function again using
'C-M-x'.

** How debug func?

Use M-x debug-on-entry and M-x cancel-debug-on-entry to control
which functions will enter the debugger when called.

When next time that function called automatically loaded debug-mode.

** How debug ini file?

When your ini has a bug, or when you load external files that cause
errors, the bug is often hard to find, because the Emacs Lisp reader does not
know about line numbers and files - it just knows an error happened, and
that's it.

*** Check if bug in ini file.

First run Emacs without loading anything:

  $ emacs --no-init-file --no-site-file

If bug not reproduced bug lies in ini files!

*** Binary Search.

Select half of the file in a region, and M-x eval-region. Depending on whether
that causes the error or not, split this half or the other half again, and
repeat.

*** Elisp.

 - Use a keyboard macro that moves forward one expression (sexp) and evaluates
   it.
 - Try C-x check-parens.
 - Set (setq debug-on-error t).

*** CLI.

  $ emacs --no-init-file --no-site-file --debug-init

*** Simplified Binary Search.

Add (error 'No error until here') in the middle of your file. If you get the
error 'No error until here' when reloading the file, move the expression
towards the back of the file, otherwise towards the front of the file.

** Call tree.

Before byte compiling file execute

  (setq byte-compile-generate-call-tree t)

* WWW.

** Text based WWW browser.

  http://en.wikipedia.org/wiki/W3m
  http://emacs-w3m.namazu.org/
  http://www.gnu.org/software/w3/

* Tricks.

** Sort and uniquify lines.

Select region, type C-u M-| sort -u RET.

With transient-mark-mode and delete-selection-mode enabled: select region,
type M-| sort -u RET to replace selection with sorted and uniquified lines.

** Determining running environment.

Check such variable:

  emacs-major-version
  emacs-minor-version
  window-system - 'nil' if in terminal, 'w32' if native Windows build, 'x' if under X Window.
  window-system-version
  operating-system-release
  system-configuration - like configuration triplet: cpu-manufacturer-os
  system-name
  system-time-locale
  system-type
  system-uses-terminfo
  window-size-fixed

Run such checks:

  (when window-system ...)
  (when (eq window-system 'x) ...)
  (when (>= emacs-major-version 22) ...)
  (when (fboundp '...) ...)
  (when (featurep '...) ...)

* Finding emacs packages.

See

  http://anc.ed.ac.uk/~stephen/emacs/ell.html
  http://www.emacswiki.org/emacs/WikifiedEmacsLispList
  http://tromey.com/elpa/index.html
                Emacs Lisp Package Archive

** ELPA.

ELPA goal is to make it simple to install, use, and upgrade Emacs Lisp
packages.

  http://tromey.com/elpa/upload.html
                how to contribute

* Compiling emacs.

** Windows.

Get MSYS for POSIX shell and utilities . Get MinGW for GCC. Get Gnuwin32 for
jpeg, ungif, tiff, xpm, png, zlib libraries.

Read emacs/nt/INSTALL.

  $ cmd
  $ cd emacs\nt
  $ configure.bat --prefix %INST_ROOT% --with-gcc --cflags -I%GNUWIN32_ROOT%/include --ldflags -L%GNUWIN32_ROOT%/lib  --ldflags -lregex
  $ make bootstrap
  $ make info
  $ make install

* Documentation.

** Elisp documentation.

  ;;; <file-name>.el --- <one-line-description>

  ;; Copyright (C) <years> <person>

  ;; Author: <person> <mail>
  ;; Maintainer: <person> <mail>
  ;; Created: <date>
  ;; Version: <version>
  ;; Keywords: <look for 'finder-by-keyword' output, separate by comma>
  ;; URL: <file-location>

  ;;; Commentary:
  <bla-bla-bla>
  ;;; Code:
  <lisp-code>
  ;;; <file-name> ends here

See

  http://www.gnu.org/software/emacs/elisp-manual/html_node/Library-Headers.html
  http://www.emacswiki.org/cgi-bin/wiki/ElispAreaConventions

*** CheckDoc.

CheckDoc checks your EmacsLisp code for errors in documentation and style.

  http://cedet.sourceforge.net/checkdoc.shtml
                home page before including it into GNU Emacs
  http://www.emacswiki.org/emacs/CheckDoc

* Installing Emacs.

** From sources.

  http://ftp.gnu.org/pub/gnu/emacs

** Windows.

  http://ftp.gnu.org/pub/gnu/emacs/windows
  http://alpha.gnu.org/gnu/emacs/windows
                beta releases for windows

** Debian.

  $ apt-get install emacs

* Emacs paths.

  source-directory data-directory doc-directory exec-directory invocation-directory trash-directory
  tutorial-directory user-emacs-directory widget-image-directory

* Emacs games.

  hanoi hanoi-unix life pong tetris gomoku