Emacs Lisp (original) (raw)

Lisp was created by John McCarthy in 1958 at the Massachusetts Institute of Technology (MIT). Lisp is the second-oldest high-level programming language (Fortran beat it by one year).

  1. "set" assigns a value to a symbol
    Since quoting the symbol name is so common a second assignment operator was created, "setq"
  2. "setq" sets the value of a variable,
    but can take multiple arguments,
    (setq varname value [varname value]...)
    (setq fname "Mitch" lname "Fincher")
    It returns the last value set.
  1. Integer
  2. Floating Point
  3. Character
  4. Symbol
  5. Sequences:
    1. List
    2. Array
  6. String
  7. Vector
  1. if statement
    (if test
    then
    else1, else2,...)
    If test is true the then clause executes. If test is false all the else clauses execute.
    Example:
    (setq testme nil)
    (if testme
    (setq a "1")
    (setq a "3")
    (setq a "2")
    )
    (message a)
    when testme is nil, the value of a is "2". When testme is true a is "1"
    Note: "if" returns the value of the last expression executed.
  2. cond
    cond returns the first true condition
    (setq home-dir-emacs (cond
    ((string= emacs-version "22.1.1") "c:/opt/gnu/emacs-22.1/")
    ((string= emacs-version "21.3.1") "c:/opt/gnu/emacs-21.3/")
    ))

;; to remove the hook
(remove-hook 'find-file-hooks 'display-file-info)
Commands and functions can also have hooks. These are created using "defadvice".

(message a)(sit-for 1))
(message a)
This will display "avacado" and then "apple"
uninitialized variables may also be used.
(let ((b "banana")
(a "avacado")
c
d)

This creates temporary variables "c" and "d", but assigns no value.

  1. (point) This is the number of characters into the buffer we are. (point) returns the value.
  2. (window-start) returns the position of the character in the upper left corner.
  3. (goto-char n) takes cursor to the nth character in the buffer
  4. (set-window-start nil n) ;;sets the window start of the current buffer to n.

dired mode;
D marks a file for deletion
x deletes the ones marked
g refreshes the buffer

  1. while - looping (always returns nil)
    (setq i 0)
    (while (< i 10)
    ;; do somthing interesting here
    (setq i (1+ i))
    )
  1. defsubst
    defsubst works like defun but "inlines" the function. Works like "Inline" in C++.
  2. progn
    aggregates a series of expressions into a single one and returns the value of the last one.
    (progn (setq a "fish")(setq b "fowl")) => "fowl"
  3. prog1 Use prog1 to return the value of the first expression
    (prog1 (setq a "fish")(setq b "fowl")) => "fish"

(beginning-of-line 0)
)
)
(defun bubble-line-up(click)
;; by mitch fincher
(interactive "@e")
(beginning-of-line)(transpose-lines 1)
(previous-line 2))
(defun insert-date-stamp ()
"Insert current date at current position."
(interactive "")
(message "starting to date stamp the line...")
(beginning-of-line)
(insert "\n")
(insert (format-time-string "%D %a" (current-time)))
(insert "\n\ntimetool:\n\n")
(forward-char -1)
(message "starting to date stamp the line - finished.")
)
(defun sqlupcase ()
" upcases sql keywords in selected region"
(interactive "
")
(setq sqlkeywords '("add " "all " "alter " "and " "any " "as " "asc " "authorization " "backup " "begin " "between " "break " "browse " "bulk " "by " "cascade " "case " "check " "checkpoint " "close " "clustered " "coalesce " "collate " "column " "commit " "compute " "constraint " "contains " "containstable " "continue " "convert " "create " "cross " "current " "current_date " "current_time " "current_timestamp " "current_user " "cursor " "database " "dbcc " "deallocate " "declare " "default " "delete " "deny " "desc " "disk " "distinct " "distributed " "double " "drop " "dummy " "dump " "else " "end " "errlvl " "escape " "except " "exec " "execute " "exists " "exit " "fetch " "file " "fillfactor " "for " "foreign " "freetext " "freetexttable " "from " "full " "function " "goto " "grant " "group " "having " "holdlock " "identity " "identitycol " "identity_insert " "if " "in " "index " "inner " "insert " "intersect " "into " "is " "join " "key " "kill " "left " "like " "lineno " "load " "national " "nocheck " "nonclustered " "not " "null " "nullif " "of " "off " "offsets " "on " "open " "opendatasource " "openquery " "openrowset " "openxml " "option " "or " "order " "outer " "over " "percent " "plan " "precision " "primary " "print " "proc " "procedure " "public " "raiserror " "read " "readtext " "reconfigure " "references " "replication " "restore " "restrict " "return " "revoke " "right " "rollback " "rowcount " "rowguidcol " "rule " "save " "schema " "select " "session_user " "set " "setuser " "shutdown " "some " "statistics " "system_user " "table " "textsize " "then " "to " "top " "tran " "transaction " "trigger " "truncate " "tsequal " "union " "unique " "update " "updatetext " "use " "user " "values " "varying " "view " "waitfor " "when " "where " "while " "with " "writetext "))
(narrow-to-region (point) (mark))
(while sqlkeywords
(goto-char (point-min))
(setq keyword (car sqlkeywords))
(replace-string keyword (upcase keyword))
(setq sqlkeywords (cdr sqlkeywords))
(message keyword)(sit-for 0 1)
)
(widen)
(message "sqlupcase complete.")
)
Or the mapcar function can be used to make it more elegant:
(defun sqlupcase ()
" upcases sql keywords in selected region"
(interactive "*")
(setq sqlkeywords '("add " "all " "alter " "and " "any " "as " "asc " "authorization " "backup " "begin " "between " "break " "browse " "bulk " "by " "cascade " "case " "check " "checkpoint " "close " "clustered " "coalesce " "collate " "column " "commit " "compute " "constraint " "contains " "containstable " "continue " "convert " "create " "cross " "current " "current_date " "current_time " "current_timestamp " "current_user " "cursor " "database " "dbcc " "deallocate " "declare " "default " "delete " "deny " "desc " "disk " "distinct " "distributed " "double " "drop " "dummy " "dump " "else " "end " "errlvl " "escape " "except " "exec " "execute " "exists " "exit " "fetch " "file " "fillfactor " "for " "foreign " "freetext " "freetexttable " "from " "full " "function " "goto " "grant " "group " "having " "holdlock " "identity " "identitycol " "identity_insert " "if " "in " "index " "inner " "insert " "intersect " "into " "is " "join " "key " "kill " "left " "like " "lineno " "load " "national " "nocheck " "nonclustered " "not " "null " "nullif " "of " "off " "offsets " "on " "open " "opendatasource " "openquery " "openrowset " "openxml " "option " "or " "order " "outer " "over " "percent " "plan " "precision " "primary " "print " "proc " "procedure " "public " "raiserror " "read " "readtext " "reconfigure " "references " "replication " "restore " "restrict " "return " "revoke " "right " "rollback " "rowcount " "rowguidcol " "rule " "save " "schema " "select " "session_user " "set " "setuser " "shutdown " "some " "statistics " "system_user " "table " "textsize " "then " "to " "top " "tran " "transaction " "trigger " "truncate " "tsequal " "union " "unique " "update " "updatetext " "use " "user " "values " "varying " "view " "waitfor " "when " "where " "while " "with " "writetext "))
(narrow-to-region (point) (mark))
(mapcar (lambda (keyword)
(goto-char (point-min))
(replace-string keyword (upcase keyword) )
(message keyword)(sit-for 0 5)
) sqlkeywords)
(widen)
(message "sqlupcase complete.")
)

Now if you enter "C-f1 t" it will run the command simple-html-insert-table.

The c:/emacs/lisp/dir file will still need the top level pointers added. e.g.,

myfile.c
other.c
twice.c

results in:
myfile.C
other.C
twice.C

  1. "--no-site-file" tells emacs not to look for a site-init.el file.
  2. "--no-init-file" do not run the ~/.emacs.d/init.el or default.el
  3. "-q" start emacs without running ~/.emacs.d/init.el
  4. "--debug-init" allows debugging of the ~/.emacs.d/init.el file
  1. https://tiny-tools.sourceforge.net/emacs-keys.html
  2. emacswiki.org
  3. windows info
  4. Emacs and Unicode
  5. FAQ in text
  6. Manual in HTML
  7. an emacs email reader
  8. Emacs and Java (JDE)
  9. gnu's nt page
  10. GNU Emacs Lisp Reference Manual Excellent source of info on the language
  11. Programming in Emacs Lisp An Introduction
  12. Writing GNU Emacs Extensions A real carbon based book. Excellent intro into emacs and lisp
  13. My .vm and simple-html-mode.el files.
    The name "Emacs" is derived from "Editor Macros", but I like "Escape Meta Alt Control Shift" better.