<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikemacs.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gregben</id>
	<title>WikEmacs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wikemacs.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gregben"/>
	<link rel="alternate" type="text/html" href="https://wikemacs.org/wiki/Special:Contributions/Gregben"/>
	<updated>2026-04-20T01:11:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>https://wikemacs.org/index.php?title=Re-builder&amp;diff=2636</id>
		<title>Re-builder</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Re-builder&amp;diff=2636"/>
		<updated>2012-04-10T01:21:36Z</updated>

		<summary type="html">&lt;p&gt;Gregben: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
An interactive Emacs tool to build a '''regexp''' (regular expression).&lt;br /&gt;
&lt;br /&gt;
RE-Builder allows you to interactively develop a '''regexp''' on the contents of the currently active buffer. &lt;br /&gt;
Immediately after you type each character, the subject buffer is updated to highlight all those strings that match the&lt;br /&gt;
'''regexp''' you've created thus far. Only the first 200 matches (if there are more than 200) are shown.&lt;br /&gt;
&lt;br /&gt;
== Invocation ==&lt;br /&gt;
&lt;br /&gt;
'''M-x re-builder'''&lt;br /&gt;
&lt;br /&gt;
A new window is created just above the minibuffer with a single a pair of quotation marks (&amp;quot;&amp;quot;).&lt;br /&gt;
This is the '''*RE-Builder*''' buffer.&lt;br /&gt;
&lt;br /&gt;
You ''build'' your '''regexp''' between the quotation marks in this buffer.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Re-builder&amp;diff=2635</id>
		<title>Re-builder</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Re-builder&amp;diff=2635"/>
		<updated>2012-04-10T01:19:44Z</updated>

		<summary type="html">&lt;p&gt;Gregben: Created page with &amp;quot;== RE-Builder ==  An interactive Emacs tool to build a '''regexp''' (regular expression).  == Invocation ==  '''M-x re-builder'''  A new window is created just above the minib...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== RE-Builder ==&lt;br /&gt;
&lt;br /&gt;
An interactive Emacs tool to build a '''regexp''' (regular expression).&lt;br /&gt;
&lt;br /&gt;
== Invocation ==&lt;br /&gt;
&lt;br /&gt;
'''M-x re-builder'''&lt;br /&gt;
&lt;br /&gt;
A new window is created just above the minibuffer with a single a pair of quotation marks (&amp;quot;&amp;quot;).&lt;br /&gt;
This is the '''*RE-Builder*''' buffer.&lt;br /&gt;
&lt;br /&gt;
You ''build'' your '''regexp''' between the quotation marks in this buffer.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
RE-Builder allows you to interactively develop a '''regexp''' on the contents of the currently active buffer. Immediately after you type each character, the subject buffer is updated to highlight all those strings that match the&lt;br /&gt;
'''regexp''' you've created thus far. Only the first 200 matches (if there are more than 200) are shown.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Regexp&amp;diff=2634</id>
		<title>Regexp</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Regexp&amp;diff=2634"/>
		<updated>2012-04-10T00:39:27Z</updated>

		<summary type="html">&lt;p&gt;Gregben: /* Tips and Tricks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Origin ==&lt;br /&gt;
&lt;br /&gt;
'''Regexp''' is a portmanteau of the words '''regular''' and '''expression'''. It is the Emacs abbreviation for &amp;quot;regular expression&amp;quot;.&lt;br /&gt;
Many other computer languages and software use the abbreviation '''regex''' (no trailing p) instead.&lt;br /&gt;
&lt;br /&gt;
Wikipedia article about [http://en.wikipedia.org/wiki/Regular_expression regular expressions]&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
The following characters are special : . * + ? ^ $ \ [&lt;br /&gt;
&lt;br /&gt;
Between brackets [], the following are special : ] - ^&lt;br /&gt;
&lt;br /&gt;
Many characters are special when they follow a backslash – see below.&lt;br /&gt;
&lt;br /&gt;
  .        any character (but newline)&lt;br /&gt;
  *        previous character or group, repeated 0 or more time&lt;br /&gt;
  +        previous character or group, repeated 1 or more time&lt;br /&gt;
  ?        previous character or group, repeated 0 or 1 time  &lt;br /&gt;
  ^        start of line&lt;br /&gt;
  $        end of line&lt;br /&gt;
  [...]    any character between brackets&lt;br /&gt;
  [^..]    any character not in the brackets&lt;br /&gt;
  [a-z]    any character between a and z&lt;br /&gt;
  \        prevents interpretation of following special char&lt;br /&gt;
  \|       or&lt;br /&gt;
  \w       word constituent&lt;br /&gt;
  \b       word boundary&lt;br /&gt;
  \sc      character with c syntax (e.g. \s- for whitespace char)&lt;br /&gt;
  \( \)    start\end of group&lt;br /&gt;
  \&amp;lt; \&amp;gt;    start\end of word&lt;br /&gt;
  \` \'    start\end of buffer&lt;br /&gt;
  \1       string matched by the first group&lt;br /&gt;
  \n       string matched by the nth group&lt;br /&gt;
  \{3\}    previous character or group, repeated 3 times&lt;br /&gt;
  \{3,\}   previous character or group, repeated 3 or more times&lt;br /&gt;
  \{3,6\}  previous character or group, repeated 3 to 6 times&lt;br /&gt;
.?, +?, and ?? are non-greedy versions of ., +, and ?&lt;br /&gt;
\W, \B, and \Sc match any character that does not match \w, \b, and \sc&lt;br /&gt;
&lt;br /&gt;
=== Character category ===&lt;br /&gt;
&lt;br /&gt;
  \ca      ascii character&lt;br /&gt;
  \Ca      non-ascii character (newline included)&lt;br /&gt;
  \cl      latin character&lt;br /&gt;
  \cg      greek character&lt;br /&gt;
&lt;br /&gt;
=== POSIX character classes ===&lt;br /&gt;
&lt;br /&gt;
  [:digit:]  a digit, same as [0-9]&lt;br /&gt;
  [:upper:]  a letter in uppercase&lt;br /&gt;
  [:space:]  a whitespace character, as defined by the syntax table&lt;br /&gt;
  [:xdigit:] an hexadecimal digit&lt;br /&gt;
  [:cntrl:]  a control character&lt;br /&gt;
  [:ascii:]  an ascii character&lt;br /&gt;
&lt;br /&gt;
=== Syntax classes ===&lt;br /&gt;
&lt;br /&gt;
  \s-   whitespace character        \s/   character quote character&lt;br /&gt;
  \sw   word constituent            \s$   paired delimiter         &lt;br /&gt;
  \s_   symbol constituent          \s'   expression prefix        &lt;br /&gt;
  \s.   punctuation character       \s&amp;lt;   comment starter          &lt;br /&gt;
  \s(   open delimiter character    \s&amp;gt;   comment ender            &lt;br /&gt;
  \s)   close delimiter character   \s!   generic comment delimiter&lt;br /&gt;
  \s&amp;quot;   string quote character      \s|   generic string delimiter &lt;br /&gt;
  \s\   escape character&lt;br /&gt;
&lt;br /&gt;
== Regexp Examples ==&lt;br /&gt;
&lt;br /&gt;
 [-+[:digit:]]                     digit or + or - sign&lt;br /&gt;
 \(\+\|-\)?[0-9]+\(\.[0-9]+\)?     decimal number (-2 or 1.5 but not .2 or 1.)&lt;br /&gt;
 \(\w+\) +\1\&amp;gt;                     two consecutive, identical words&lt;br /&gt;
 \&amp;lt;[[:upper:]]\w*                  word starting with an uppercase letter&lt;br /&gt;
  +$                               trailing whitespaces (note the starting SPC)&lt;br /&gt;
 \w\{20,\}                         word with 20 letters or more&lt;br /&gt;
 \w+phony\&amp;gt;                        word ending by phony&lt;br /&gt;
 \(19\|20\)[0-9]\{2\}              year 1900-2099&lt;br /&gt;
 ^.\{6,\}                          at least 6 symbols&lt;br /&gt;
 ^[a-zA-Z0-9_]\{3,16\}$            decent string for a user name&lt;br /&gt;
 &amp;lt;tag[^&amp;gt; C-q C-j ]*&amp;gt;\(.*?\)&amp;lt;/tag&amp;gt;  html tag&lt;br /&gt;
&lt;br /&gt;
== Emacs Commands that Use Regular Expressions ==&lt;br /&gt;
&lt;br /&gt;
 C-M-s                   incremental forward search matching regexp&lt;br /&gt;
 C-M-r                   incremental backward search matching regexp &lt;br /&gt;
 replace-regexp          replace string matching regexp&lt;br /&gt;
 query-replace-regexp    same, but query before each replacement&lt;br /&gt;
 align-regexp            align, using strings matching regexp as delimiters&lt;br /&gt;
 highlight-regexp        highlight strings matching regexp&lt;br /&gt;
 occur                   show lines containing a match&lt;br /&gt;
 multi-occur             show lines in all buffers containing a match&lt;br /&gt;
 how-many                count the number of strings matching regexp&lt;br /&gt;
 keep-lines              delete all lines except those containing matches&lt;br /&gt;
 flush-lines             delete lines containing matches&lt;br /&gt;
 grep                    call unix grep command and put result in a buffer&lt;br /&gt;
 lgrep                   user-friendly interface to the grep command&lt;br /&gt;
 rgrep                   recursive grep&lt;br /&gt;
 dired-do-copy-regexp    copy files with names matching regexp&lt;br /&gt;
 dired-do-rename-regexp  rename files matching regexp &lt;br /&gt;
 find-grep-dired         display files containing matches for regexp with Dired&lt;br /&gt;
&lt;br /&gt;
== Tips and Tricks ==&lt;br /&gt;
&lt;br /&gt;
To enter a '''newline''' character in a regexp, use the two keystroke sequence '''C-q C-j'''.&lt;br /&gt;
It will appear in the minibuffer as '''^J'''.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[[Re-builder]] build regexp interactively in buffer&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Regexp&amp;diff=2633</id>
		<title>Regexp</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Regexp&amp;diff=2633"/>
		<updated>2012-04-10T00:37:17Z</updated>

		<summary type="html">&lt;p&gt;Gregben: Added Tips and Tricks section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Origin ==&lt;br /&gt;
&lt;br /&gt;
'''Regexp''' is a portmanteau of the words '''regular''' and '''expression'''. It is the Emacs abbreviation for &amp;quot;regular expression&amp;quot;.&lt;br /&gt;
Many other computer languages and software use the abbreviation '''regex''' (no trailing p) instead.&lt;br /&gt;
&lt;br /&gt;
Wikipedia article about [http://en.wikipedia.org/wiki/Regular_expression regular expressions]&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
The following characters are special : . * + ? ^ $ \ [&lt;br /&gt;
&lt;br /&gt;
Between brackets [], the following are special : ] - ^&lt;br /&gt;
&lt;br /&gt;
Many characters are special when they follow a backslash – see below.&lt;br /&gt;
&lt;br /&gt;
  .        any character (but newline)&lt;br /&gt;
  *        previous character or group, repeated 0 or more time&lt;br /&gt;
  +        previous character or group, repeated 1 or more time&lt;br /&gt;
  ?        previous character or group, repeated 0 or 1 time  &lt;br /&gt;
  ^        start of line&lt;br /&gt;
  $        end of line&lt;br /&gt;
  [...]    any character between brackets&lt;br /&gt;
  [^..]    any character not in the brackets&lt;br /&gt;
  [a-z]    any character between a and z&lt;br /&gt;
  \        prevents interpretation of following special char&lt;br /&gt;
  \|       or&lt;br /&gt;
  \w       word constituent&lt;br /&gt;
  \b       word boundary&lt;br /&gt;
  \sc      character with c syntax (e.g. \s- for whitespace char)&lt;br /&gt;
  \( \)    start\end of group&lt;br /&gt;
  \&amp;lt; \&amp;gt;    start\end of word&lt;br /&gt;
  \` \'    start\end of buffer&lt;br /&gt;
  \1       string matched by the first group&lt;br /&gt;
  \n       string matched by the nth group&lt;br /&gt;
  \{3\}    previous character or group, repeated 3 times&lt;br /&gt;
  \{3,\}   previous character or group, repeated 3 or more times&lt;br /&gt;
  \{3,6\}  previous character or group, repeated 3 to 6 times&lt;br /&gt;
.?, +?, and ?? are non-greedy versions of ., +, and ?&lt;br /&gt;
\W, \B, and \Sc match any character that does not match \w, \b, and \sc&lt;br /&gt;
&lt;br /&gt;
=== Character category ===&lt;br /&gt;
&lt;br /&gt;
  \ca      ascii character&lt;br /&gt;
  \Ca      non-ascii character (newline included)&lt;br /&gt;
  \cl      latin character&lt;br /&gt;
  \cg      greek character&lt;br /&gt;
&lt;br /&gt;
=== POSIX character classes ===&lt;br /&gt;
&lt;br /&gt;
  [:digit:]  a digit, same as [0-9]&lt;br /&gt;
  [:upper:]  a letter in uppercase&lt;br /&gt;
  [:space:]  a whitespace character, as defined by the syntax table&lt;br /&gt;
  [:xdigit:] an hexadecimal digit&lt;br /&gt;
  [:cntrl:]  a control character&lt;br /&gt;
  [:ascii:]  an ascii character&lt;br /&gt;
&lt;br /&gt;
=== Syntax classes ===&lt;br /&gt;
&lt;br /&gt;
  \s-   whitespace character        \s/   character quote character&lt;br /&gt;
  \sw   word constituent            \s$   paired delimiter         &lt;br /&gt;
  \s_   symbol constituent          \s'   expression prefix        &lt;br /&gt;
  \s.   punctuation character       \s&amp;lt;   comment starter          &lt;br /&gt;
  \s(   open delimiter character    \s&amp;gt;   comment ender            &lt;br /&gt;
  \s)   close delimiter character   \s!   generic comment delimiter&lt;br /&gt;
  \s&amp;quot;   string quote character      \s|   generic string delimiter &lt;br /&gt;
  \s\   escape character&lt;br /&gt;
&lt;br /&gt;
== Regexp Examples ==&lt;br /&gt;
&lt;br /&gt;
 [-+[:digit:]]                     digit or + or - sign&lt;br /&gt;
 \(\+\|-\)?[0-9]+\(\.[0-9]+\)?     decimal number (-2 or 1.5 but not .2 or 1.)&lt;br /&gt;
 \(\w+\) +\1\&amp;gt;                     two consecutive, identical words&lt;br /&gt;
 \&amp;lt;[[:upper:]]\w*                  word starting with an uppercase letter&lt;br /&gt;
  +$                               trailing whitespaces (note the starting SPC)&lt;br /&gt;
 \w\{20,\}                         word with 20 letters or more&lt;br /&gt;
 \w+phony\&amp;gt;                        word ending by phony&lt;br /&gt;
 \(19\|20\)[0-9]\{2\}              year 1900-2099&lt;br /&gt;
 ^.\{6,\}                          at least 6 symbols&lt;br /&gt;
 ^[a-zA-Z0-9_]\{3,16\}$            decent string for a user name&lt;br /&gt;
 &amp;lt;tag[^&amp;gt; C-q C-j ]*&amp;gt;\(.*?\)&amp;lt;/tag&amp;gt;  html tag&lt;br /&gt;
&lt;br /&gt;
== Emacs Commands that Use Regular Expressions ==&lt;br /&gt;
&lt;br /&gt;
 C-M-s                   incremental forward search matching regexp&lt;br /&gt;
 C-M-r                   incremental backward search matching regexp &lt;br /&gt;
 replace-regexp          replace string matching regexp&lt;br /&gt;
 query-replace-regexp    same, but query before each replacement&lt;br /&gt;
 align-regexp            align, using strings matching regexp as delimiters&lt;br /&gt;
 highlight-regexp        highlight strings matching regexp&lt;br /&gt;
 occur                   show lines containing a match&lt;br /&gt;
 multi-occur             show lines in all buffers containing a match&lt;br /&gt;
 how-many                count the number of strings matching regexp&lt;br /&gt;
 keep-lines              delete all lines except those containing matches&lt;br /&gt;
 flush-lines             delete lines containing matches&lt;br /&gt;
 grep                    call unix grep command and put result in a buffer&lt;br /&gt;
 lgrep                   user-friendly interface to the grep command&lt;br /&gt;
 rgrep                   recursive grep&lt;br /&gt;
 dired-do-copy-regexp    copy files with names matching regexp&lt;br /&gt;
 dired-do-rename-regexp  rename files matching regexp &lt;br /&gt;
 find-grep-dired         display files containing matches for regexp with Dired&lt;br /&gt;
&lt;br /&gt;
== Tips and Tricks ==&lt;br /&gt;
&lt;br /&gt;
To enter a '''newline''' character in a regexp, use the two keystroke sequence '''C-q C-j'''.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[[Re-builder]] build regexp interactively in buffer&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Regexp&amp;diff=2632</id>
		<title>Regexp</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Regexp&amp;diff=2632"/>
		<updated>2012-04-09T21:15:49Z</updated>

		<summary type="html">&lt;p&gt;Gregben: Added small section introducing regular expressions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Origin ==&lt;br /&gt;
&lt;br /&gt;
'''Regexp''' is a portmanteau of the words '''regular''' and '''expression'''. It is the Emacs abbreviation for &amp;quot;regular expression&amp;quot;.&lt;br /&gt;
Many other computer languages and software use the abbreviation '''regex''' (no trailing p) instead.&lt;br /&gt;
&lt;br /&gt;
Wikipedia article about [http://en.wikipedia.org/wiki/Regular_expression regular expressions]&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
&lt;br /&gt;
The following characters are special : . * + ? ^ $ \ [&lt;br /&gt;
&lt;br /&gt;
Between brackets [], the following are special : ] - ^&lt;br /&gt;
&lt;br /&gt;
Many characters are special when they follow a backslash – see below.&lt;br /&gt;
&lt;br /&gt;
  .        any character (but newline)&lt;br /&gt;
  *        previous character or group, repeated 0 or more time&lt;br /&gt;
  +        previous character or group, repeated 1 or more time&lt;br /&gt;
  ?        previous character or group, repeated 0 or 1 time  &lt;br /&gt;
  ^        start of line&lt;br /&gt;
  $        end of line&lt;br /&gt;
  [...]    any character between brackets&lt;br /&gt;
  [^..]    any character not in the brackets&lt;br /&gt;
  [a-z]    any character between a and z&lt;br /&gt;
  \        prevents interpretation of following special char&lt;br /&gt;
  \|       or&lt;br /&gt;
  \w       word constituent&lt;br /&gt;
  \b       word boundary&lt;br /&gt;
  \sc      character with c syntax (e.g. \s- for whitespace char)&lt;br /&gt;
  \( \)    start\end of group&lt;br /&gt;
  \&amp;lt; \&amp;gt;    start\end of word&lt;br /&gt;
  \` \'    start\end of buffer&lt;br /&gt;
  \1       string matched by the first group&lt;br /&gt;
  \n       string matched by the nth group&lt;br /&gt;
  \{3\}    previous character or group, repeated 3 times&lt;br /&gt;
  \{3,\}   previous character or group, repeated 3 or more times&lt;br /&gt;
  \{3,6\}  previous character or group, repeated 3 to 6 times&lt;br /&gt;
.?, +?, and ?? are non-greedy versions of ., +, and ?&lt;br /&gt;
\W, \B, and \Sc match any character that does not match \w, \b, and \sc&lt;br /&gt;
&lt;br /&gt;
=== Character category ===&lt;br /&gt;
&lt;br /&gt;
  \ca      ascii character&lt;br /&gt;
  \Ca      non-ascii character (newline included)&lt;br /&gt;
  \cl      latin character&lt;br /&gt;
  \cg      greek character&lt;br /&gt;
&lt;br /&gt;
=== POSIX character classes ===&lt;br /&gt;
&lt;br /&gt;
  [:digit:]  a digit, same as [0-9]&lt;br /&gt;
  [:upper:]  a letter in uppercase&lt;br /&gt;
  [:space:]  a whitespace character, as defined by the syntax table&lt;br /&gt;
  [:xdigit:] an hexadecimal digit&lt;br /&gt;
  [:cntrl:]  a control character&lt;br /&gt;
  [:ascii:]  an ascii character&lt;br /&gt;
&lt;br /&gt;
=== Syntax classes ===&lt;br /&gt;
&lt;br /&gt;
  \s-   whitespace character        \s/   character quote character&lt;br /&gt;
  \sw   word constituent            \s$   paired delimiter         &lt;br /&gt;
  \s_   symbol constituent          \s'   expression prefix        &lt;br /&gt;
  \s.   punctuation character       \s&amp;lt;   comment starter          &lt;br /&gt;
  \s(   open delimiter character    \s&amp;gt;   comment ender            &lt;br /&gt;
  \s)   close delimiter character   \s!   generic comment delimiter&lt;br /&gt;
  \s&amp;quot;   string quote character      \s|   generic string delimiter &lt;br /&gt;
  \s\   escape character&lt;br /&gt;
&lt;br /&gt;
== Regexp Examples ==&lt;br /&gt;
&lt;br /&gt;
 [-+[:digit:]]                     digit or + or - sign&lt;br /&gt;
 \(\+\|-\)?[0-9]+\(\.[0-9]+\)?     decimal number (-2 or 1.5 but not .2 or 1.)&lt;br /&gt;
 \(\w+\) +\1\&amp;gt;                     two consecutive, identical words&lt;br /&gt;
 \&amp;lt;[[:upper:]]\w*                  word starting with an uppercase letter&lt;br /&gt;
  +$                               trailing whitespaces (note the starting SPC)&lt;br /&gt;
 \w\{20,\}                         word with 20 letters or more&lt;br /&gt;
 \w+phony\&amp;gt;                        word ending by phony&lt;br /&gt;
 \(19\|20\)[0-9]\{2\}              year 1900-2099&lt;br /&gt;
 ^.\{6,\}                          at least 6 symbols&lt;br /&gt;
 ^[a-zA-Z0-9_]\{3,16\}$            decent string for a user name&lt;br /&gt;
 &amp;lt;tag[^&amp;gt; C-q C-j ]*&amp;gt;\(.*?\)&amp;lt;/tag&amp;gt;  html tag&lt;br /&gt;
&lt;br /&gt;
== Emacs Commands that Use Regular Expressions ==&lt;br /&gt;
&lt;br /&gt;
 C-M-s                   incremental forward search matching regexp&lt;br /&gt;
 C-M-r                   incremental backward search matching regexp &lt;br /&gt;
 replace-regexp          replace string matching regexp&lt;br /&gt;
 query-replace-regexp    same, but query before each replacement&lt;br /&gt;
 align-regexp            align, using strings matching regexp as delimiters&lt;br /&gt;
 highlight-regexp        highlight strings matching regexp&lt;br /&gt;
 occur                   show lines containing a match&lt;br /&gt;
 multi-occur             show lines in all buffers containing a match&lt;br /&gt;
 how-many                count the number of strings matching regexp&lt;br /&gt;
 keep-lines              delete all lines except those containing matches&lt;br /&gt;
 flush-lines             delete lines containing matches&lt;br /&gt;
 grep                    call unix grep command and put result in a buffer&lt;br /&gt;
 lgrep                   user-friendly interface to the grep command&lt;br /&gt;
 rgrep                   recursive grep&lt;br /&gt;
 dired-do-copy-regexp    copy files with names matching regexp&lt;br /&gt;
 dired-do-rename-regexp  rename files matching regexp &lt;br /&gt;
 find-grep-dired         display files containing matches for regexp with Dired&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[[Re-builder]] build regexp interactively in buffer&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Emacs_Lisp_Cookbook&amp;diff=2631</id>
		<title>Emacs Lisp Cookbook</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Emacs_Lisp_Cookbook&amp;diff=2631"/>
		<updated>2012-04-09T20:52:57Z</updated>

		<summary type="html">&lt;p&gt;Gregben: grammatical corrections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains snippets of code that demonstrate basic [[Emacs Lisp]]&lt;br /&gt;
programming operations in the spirit of O'Reilly's Cookbook&lt;br /&gt;
series of books. For every task addressed, a worked-out solution&lt;br /&gt;
is presented as a short, focused, directly usable piece of code.&lt;br /&gt;
&lt;br /&gt;
All this stuff can be found elsewhere, but it is scattered about in&lt;br /&gt;
libraries, manuals, etc.  It would be helpful to have it here in one&lt;br /&gt;
spot.&lt;br /&gt;
&lt;br /&gt;
These recipes should be pastable into the '''*scratch*''' buffer so that&lt;br /&gt;
users can hit '''C-j''' and evaluate them step by step.&lt;br /&gt;
&lt;br /&gt;
== Strings ==&lt;br /&gt;
&lt;br /&gt;
The empty string (zero-length string, null string, ...):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(zerop (string-match &amp;quot;&amp;quot; &amp;quot;&amp;quot;)) ;; O(n)&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(string-equal &amp;quot;&amp;quot; &amp;quot;&amp;quot;) ;; O(n)?&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(equal &amp;quot;&amp;quot; &amp;quot;&amp;quot;) ;; O(n)?&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(zerop (length &amp;quot;&amp;quot;)) ;; O(1)&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(eq &amp;quot;&amp;quot; &amp;quot;&amp;quot;) ;; O(1)&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As a space and performance optimization, Emacs keeps an intern-ed copy&lt;br /&gt;
of the empty string as a single object&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(eq &amp;quot;&amp;quot; (purecopy &amp;quot;&amp;quot;))&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(eq &amp;quot;&amp;quot; (propertize &amp;quot;&amp;quot; 'face 'italic))&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Strings vs buffer content ===&lt;br /&gt;
&lt;br /&gt;
While it is quite common in other programming languages to work on&lt;br /&gt;
strings contained in variables in Emacs it is even more idiomatic to&lt;br /&gt;
work on strings in buffers. That's why the following contains examples&lt;br /&gt;
of both.&lt;br /&gt;
&lt;br /&gt;
=== Substrings ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(substring &amp;quot;abcdefg&amp;quot; 0 3)&lt;br /&gt;
==&amp;gt; &amp;quot;abc&amp;quot;&lt;br /&gt;
(substring &amp;quot;abcdefg&amp;quot; -3 -1)&lt;br /&gt;
==&amp;gt; &amp;quot;ef&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The TO argument is optional:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(substring &amp;quot;abcdefg&amp;quot; -3)&lt;br /&gt;
==&amp;gt; &amp;quot;efg&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Buffers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(with-temp-buffer&lt;br /&gt;
  (insert &amp;quot;abcdefg&amp;quot;)&lt;br /&gt;
  (buffer-substring 2 4))&lt;br /&gt;
==&amp;gt; &amp;quot;bc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Processing characters ===&lt;br /&gt;
&lt;br /&gt;
Reversing a string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(string-to-list &amp;quot;foo&amp;quot;)&lt;br /&gt;
==&amp;gt; (102 111 111)&lt;br /&gt;
(reverse (string-to-list &amp;quot;foo&amp;quot;))&lt;br /&gt;
==&amp;gt; (111 111 102)&lt;br /&gt;
(apply 'string (reverse (string-to-list &amp;quot;foo&amp;quot;)))&lt;br /&gt;
==&amp;gt; &amp;quot;oof&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See CharacterProcessing and StringModification. See [[tr]] for an example of you sometimes need to mix strings and characters.&lt;br /&gt;
&lt;br /&gt;
Looking at characters in buffers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(with-temp-buffer&lt;br /&gt;
  (insert &amp;quot;abcdefg&amp;quot;)&lt;br /&gt;
  (goto-char (point-min))&lt;br /&gt;
  (while (not (= (char-after) ?b))&lt;br /&gt;
    (forward-char))&lt;br /&gt;
  (point))&lt;br /&gt;
==&amp;gt; 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Trim whitespace ===&lt;br /&gt;
&lt;br /&gt;
Trim whitespace from the end of a string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(setq test-str &amp;quot;abcdefg  &amp;quot;)&lt;br /&gt;
(when (string-match &amp;quot;[ \t]*$&amp;quot; test-str)&lt;br /&gt;
  (message (concat &amp;quot;[&amp;quot; (replace-match &amp;quot;&amp;quot; nil nil test-str) &amp;quot;]&amp;quot;)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trim whitespace from a string with a Perl-like chomp function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(defun chomp (str)&lt;br /&gt;
  &amp;quot;Chomp leading and tailing whitespace from STR.&amp;quot;&lt;br /&gt;
  (while (string-match &amp;quot;\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'&amp;quot;&lt;br /&gt;
                       str)&lt;br /&gt;
    (setq str (replace-match &amp;quot;&amp;quot; t t str)))&lt;br /&gt;
  str)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Splitting strings ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
=== Joining strings ===&lt;br /&gt;
&lt;br /&gt;
Use `mapconcat' to join a list into a string using a separator (&amp;quot;glue&amp;quot;) between elements in the string.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(mapconcat 'identity '(&amp;quot;&amp;quot; &amp;quot;home&amp;quot; &amp;quot;alex &amp;quot; &amp;quot;elisp&amp;quot; &amp;quot;erc&amp;quot;) &amp;quot;/&amp;quot;)&lt;br /&gt;
==&amp;gt; &amp;quot;/home/alex /elisp/erc&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serialization ===&lt;br /&gt;
&lt;br /&gt;
The basic idea is to convert forms to strings with `prin1-to-string' and convert it back from a string with `read'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(length (read (prin1-to-string (make-list 1000000 '(x)))))&lt;br /&gt;
==&amp;gt; 1000000&lt;br /&gt;
&lt;br /&gt;
(read (prin1-to-string &amp;quot;Hello World!&amp;quot;))&lt;br /&gt;
==&amp;gt; &amp;quot;Hello World!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This only works in the simplest cases.  Unfortunately, this doesn't work for all Emacs data types for programming or the editor.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(read (prin1-to-string (make-hash-table))) ;; Error before Emacs 23.&lt;br /&gt;
==&amp;gt; #s(hash-table size 65 test eql rehash-size 1.5 [...] data ())&lt;br /&gt;
&lt;br /&gt;
(read (prin1-to-string (current-buffer)))&lt;br /&gt;
==&amp;gt; Lisp error: (invalid-read-syntax &amp;quot;#&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Formatting ===&lt;br /&gt;
&lt;br /&gt;
== Killing text ==&lt;br /&gt;
&lt;br /&gt;
As the Emacs Lisp Manual says, &amp;quot;Most of the kill commands are primarily for&lt;br /&gt;
interactive use [...]  When you need to delete text for internal&lt;br /&gt;
purposes within a Lisp function, you should normally use deletion&lt;br /&gt;
functions, so as not to disturb the kill ring contents.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The following mimic the `kill-' commands but without disturbing the kill ring.&lt;br /&gt;
&lt;br /&gt;
=== Delete region ===&lt;br /&gt;
&lt;br /&gt;
The Lisp equivalent of `kill-region' (`C-w') but without kill ring side effects::&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (region-beginning) (region-end))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                 &lt;br /&gt;
&lt;br /&gt;
According to the ElispManual, &amp;quot;Few programs need to use the&lt;br /&gt;
`region-beginning' and `region-end' functions.&amp;quot;  This is because&lt;br /&gt;
Lisp code should not rely on nor &amp;quot;alter the mark unless altering&lt;br /&gt;
the mark is part of the user-level functionality of the&lt;br /&gt;
command.  (And, in that case, this effect should be documented.)&lt;br /&gt;
To remember a location for internal use in the Lisp program,&lt;br /&gt;
store it in a Lisp variable.  For example: [...]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (point)))&lt;br /&gt;
  (forward-line 1)&lt;br /&gt;
  (delete-region beg (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delete line ===&lt;br /&gt;
&lt;br /&gt;
The equivalent of `kill-line' (`C-k') but without kill ring side effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (point)))&lt;br /&gt;
  (forward-line 1)&lt;br /&gt;
  (forward-char -1)&lt;br /&gt;
  (delete-region beg (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, replacing the `let' with `save-excursion'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (point)&lt;br /&gt;
               (save-excursion&lt;br /&gt;
                 (forward-line 1)&lt;br /&gt;
                 (forward-char -1)&lt;br /&gt;
                 (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                   &lt;br /&gt;
&lt;br /&gt;
Or simplest of all,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (point) (line-end-position))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
The examples with `forward-line' are shown because the paradigm is used later, see below.&lt;br /&gt;
&lt;br /&gt;
=== Delete line backwards ===&lt;br /&gt;
&lt;br /&gt;
The equivalent of killing the line backwards (`C-0 C-k') but without kill ring side effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (point)))&lt;br /&gt;
  (forward-line 0)&lt;br /&gt;
  (delete-region (point) beg))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Alternatively, replacing the `let' with `save-excursion'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (save-excursion&lt;br /&gt;
                 (forward-line 0)&lt;br /&gt;
                 (point))&lt;br /&gt;
               (point))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                 &lt;br /&gt;
&lt;br /&gt;
Or simplest of all,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (line-beginning-position) (point))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Delete line to next line  ===&lt;br /&gt;
&lt;br /&gt;
The equivalent of killing the line and the newline (`C-1 C-k') but without kill ring side effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (point)))&lt;br /&gt;
  (forward-line 1)&lt;br /&gt;
  (delete-region beg (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Alternatively, replacing the `let' with `save-excursion'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (point)&lt;br /&gt;
               (save-excursion&lt;br /&gt;
                 (forward-line 1)&lt;br /&gt;
                 (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                   &lt;br /&gt;
&lt;br /&gt;
=== Delete whole line ===&lt;br /&gt;
&lt;br /&gt;
The equivalent of `kill-whole-line' (`C-S-DEL') but without kill ring side effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (progn (forward-line 0)&lt;br /&gt;
                  (point))))&lt;br /&gt;
  (forward-line 1)&lt;br /&gt;
  (delete-region beg (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Alternatively, replacing the `let' with `save-excursion'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (save-excursion&lt;br /&gt;
                 (forward-line 0)&lt;br /&gt;
                 (point))&lt;br /&gt;
               (save-excursion&lt;br /&gt;
                 (forward-line 1)&lt;br /&gt;
                 (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                   &lt;br /&gt;
&lt;br /&gt;
Or simplest of all,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (line-beginning-position) (line-end-position))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
=== Delete word ===&lt;br /&gt;
&lt;br /&gt;
The equivalent of `kill-word' (`M-d') but without kill ring side effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (point)))&lt;br /&gt;
  (forward-word 1)&lt;br /&gt;
  (delete-region beg (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Alternatively, replacing the `let' with `save-excursion'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(delete-region (point)&lt;br /&gt;
               (save-excursion&lt;br /&gt;
                 (forward-word 1)&lt;br /&gt;
                 (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                   &lt;br /&gt;
&lt;br /&gt;
=== Delete sentence ===&lt;br /&gt;
&lt;br /&gt;
The equivalent of `kill-sentence' (`M-k') but without kill ring side effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(let ((beg (point)))&lt;br /&gt;
  (forward-sentence 1)&lt;br /&gt;
  (delete-region beg (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
Alternatively, replacing the `let' with `save-excursion'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (delete-region (point)&lt;br /&gt;
                 (save-excursion&lt;br /&gt;
                   (forward-sentence 1)&lt;br /&gt;
                   (point)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
                   &lt;br /&gt;
== Numbers ==&lt;br /&gt;
&lt;br /&gt;
=== String a number? ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(defun string-integer-p (string)&lt;br /&gt;
  (if (string-match &amp;quot;\\`[-+]?[0-9]+\\'&amp;quot; string)&lt;br /&gt;
      t&lt;br /&gt;
    nil))&lt;br /&gt;
&lt;br /&gt;
(string-integer-p &amp;quot;1234&amp;quot;)&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(string-integer-p &amp;quot;x1234&amp;quot;)&lt;br /&gt;
==&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
(string-integer-p &amp;quot;3.141592653589793&amp;quot;)&lt;br /&gt;
==&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
(defun string-float-p (string)&lt;br /&gt;
  (if (string-match &amp;quot;\\`[-+]?[0-9]+\\.[0-9]*\\'&amp;quot; string)&lt;br /&gt;
      t&lt;br /&gt;
    nil))&lt;br /&gt;
&lt;br /&gt;
(string-float-p &amp;quot;1234&amp;quot;)&lt;br /&gt;
==&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
(string-float-p &amp;quot;3.141592653589793&amp;quot;)&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&lt;br /&gt;
(string-float-p &amp;quot;.1&amp;quot;)&lt;br /&gt;
==&amp;gt; nil&lt;br /&gt;
&lt;br /&gt;
(string-float-p &amp;quot;1.&amp;quot;)&lt;br /&gt;
==&amp;gt; t&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;   &lt;br /&gt;
&lt;br /&gt;
=== String to number ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(defun decimal-number (string)&lt;br /&gt;
  (let ((n (string-to-number string)))&lt;br /&gt;
    (if (and (zerop n)&lt;br /&gt;
             (not (string-match &amp;quot;\\`\\s-*0+\\.?0*\\s-*\\'&amp;quot; string)))&lt;br /&gt;
        nil&lt;br /&gt;
      n)))&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot;536870911&amp;quot;)&lt;br /&gt;
==&amp;gt; 536870911&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot;536870912&amp;quot;)&lt;br /&gt;
==&amp;gt; 536870912.0&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot;3.141592653589793&amp;quot;)&lt;br /&gt;
==&amp;gt; 3.141592653589793&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot;042&amp;quot;)&lt;br /&gt;
==&amp;gt; 42&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot; 0 &amp;quot;)&lt;br /&gt;
==&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot;000&amp;quot;)&lt;br /&gt;
==&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
(decimal-number &amp;quot;0.0&amp;quot;)&lt;br /&gt;
==&amp;gt; 0.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Random numbers ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (random 2)  ;coin toss (0 or 1)&lt;br /&gt;
  (+ (random 6) 1)  ;dice&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
=== Put commas in numbers ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (defun group-number (num &amp;amp;optional size char)&lt;br /&gt;
    &amp;quot;Format NUM as string grouped to SIZE with CHAR.&amp;quot;&lt;br /&gt;
    ;; Based on code for `math-group-float' in calc-ext.el&lt;br /&gt;
    (let* ((size (or size 3))&lt;br /&gt;
           (char (or char &amp;quot;,&amp;quot;))&lt;br /&gt;
           (str (if (stringp num)&lt;br /&gt;
                    num&lt;br /&gt;
                  (number-to-string num)))&lt;br /&gt;
           (pt (or (string-match &amp;quot;[^0-9a-zA-Z]&amp;quot; str) (length str))))&lt;br /&gt;
      (while (&amp;gt; pt size)&lt;br /&gt;
        (setq str (concat (substring str 0 (- pt size))&lt;br /&gt;
                          char&lt;br /&gt;
                          (substring str (- pt size)))&lt;br /&gt;
              pt (- pt size)))&lt;br /&gt;
      str))&lt;br /&gt;
&lt;br /&gt;
  (group-number 299792458)&lt;br /&gt;
  ==&amp;gt; &amp;quot;299,792,458&amp;quot;&lt;br /&gt;
  (group-number &amp;quot;149597870691&amp;quot; 4 &amp;quot; &amp;quot;)&lt;br /&gt;
  ==&amp;gt; &amp;quot;1495 9787 0691&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
=== Incrementing numbers ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
== Dates and times ==&lt;br /&gt;
&lt;br /&gt;
=== Get today's date ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
=== Formatting dates ===&lt;br /&gt;
&lt;br /&gt;
Use the function `format-time-string' which is a build in function in both Emacsen and works like `strftime':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    ;; Year-Month-Day:&lt;br /&gt;
    (insert (format-time-string &amp;quot;%Y-%m-%d&amp;quot;))&lt;br /&gt;
    ;; Hour:Minutes:Seconds&lt;br /&gt;
    (insert (format-time-string &amp;quot;%H-%M-%S&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
=== Conversions ===&lt;br /&gt;
&lt;br /&gt;
Read a date from a string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((time (date-to-time &amp;quot;Tue, 27-Sep-83 12:35:59 EST&amp;quot;)))&lt;br /&gt;
    (set-time-zone-rule t) ;; Use Universal time.&lt;br /&gt;
    (prog1 (format-time-string &amp;quot;%Y-%m-%d %T UTC&amp;quot; time)&lt;br /&gt;
      (set-time-zone-rule nil))) ;; Reset to default time zone.&lt;br /&gt;
  ==&amp;gt; &amp;quot;1983-09-27 17:35:59 UTC&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Decode a time object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (decode-time (date-to-time &amp;quot;Tue, 27-Sep-83 12:35:59 EST&amp;quot;))&lt;br /&gt;
  ==&amp;gt; (59 35 13 27 9 1983 2 t -14400)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Get the seconds from the unix epoch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((time (date-to-time &amp;quot;13 Feb 2009 23:31:30 UTC&amp;quot;)))&lt;br /&gt;
    (float-time time))&lt;br /&gt;
  ==&amp;gt; 1234585890.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Find the date for seconds from the unix epoch.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (format-time-string &amp;quot;%Y-%m-%d %T UTC&amp;quot; (seconds-to-time 1234585890))&lt;br /&gt;
  ==&amp;gt; &amp;quot;2009-02-13 23:31:30 UTC&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Find the date 30 seconds in the future.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (format-time-string &amp;quot;%Y-%m-%d %T UTC&amp;quot; (time-add (current-time)&lt;br /&gt;
                                                  (seconds-to-time 30)))&lt;br /&gt;
  ==&amp;gt; &amp;quot;2012-02-13 10:07:11 UTC&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Formatting elapsed time in years, days, hours, minutes and seconds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (format-seconds &amp;quot;%Y %D %h:%m:%s&amp;quot; (1- (* 367 24 3600)))&lt;br /&gt;
  ==&amp;gt; &amp;quot;1 year 1 day 23:59:59&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Find the days between two dates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((days1 (time-to-days (date-to-time &amp;quot;Tue, 27-Sep-83 12:35:59 EST&amp;quot;)))&lt;br /&gt;
        (days2 (time-to-days (date-to-time &amp;quot;2009-02-13 23:31:30 UTC&amp;quot;))))&lt;br /&gt;
    (- days2 days1))&lt;br /&gt;
  ==&amp;gt; 9271&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Getting the day in the year.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (time-to-day-in-year (current-time))&lt;br /&gt;
  ==&amp;gt; 44&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Build a date based on the day of the year.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (format-time-string &amp;quot;%j&amp;quot;&lt;br /&gt;
                      (encode-time 0 0 0 44 1 2012))&lt;br /&gt;
  ==&amp;gt; &amp;quot;044&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
=== Timers ===&lt;br /&gt;
&lt;br /&gt;
TODO&lt;br /&gt;
&lt;br /&gt;
== Pattern matching ==&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Patterns&amp;quot; refers to RegularExpression&amp;quot;&amp;quot;s.&lt;br /&gt;
&lt;br /&gt;
There's a set of functions that work in strings, and a set that work in buffers.&lt;br /&gt;
&lt;br /&gt;
=== Finding ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (string-match &amp;quot;foo*&amp;quot; &amp;quot;Fight foo for food!&amp;quot;)&lt;br /&gt;
    ==&amp;gt; 6&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Buffers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (with-temp-buffer&lt;br /&gt;
      (insert &amp;quot;Fight foo for food!&amp;quot;)&lt;br /&gt;
      (goto-char (point-min))&lt;br /&gt;
      (re-search-forward &amp;quot;foo*&amp;quot;)&lt;br /&gt;
      (point))&lt;br /&gt;
    ==&amp;gt; 10&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Alternative without regular expressions: `search-forward'.&lt;br /&gt;
&lt;br /&gt;
Note that the functions working on buffers move point to the end of the occurrence found and return it.&lt;br /&gt;
That's why the result is 10 instead of 6!&lt;br /&gt;
&lt;br /&gt;
=== Comments ===&lt;br /&gt;
&lt;br /&gt;
Move to the beginning of the current comment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (require 'newcomment)&lt;br /&gt;
    (comment-beginning)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Move to the text after a comment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (comment-search-forward (line-end-position) t)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
See also EndOfLineNoComments.&lt;br /&gt;
&lt;br /&gt;
=== Search and replace ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (replace-regexp-in-string &amp;quot;foo*&amp;quot; &amp;quot;fu&amp;quot; &amp;quot;Fight foo for food!&amp;quot;)&lt;br /&gt;
    ==&amp;gt; &amp;quot;Fight fu fur fud!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Buffers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (with-temp-buffer&lt;br /&gt;
       (insert &amp;quot;Fight foo for food!&amp;quot;)&lt;br /&gt;
       (goto-char (point-min))&lt;br /&gt;
       (while (re-search-forward &amp;quot;foo*&amp;quot; nil t)&lt;br /&gt;
         (replace-match &amp;quot;fu&amp;quot;))&lt;br /&gt;
       (buffer-string))&lt;br /&gt;
    ==&amp;gt; &amp;quot;Fight fu fur fud!&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Alternative without regular expressions: `search-forward'.&lt;br /&gt;
&lt;br /&gt;
See also StringSearchAndReplace.&lt;br /&gt;
&lt;br /&gt;
=== Verifying ===&lt;br /&gt;
&lt;br /&gt;
Sometimes you just want to check whether you're at the right place:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (with-temp-buffer&lt;br /&gt;
      (insert &amp;quot;Fight foo for food!&amp;quot;)&lt;br /&gt;
      (goto-char (point-min))&lt;br /&gt;
      (looking-at &amp;quot;fight&amp;quot;))&lt;br /&gt;
    ==&amp;gt; t&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
== Sequences ==&lt;br /&gt;
&lt;br /&gt;
Datatypes used to represent sequences of things:&lt;br /&gt;
&lt;br /&gt;
     _____________________________________________&lt;br /&gt;
    |                                             |&lt;br /&gt;
    |          Sequence                           |&lt;br /&gt;
    |  ______   ________________________________  |&lt;br /&gt;
    | |      | |                                | |&lt;br /&gt;
    | | List | |             Array              | |&lt;br /&gt;
    | |      | |    ________       ________     | |&lt;br /&gt;
    | |______| |   |        |     |        |    | |&lt;br /&gt;
    |          |   | Vector |     | String |    | |&lt;br /&gt;
    |          |   |________|     |________|    | |&lt;br /&gt;
    |          |  ____________   _____________  | |&lt;br /&gt;
    |          | |            | |             | | |&lt;br /&gt;
    |          | | Char-table | | Bool-vector | | |&lt;br /&gt;
    |          | |____________| |_____________| | |&lt;br /&gt;
    |          |________________________________| |&lt;br /&gt;
    |_____________________________________________|&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Lists ===&lt;br /&gt;
&lt;br /&gt;
List basics are explained on ListStructure.&lt;br /&gt;
Lists can shrink and grow, but access to elements towards the end of the list is slow if the list is long.&lt;br /&gt;
&lt;br /&gt;
Use `cons' to append a new element to the front of a list.&lt;br /&gt;
Use `nth' to access an element of the list.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let ((words '(&amp;quot;fight&amp;quot; &amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;)))&lt;br /&gt;
      (when (string= &amp;quot;foo&amp;quot; (nth 1 words))&lt;br /&gt;
        (setq words (cons &amp;quot;bar&amp;quot; words)))&lt;br /&gt;
      words)&lt;br /&gt;
    ==&amp;gt; (&amp;quot;bar&amp;quot; &amp;quot;fight&amp;quot; &amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
See ListModification for more ways of changing a list.&lt;br /&gt;
&lt;br /&gt;
Iteration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let ((result))&lt;br /&gt;
      (dolist (word '(&amp;quot;fight&amp;quot; &amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;))&lt;br /&gt;
        (when (string-match &amp;quot;o&amp;quot; word)&lt;br /&gt;
          (setq result (cons word result))))&lt;br /&gt;
      (nreverse result))&lt;br /&gt;
    ==&amp;gt; (&amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Note how `cons' adds an element to the front of the list,&lt;br /&gt;
so that usually the list has to be reversed after the loop.&lt;br /&gt;
`nreverse' is particularly efficient because it does this&lt;br /&gt;
destructively by swiveling pointers around. See&lt;br /&gt;
DestructiveOperations for more about this.&lt;br /&gt;
&lt;br /&gt;
Copying:&lt;br /&gt;
&lt;br /&gt;
Use `copy-sequence' to make a copy of a list that won't change the&lt;br /&gt;
elements of the original.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let* ((orig '((1 2) (3 4)))&lt;br /&gt;
           (copy (copy-sequence orig)))&lt;br /&gt;
      (setcdr copy '((5 6)))&lt;br /&gt;
      (list orig copy))&lt;br /&gt;
    ==&amp;gt; (((1 2) (3 4)) ((1 2) (5 6)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
However, the elements in the copy are still from the original.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let* ((orig '((1 2) (3 4)))&lt;br /&gt;
           (copy (copy-sequence orig)))&lt;br /&gt;
      (setcdr (cadr copy) '(0))&lt;br /&gt;
      (list orig copy))&lt;br /&gt;
    ==&amp;gt; (((1 2) (3 0)) ((1 2) (3 0)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
The function `copy-tree' is the recursive version of `copy-sequence'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let* ((orig '((1 2) (3 4)))&lt;br /&gt;
           (copy (copy-tree orig)))&lt;br /&gt;
      (setcdr (cadr copy) '(0))&lt;br /&gt;
      (list orig copy))&lt;br /&gt;
    ==&amp;gt; (((1 2) (3 4)) ((1 2) (3 0)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Filtering:&lt;br /&gt;
&lt;br /&gt;
Emacs Lisp doesn't come with a `filter' function to keep elements that satisfy a conditional and excise the elements that do not satisfy it.  One can use `mapcar' to iterate over a list with a conditional, and then use `delq' to remove the `nil' values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (defun my-filter (condp lst)&lt;br /&gt;
    (delq nil&lt;br /&gt;
          (mapcar (lambda (x) (and (funcall condp x) x)) lst)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;          &lt;br /&gt;
&lt;br /&gt;
Therefore,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (my-filter 'identity my-list)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
is equivalent to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (delq nil my-list)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((num-list '(1 'a 2 &amp;quot;nil&amp;quot; 3 nil 4)))&lt;br /&gt;
    (my-filter 'numberp num-list))&lt;br /&gt;
  ==&amp;gt; (1 2 3 4)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Actually the package cl-seq contains the functions `remove-if' and `remove-if-not'.  The latter can be used instead of `my-filter'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((num-list '(1 'a 2 &amp;quot;nil&amp;quot; 3 nil 4)))&lt;br /&gt;
    (remove-if-not 'numberp num-list))&lt;br /&gt;
  ==&amp;gt; (1 2 3 4)&lt;br /&gt;
&lt;br /&gt;
  (let ((num-list '(1 'a 2 &amp;quot;nil&amp;quot; 3 nil 4)))&lt;br /&gt;
    (remove-if 'numberp num-list))&lt;br /&gt;
  ==&amp;gt; ((quote a) &amp;quot;nil&amp;quot; nil)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
As an example here is the quick sort algorithm:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (defun quicksort (lst)&lt;br /&gt;
    &amp;quot;Implement the quicksort algorithm.&amp;quot;&lt;br /&gt;
    (if (null lst) nil&lt;br /&gt;
      (let* ((spl (car lst))&lt;br /&gt;
             (rst (cdr lst))&lt;br /&gt;
             (smalp (lambda (x)&lt;br /&gt;
                   (&amp;lt; x spl))))&lt;br /&gt;
        (append (quicksort (remove-if-not smalp rst))&lt;br /&gt;
                (list spl)&lt;br /&gt;
                (quicksort (remove-if smalp rst))))))&lt;br /&gt;
&lt;br /&gt;
  (quicksort '(5 7 1 3 -9 8 7 -4 0))&lt;br /&gt;
  ==&amp;gt; (-9 -4 0 1 3 5 7 7 8)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Tranposing:&lt;br /&gt;
&lt;br /&gt;
Convert multiple lists into a list &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
 ((lambda (&amp;amp;rest args)&lt;br /&gt;
    (mapcar (lambda (n)&lt;br /&gt;
              (delq nil (mapcar (lambda (arg) (nth n arg)) args)))&lt;br /&gt;
            (number-sequence 0 (1- (apply 'max (mapcar 'length args))))))&lt;br /&gt;
  '(1 2 3) '(a b c) '(A B C))&lt;br /&gt;
  ==&amp;gt; ((1 a A) (2 b B) (3 c C))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
A more concise version is possible with the the higher-arity version of mapcar available with the `cl' library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  ((lambda (&amp;amp;rest args)&lt;br /&gt;
     (apply (function mapcar*) (function list) args))&lt;br /&gt;
   '(1 2 3) '(a b c) '(A B C))&lt;br /&gt;
  ==&amp;gt; ((1 a A) (2 b B) (3 c C))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Searching:&lt;br /&gt;
&lt;br /&gt;
Simply checking for existence of a value in a list can be done with&lt;br /&gt;
`member' or `memq'.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((words '(&amp;quot;fight&amp;quot; &amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;)))&lt;br /&gt;
    (car (member &amp;quot;for&amp;quot; words)))&lt;br /&gt;
  ==&amp;gt; &amp;quot;for&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  (let ((re &amp;quot;\\wo\\b&amp;quot;)&lt;br /&gt;
        (words '(&amp;quot;fight&amp;quot; &amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;)))&lt;br /&gt;
    (consp (memq t&lt;br /&gt;
             (mapcar (lambda (s) (numberp (string-match re s))) words))))&lt;br /&gt;
  ==&amp;gt; t&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In the latter, a more efficient algorithm would use a loop (a non-local exit).&lt;br /&gt;
&lt;br /&gt;
=== Association lists ===&lt;br /&gt;
&lt;br /&gt;
The ElispManual has examples of finding and deleting values in an&lt;br /&gt;
association list.  Here are cases when the car values are strings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (assoc &amp;quot;2&amp;quot; '((&amp;quot;2&amp;quot; . 2) (&amp;quot;1&amp;quot; . 1) (&amp;quot;2&amp;quot;) (&amp;quot;3&amp;quot; . 3)))&lt;br /&gt;
  ==&amp;gt; (&amp;quot;2&amp;quot; . 2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Deleting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((alist '((&amp;quot;a&amp;quot; . 1) (&amp;quot;b&amp;quot; . 2))))&lt;br /&gt;
    (delq (assoc &amp;quot;a&amp;quot; alist) alist))&lt;br /&gt;
  ==&amp;gt; ((&amp;quot;b&amp;quot; . 2))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Matches with a test function other than `equal':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (let ((alist '((&amp;quot;ab&amp;quot; . 1) (&amp;quot;bc&amp;quot; . 2) (&amp;quot;cd&amp;quot; . 3))))&lt;br /&gt;
    (assoc-default &amp;quot;c&amp;quot; alist (lambda (x y) (string-match y x))))&lt;br /&gt;
  ==&amp;gt; 2&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
=== Vectors ===&lt;br /&gt;
&lt;br /&gt;
Vectors are fixed in size but elements can be accessed in constant time.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let ((words [&amp;quot;fight&amp;quot; &amp;quot;foo&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;]))&lt;br /&gt;
      (when (string= &amp;quot;foo&amp;quot; (aref words 1))&lt;br /&gt;
        (aset words 1 &amp;quot;bar&amp;quot;))&lt;br /&gt;
      words)&lt;br /&gt;
    ==&amp;gt; [&amp;quot;fight&amp;quot; &amp;quot;bar&amp;quot; &amp;quot;for&amp;quot; &amp;quot;food!&amp;quot;]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
== Hashes ==&lt;br /&gt;
&lt;br /&gt;
Hashes map keys to values. In a way they are similar to alists, except&lt;br /&gt;
they are more efficient for a large number of keys.&lt;br /&gt;
&lt;br /&gt;
More info is available on the HashMap page.&lt;br /&gt;
&lt;br /&gt;
=== Storing and retrieving keys and values ===&lt;br /&gt;
&lt;br /&gt;
By default, hash tables use `eql' to compare keys. This is not appropriate&lt;br /&gt;
for strings: ##(eql &amp;quot;alex&amp;quot; &amp;quot;alex&amp;quot;)## ==&amp;gt; nil. Thus, use `equal' in these cases:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let ((nick-table (make-hash-table :test 'equal)))&lt;br /&gt;
      (puthash &amp;quot;kensanata&amp;quot; &amp;quot;Alex Schroeder&amp;quot; nick-table)&lt;br /&gt;
      (gethash &amp;quot;kensanata&amp;quot; nick-table))&lt;br /&gt;
    ==&amp;gt; &amp;quot;Alex Schroeder&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
Iterate:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let ((nick-table (make-hash-table :test 'equal))&lt;br /&gt;
          nicks)&lt;br /&gt;
      (puthash &amp;quot;kensanata&amp;quot; &amp;quot;Alex Schroeder&amp;quot; nick-table)&lt;br /&gt;
      (puthash &amp;quot;e1f&amp;quot; &amp;quot;Luis Fernandes&amp;quot; nick-table)&lt;br /&gt;
      (puthash &amp;quot;pjb&amp;quot; &amp;quot;Pascal J. Bourguignon&amp;quot; nick-table)&lt;br /&gt;
      (maphash (lambda (nick real-name)&lt;br /&gt;
                 (setq nicks (cons nick nicks)))&lt;br /&gt;
               nick-table)&lt;br /&gt;
      nicks)&lt;br /&gt;
      ==&amp;gt; (&amp;quot;pjb&amp;quot; &amp;quot;e1f&amp;quot; &amp;quot;kensanata&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;      &lt;br /&gt;
&lt;br /&gt;
=== Sorting keys  ===&lt;br /&gt;
&lt;br /&gt;
Use `maphash' to build up a list of keys, sort it, and then loop through&lt;br /&gt;
the list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (let ((nick-table (make-hash-table :test 'equal))&lt;br /&gt;
          nicks)&lt;br /&gt;
      (puthash &amp;quot;kensanata&amp;quot; &amp;quot;Alex Schroeder&amp;quot; nick-table)&lt;br /&gt;
      (puthash &amp;quot;e1f&amp;quot; &amp;quot;Luis Fernandes&amp;quot; nick-table)&lt;br /&gt;
      (puthash &amp;quot;pjb&amp;quot; &amp;quot;Pascal J. Bourguignon&amp;quot; nick-table)&lt;br /&gt;
      (maphash (lambda (nick real-name)&lt;br /&gt;
                 (setq nicks (cons nick nicks)))&lt;br /&gt;
               nick-table)&lt;br /&gt;
      (mapcar (lambda (nick)&lt;br /&gt;
                (concat nick &amp;quot; =&amp;gt; &amp;quot; (gethash nick nick-table)))&lt;br /&gt;
              (sort nicks 'string&amp;lt;)))&lt;br /&gt;
      ==&amp;gt; (&amp;quot;e1f =&amp;gt; Luis Fernandes&amp;quot;&lt;br /&gt;
           &amp;quot;kensanata =&amp;gt; Alex Schroeder&amp;quot;&lt;br /&gt;
           &amp;quot;pjb =&amp;gt; Pascal J. Bourguignon&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;           &lt;br /&gt;
&lt;br /&gt;
== Files ==&lt;br /&gt;
&lt;br /&gt;
=== Read ===&lt;br /&gt;
&lt;br /&gt;
Processing a file is usually done with a temporary buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
 (defun process-file (file)&lt;br /&gt;
   &amp;quot;Read the contents of a file into a temp buffer and then do&lt;br /&gt;
 something there.&amp;quot;&lt;br /&gt;
   (when (file-readable-p file)&lt;br /&gt;
     (with-temp-buffer&lt;br /&gt;
       (insert-file-contents file)&lt;br /&gt;
       (goto-char (point-min))&lt;br /&gt;
       (while (not (eobp))&lt;br /&gt;
       ;; do something here with buffer content&lt;br /&gt;
         (forward-line)))))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;         &lt;br /&gt;
&lt;br /&gt;
On the chance that a buffer may already be actively visiting the file,&lt;br /&gt;
consider using `find-file-noselect'&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (defun file-string (file)&lt;br /&gt;
    &amp;quot;Read the contents of a file and return as a string.&amp;quot;&lt;br /&gt;
    (with-current-buffer (find-file-noselect file)&lt;br /&gt;
      (buffer-string)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;      &lt;br /&gt;
&lt;br /&gt;
=== Write ===&lt;br /&gt;
&lt;br /&gt;
To write something to a file you can create a temporary buffer, insert the things to write there and write the buffer contents to a file.  The following example read a string and a filename (with completion, but doesn't need to exist, see InteractiveCodeChar F) and write the string to that file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
 (defun write-string-to-file (string file)&lt;br /&gt;
   (interactive &amp;quot;sEnter the string: \nFFile to save to: &amp;quot;)&lt;br /&gt;
   (with-temp-buffer&lt;br /&gt;
     (insert string)&lt;br /&gt;
     (when (file-writable-p file)&lt;br /&gt;
       (write-region (point-min)&lt;br /&gt;
                     (point-max)&lt;br /&gt;
                     file))))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                     &lt;br /&gt;
&lt;br /&gt;
=== Input and output (I/O) ===&lt;br /&gt;
&lt;br /&gt;
This is a nice and simple way to edit a file with Emacs Lisp,&lt;br /&gt;
especially when there's a chance the file might be already be visited&lt;br /&gt;
in Emacs and its ok to edit the existing buffer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (with-current-buffer (find-file-noselect &amp;quot;~/logfile&amp;quot;)&lt;br /&gt;
    (goto-char (point-max))&lt;br /&gt;
    (insert (format &amp;quot;Hash of last line: %s&amp;quot;&lt;br /&gt;
             (md5&lt;br /&gt;
              (save-excursion&lt;br /&gt;
                (forward-line -1)&lt;br /&gt;
                (buffer-substring-no-properties (point)&lt;br /&gt;
                                                (line-end-position))))))&lt;br /&gt;
    (newline)&lt;br /&gt;
    (with-temp-message &amp;quot;Writing file...&amp;quot;&lt;br /&gt;
      (save-buffer))&lt;br /&gt;
    (message &amp;quot;Writing file...done&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
=== Searching ===&lt;br /&gt;
&lt;br /&gt;
If you don't have grep, then you may need to write some Lisp which can find a match in a file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  ;; Visit file unless its already open.&lt;br /&gt;
  (with-current-buffer (find-file-noselect &amp;quot;~/.emacs&amp;quot;)&lt;br /&gt;
    (save-excursion ;; Don't change location of point.&lt;br /&gt;
      (goto-char (point-min)) ;; From the beginning...&lt;br /&gt;
      (if (re-search-forward &amp;quot;.*load-path.*&amp;quot; nil t 1)&lt;br /&gt;
          (match-string-no-properties 0)&lt;br /&gt;
        (error &amp;quot;Search failed&amp;quot;))))&lt;br /&gt;
  ==&amp;gt; &amp;quot;(add-to-list 'load-path \&amp;quot;/usr/share/emacs/site-lisp/\&amp;quot;)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
=== Filter ===&lt;br /&gt;
&lt;br /&gt;
=== Locking ===&lt;br /&gt;
&lt;br /&gt;
=== Stat ===&lt;br /&gt;
&lt;br /&gt;
An interface to the kernel's stat(2) is provided by the function file-attributes. The way times are represented may be a bit unexpected, though.&lt;br /&gt;
&lt;br /&gt;
=== Deleting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (if (file-exists-p filename)&lt;br /&gt;
      (delete-file filename))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;      &lt;br /&gt;
&lt;br /&gt;
=== Copy, move and rename ===&lt;br /&gt;
&lt;br /&gt;
== Directories ==&lt;br /&gt;
&lt;br /&gt;
=== Traversing ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
    (defun walk-path (dir action)&lt;br /&gt;
       &amp;quot;walk DIR executing ACTION with (dir file)&amp;quot;&lt;br /&gt;
       (cond ((file-directory-p dir)&lt;br /&gt;
              (or (char-equal ?/ (aref dir(1- (length dir))))&lt;br /&gt;
                  (setq dir (file-name-as-directory dir)))&lt;br /&gt;
              (let ((lst (directory-files dir nil nil t))&lt;br /&gt;
                     fullname file)&lt;br /&gt;
                (while lst&lt;br /&gt;
                  (setq file (car lst))&lt;br /&gt;
                  (setq lst (cdr lst))&lt;br /&gt;
                  (cond ((member file '(&amp;quot;.&amp;quot; &amp;quot;..&amp;quot;)))&lt;br /&gt;
                        (t&lt;br /&gt;
                         (and (funcall action dir file)&lt;br /&gt;
                              (setq fullname (concat dir file))&lt;br /&gt;
                              (file-directory-p fullname)&lt;br /&gt;
                              (walk-path fullname action)))))))&lt;br /&gt;
             (t&lt;br /&gt;
              (funcall action&lt;br /&gt;
                       (file-name-directory dir)&lt;br /&gt;
                       (file-name-nondirectory dir)))))&lt;br /&gt;
&lt;br /&gt;
    (defun walk-path-visitor (dir file)&lt;br /&gt;
       &amp;quot;Called by walk-path for each file found&amp;quot;&lt;br /&gt;
       (message (concat  dir file)))&lt;br /&gt;
&lt;br /&gt;
    (walk-path &amp;quot;~/&amp;quot; 'walk-path-visitor)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;    &lt;br /&gt;
&lt;br /&gt;
=== Path splitting ===&lt;br /&gt;
&lt;br /&gt;
Splitting the path can be done with `split-string' and with the slash. Previously, Emacs would determine the character separating directory names with `directory-sep-char'.  However, the variable is obselete with Emacs 21.1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(split-string default-directory &amp;quot;/&amp;quot;)&lt;br /&gt;
==&amp;gt; (&amp;quot;&amp;quot; &amp;quot;usr&amp;quot; &amp;quot;share&amp;quot; &amp;quot;emacs&amp;quot; &amp;quot;22.2&amp;quot; &amp;quot;lisp&amp;quot; &amp;quot;&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For splitting a path variable, Emacs already has the `parse-colon-path' function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(parse-colon-path (getenv &amp;quot;PATH&amp;quot;))&lt;br /&gt;
==&amp;gt; (&amp;quot;/usr/lib/qt-3.3/bin/&amp;quot; &amp;quot;/usr/kerberos/bin/&amp;quot; &amp;quot;/usr/local/bin/&amp;quot;&lt;br /&gt;
&amp;quot;/usr/bin/&amp;quot; &amp;quot;/bin/&amp;quot; &amp;quot;/usr/local/sbin/&amp;quot; &amp;quot;/usr/sbin/&amp;quot; &amp;quot;/sbin/&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Processes ==&lt;br /&gt;
&lt;br /&gt;
=== Running a program ===&lt;br /&gt;
&lt;br /&gt;
Run a command without caring about its output.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (async-shell-command &amp;quot;emacs&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Run a command and put its output in the current buffer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (shell-command &amp;quot;seq 8 12 | sort&amp;quot; t)&lt;br /&gt;
  10&lt;br /&gt;
  11&lt;br /&gt;
  12&lt;br /&gt;
  8&lt;br /&gt;
  9&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Run a command and put its output in a new buffer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (shell-command &amp;quot;seq 8 12 | sort&amp;quot;&lt;br /&gt;
                 (get-buffer-create &amp;quot;*Standard output*&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;                 &lt;br /&gt;
&lt;br /&gt;
Run a command return its output as a string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
  (shell-command-to-string &amp;quot;seq 8 12 | sort&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
XEmacs also comes with `exec-to-string'.&lt;br /&gt;
&lt;br /&gt;
=== Handling signals ===&lt;br /&gt;
&lt;br /&gt;
== Sockets ==&lt;br /&gt;
&lt;br /&gt;
=== Tcp client ===&lt;br /&gt;
&lt;br /&gt;
=== Tcp server ===&lt;br /&gt;
&lt;br /&gt;
Perhaps EmacsEchoServer and EmacsDaytimeServer can be useful here.&lt;br /&gt;
&lt;br /&gt;
== Keyboard events ==&lt;br /&gt;
&lt;br /&gt;
* Call function bound to key&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(funcall (key-binding (kbd &amp;quot;M-TAB&amp;quot;)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lisp&amp;quot;&amp;gt;&lt;br /&gt;
(call-interactively (key-binding (kbd &amp;quot;M-TAB&amp;quot;)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
[[Category:Customization]]&lt;br /&gt;
[[Category:Intermediate]]&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Main_Page&amp;diff=2630</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Main_Page&amp;diff=2630"/>
		<updated>2012-04-09T20:49:40Z</updated>

		<summary type="html">&lt;p&gt;Gregben: grammatical corrections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''WikEmacs''' (pronounced wiki-macs) collects useful resources for working with [[GNU Emacs]]. Think of it as a&lt;br /&gt;
'''next generation, better structured and improved [http://www.emacswiki.org/ Emacs Wiki]''' . &lt;br /&gt;
[[File:Emacs-explanation.png|320px|thumb|right|Basic terminology of typical Emacs GUI Frame]]&lt;br /&gt;
&lt;br /&gt;
---------&lt;br /&gt;
'''First time visitors''' can start [[#Explore WikEmacs | exploring WikEmacs]]. We have added lots of useful pages since the launch of WikEmacs. We want to keep you excited and engaged. &lt;br /&gt;
&lt;br /&gt;
-----------&lt;br /&gt;
We need more '''[[:Category:WikEmacs Contributor|WikEmacs Contributor]]s'''.  You can help the following way.&lt;br /&gt;
&lt;br /&gt;
{{Note| First of all, please take a minute to look at the&lt;br /&gt;
[[WikEmacs:Guidelines]] before you start editing.}}&lt;br /&gt;
&lt;br /&gt;
* Priority tasks&lt;br /&gt;
** Migrate content from [http://www.emacswiki.org EmacsWiki]. Please adopt the following approach -''I found this on EmacsWiki which was helpful. But it took me a lot of time to find it. Now that I have found it, I will put it in WikEmacs so that others can benefit from it.''&lt;br /&gt;
&lt;br /&gt;
* Intermediate tasks&lt;br /&gt;
** Provide tutorials or content for the [[:Category:Popular Package|Popular Packages]] or [[:Category:Native Package|Native Packages]].&lt;br /&gt;
** Add more content to [[Special:ShortPages]]&lt;br /&gt;
** Document or add more [[:Category:Third Party Package|Third Party Package]]s&lt;br /&gt;
&lt;br /&gt;
* Other tasks&lt;br /&gt;
** Copy edit [[Special:RecentChanges]] or be a moral police&lt;br /&gt;
** Add more members to various [[Special:Categories]]&lt;br /&gt;
** Categorize one of these pages [[Special:UncategorizedPages]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
'''Emacs News'''&lt;br /&gt;
&lt;br /&gt;
The latest stable release of Emacs is [[GNU Emacs 23|Emacs-23.4]].&lt;br /&gt;
The next major release is [[GNU Emacs 24|Emacs-24.1]] and is in ''Pretest'' stage.&lt;br /&gt;
&lt;br /&gt;
Emacs is available on all popular [[:Category:Install Or Upgrade| Operating Systems]] including [[Installing Emacs on GNU/Linux | GNU/Linux]], [[Installing Emacs on BSD |BSD]], [[Installing Emacs on OS X | OS X]] and [[Installing Emacs on Windows| Windows]].  It supports a variety of [[:Category:Programming languages|programming languages]].&lt;br /&gt;
&lt;br /&gt;
= Explore WikEmacs =&lt;br /&gt;
&lt;br /&gt;
To explore WikEmacs proceed as follows:&lt;br /&gt;
* Search for or visit a page of interest&lt;br /&gt;
* At the end of the page, there is a list of categories&lt;br /&gt;
* Click on individual categories and it will give you a list of all pages that will be of interest to you.&lt;br /&gt;
&lt;br /&gt;
==  What is your comfort level with Emacs? ==&lt;br /&gt;
* [[:Category:Beginner|Beginner]]&lt;br /&gt;
* [[:Category:Intermediate|Intermediate]]&lt;br /&gt;
* [[:Category:Expert|Expert]]&lt;br /&gt;
** Are you a maintainer of a [[:Category:Built-in Package|Built-in Package]]? If you don't find information about your package, please add it. No one else is better than your are to write about it.&lt;br /&gt;
** Have you developed any [[:Category:Third Party Package|Third Party Package]]s? Consider writing about what it is and how to use it.&lt;br /&gt;
* [[:Category:Vim User|Vim User]]&lt;br /&gt;
* [[:Category:User Level|Other]]&lt;br /&gt;
&lt;br /&gt;
== What do you want to accomplish now? ==&lt;br /&gt;
* [[:Category:Install Or Upgrade|Install Or Upgrade]]&lt;br /&gt;
* [[:Category:Customization|Customize Emacs]]&lt;br /&gt;
* [[Key Bindings|Tweak Key Bindings]]&lt;br /&gt;
* [[:Category:Tutorial|Learn more Emacs (Tutorials)]]&lt;br /&gt;
&lt;br /&gt;
== What do you use Emacs for? ==&lt;br /&gt;
* [[:Category:Text Editing|Text Editing]]&lt;br /&gt;
* [[:Category:Programming|Programming]]&lt;br /&gt;
* [[:Category:Document authoring|Document authoring]]&lt;br /&gt;
* [[:Category:Organizer|Getting Organized]]&lt;br /&gt;
* [[:Category:Email|Emailing]]&lt;br /&gt;
* [[:Category:Chat|Chatting]]&lt;br /&gt;
* [[:Category:Blogging|Blogging]]&lt;br /&gt;
* [[:Category:Browse|Browsing]] &lt;br /&gt;
* [[:Category:Workflow|Other]]&lt;br /&gt;
&lt;br /&gt;
== How do you involve yourself with the community? ==&lt;br /&gt;
* [[:Category:Emacs User]]&lt;br /&gt;
* [[:Category:Emacs Contributor]]&lt;br /&gt;
* [[:Category:WikEmacs Contributor]]&lt;br /&gt;
* [[:Category:User Role|Other]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:WikEmacs]]&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=Main_Page&amp;diff=570</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=Main_Page&amp;diff=570"/>
		<updated>2012-03-26T16:07:53Z</updated>

		<summary type="html">&lt;p&gt;Gregben: /* Getting started with Emacs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Welcome to WikEmacs - A Community Maintained Emacs Wiki'''&lt;br /&gt;
&lt;br /&gt;
== About == &lt;br /&gt;
&lt;br /&gt;
Useful resources for working with [http://www.gnu.org/software/emacs/emacs.html GNU Emacs], the extensible, self-documenting text editor.  See also [http://en.wikipedia.org/wiki/Emacs Emacs (Wikipedia)].&lt;br /&gt;
&lt;br /&gt;
Emacs is [https://en.wikipedia.org/wiki/Free_software free software (Wikipedia)].&lt;br /&gt;
&lt;br /&gt;
WikEmacs (pronounced wikimacs) is intended as a next generation alternative to the traditional [http://www.emacswiki.org/ EmacsWiki].&lt;br /&gt;
&lt;br /&gt;
See [[WikEmacs:Guidelines]] for information on editing this wiki.&lt;br /&gt;
&lt;br /&gt;
== Getting started with Emacs ==&lt;br /&gt;
&lt;br /&gt;
The latest stable release is [[:Category:Emacs-23.4|Emacs-23.4]].  The next major release is [[:Category:Emacs-24.1|Emacs-24.1]] and is in ''Pretest'' stage.&lt;br /&gt;
&lt;br /&gt;
Emacs is available on all popular [[:Category:Operating System | Operating Systems]] including [[GNU/Linux]], [[OSX]] and [[Windows]].  It supports variety of [[:Category:Programming languages|Programming languages]].&lt;br /&gt;
&lt;br /&gt;
Explore this Wiki based on your needs. Here are some starting points:&lt;br /&gt;
&lt;br /&gt;
; [[:Category:User Role|Pages organized by your role in Emacs community]]&lt;br /&gt;
: Whether you are a '''''Emacs User''''', a '''''Emacs Contributor''''' or a '''''Programmer''''', there are few things just for you.&lt;br /&gt;
&lt;br /&gt;
; [[:Category:Workflow|Pages organized by your current workflow]]&lt;br /&gt;
: Whether you want to '''''write mails''''', '''''browse the web''''', '''''blog''''', '''''read news feeds''''', '''''author documents''''' or for that matter '''''get organized''''', there are few things just for you.&lt;br /&gt;
&lt;br /&gt;
; [[:Category:User Level|Pages organized by your comfort level with Emacs]] &lt;br /&gt;
: Whether you are a '''''beginner''''', '''''intermediate user''''' or an '''''expert user''''', here are a few things just for you:&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
* [[Starter Kits]]&lt;br /&gt;
* [[Learning Resources]] and getting help&lt;br /&gt;
* [[Package Managers]]&lt;br /&gt;
* [[Key Bindings]]&lt;br /&gt;
* [[Look and Feel]]&lt;br /&gt;
* [[Emacs for Vim users]]&lt;br /&gt;
* [[Emacs Terminology]]&lt;br /&gt;
** [[Buffer]]&lt;br /&gt;
** [[Window]]&lt;br /&gt;
** [[Frame]]&lt;br /&gt;
** [[Point and mark]]&lt;br /&gt;
** [[Killing and yanking]]&lt;br /&gt;
** [[Region]]&lt;br /&gt;
** [[Fill]]&lt;br /&gt;
** Case-fold (compared with case sensitivity)&lt;br /&gt;
** Narrow and widen (compared with collapse and expand)&lt;br /&gt;
* Quitting Emacs: type `C-x C-c` (that's Control-X, Control-C)&lt;br /&gt;
&lt;br /&gt;
== Text editing in Emacs ==&lt;br /&gt;
&lt;br /&gt;
* [[ Search and replace ]]&lt;br /&gt;
** [[ Incremental Search ]]&lt;br /&gt;
** [[ Regexp Search ]]&lt;br /&gt;
* [[ Undo and redo ]]&lt;br /&gt;
* [[ Spell check ]]&lt;br /&gt;
* [[ International Users ]]&lt;br /&gt;
* [[ Remote Editing ]] via FTP, ssh, etc.&lt;br /&gt;
* [[ Emacs server ]] and [[ emacsclient ]]&lt;br /&gt;
* [[ Registers ]]&lt;br /&gt;
* [[ Bookmarks ]]&lt;br /&gt;
* [[ Rectangles ]]&lt;br /&gt;
&lt;br /&gt;
== Automation in Emacs ==&lt;br /&gt;
&lt;br /&gt;
* [[ Keyboard macros ]]&lt;br /&gt;
* [[ Emacs Lisp ]]&lt;br /&gt;
&lt;br /&gt;
== Configuring Emacs ==&lt;br /&gt;
&lt;br /&gt;
* [[ Custom ]] for choosing and setting options.&lt;br /&gt;
* Scripting your [[ init.el ]] file (formerly .emacs) using [[ Emacs Lisp ]].&lt;br /&gt;
&lt;br /&gt;
== Convenience ==&lt;br /&gt;
&lt;br /&gt;
* Completion and selection &lt;br /&gt;
** [[Ido]]: '''I'''nteractively '''do''' things&lt;br /&gt;
** [[Helm]]: incremental completion and selection (formerly [[Anything]])&lt;br /&gt;
** [[Icicles]]&lt;br /&gt;
** Abbrev and dabbrev&lt;br /&gt;
** Auto-complete and hippie-expand&lt;br /&gt;
** YaSnippet&lt;br /&gt;
&lt;br /&gt;
== Emacs and Desktop Integration ==&lt;br /&gt;
* [[ Dired ]]&lt;br /&gt;
** [[ Archive mode ]]&lt;br /&gt;
* [[ Battery ]]&lt;br /&gt;
* [[ Notifications ]]&lt;br /&gt;
&lt;br /&gt;
== Typesetting, Document Markup and Document Creation in Emacs ==&lt;br /&gt;
&lt;br /&gt;
* [[ Markdown ]]&lt;br /&gt;
* [[ Org]] export to HTML, PDF etc&lt;br /&gt;
* [[ SGML ]], [[ HTML ]] and [[ XML ]]&lt;br /&gt;
* [[TeX]], [[LaTeX]], [[TeXinfo]], [[BibTeX]] etc.&lt;br /&gt;
&lt;br /&gt;
== Emacs for Development ==&lt;br /&gt;
&lt;br /&gt;
You can use Emacs to program in variety of [[:Category:Programming languages|Programming languages]]. If you don't see an entry for your favorite language, please create an page for it and few words about it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Markup Languages ===&lt;br /&gt;
&lt;br /&gt;
* [[CSS]]&lt;br /&gt;
* [[HTML]]&lt;br /&gt;
* [[JSON]]&lt;br /&gt;
* [[Markdown]]&lt;br /&gt;
* [[SGML]]&lt;br /&gt;
* [[XML]]&lt;br /&gt;
&lt;br /&gt;
=== Compiling ===&lt;br /&gt;
&lt;br /&gt;
* [[ flymake ]]&lt;br /&gt;
&lt;br /&gt;
=== Debugging ===&lt;br /&gt;
&lt;br /&gt;
=== REPLs ===&lt;br /&gt;
&lt;br /&gt;
Interactive command-line environments for Lisp. ('''R'''ead-'''E'''val-'''P'''rint-'''L'''oop)&lt;br /&gt;
&lt;br /&gt;
* [[ Inferior Emacs Lisp Mode ]] (IELM), for interacting with Emacs' own internal Lisp&lt;br /&gt;
* [[mozrepl]], for interacting with an external web browser's internal JavaScript engine&lt;br /&gt;
* [[SLIME]], for interacting with an external Common Lisp or Clojure instance&lt;br /&gt;
&lt;br /&gt;
=== Emacs as an IDE ===&lt;br /&gt;
&lt;br /&gt;
Integrated Development Environment (IDE) for Emacs is called [http://cedet.sourceforge.net/ CEDET]. See [http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html Gentle Introduction to CEDET].&lt;br /&gt;
&lt;br /&gt;
For Literate Programming see [http://orgmode.org/worg/org-contrib/babel/ Org Babel].&lt;br /&gt;
&lt;br /&gt;
=== [[ Version Control ]] ===&lt;br /&gt;
&lt;br /&gt;
Emacs supports many [[Version Control]] systems out of the box and provides bindings and other shortcuts for a better workflow between Emacs and these systems.&lt;br /&gt;
&lt;br /&gt;
Within Emacs, [[ ediff ]] provides sophisticated diff and merge functions. Both [[vc]] and [[dvc]] integrate well with ediff.&lt;br /&gt;
&lt;br /&gt;
== Productivity ==&lt;br /&gt;
* [[ Org ]] Mode&lt;br /&gt;
* [[ calc ]]&lt;br /&gt;
* [[ calendar ]]&lt;br /&gt;
* [[ notification ]]&lt;br /&gt;
* [[ diary ]]&lt;br /&gt;
* Contacts: [[ bbdb ]]&lt;br /&gt;
&lt;br /&gt;
== Communication ==&lt;br /&gt;
&lt;br /&gt;
* [[ Blogging ]]&lt;br /&gt;
* [[ Chat ]]&lt;br /&gt;
* [[ Email ]]&lt;br /&gt;
* [[ Feed reading ]]&lt;br /&gt;
* [[ Microblogging ]]&lt;br /&gt;
* [[ Usenet news ]]&lt;br /&gt;
&lt;br /&gt;
== Web browsing and web development ==&lt;br /&gt;
&lt;br /&gt;
* [[w3]]: a pure-Emacs-Lisp text-mode web browser.&lt;br /&gt;
* [[w3m-el]]: The text-mode w3m web browser hosted and enhanced within Emacs, with rudimentary inline image support but no JavaScript.&lt;br /&gt;
* Launching and interacting with an [[external browser]] from emacs&lt;br /&gt;
* Using [[emacs as a browser's external editor]], either when entering text on web pages or when viewing a web page's source document or both.&lt;br /&gt;
&lt;br /&gt;
== Shells and terminal emulation ==&lt;br /&gt;
&lt;br /&gt;
Within Emacs you can interact with various shells and other command-line/text-mode programs running as a sub-process within an Emacs terminal emulator:&lt;br /&gt;
* [[ ansi-term ]]&lt;br /&gt;
* [[ shell ]]&lt;br /&gt;
* [[ term ]]&lt;br /&gt;
* [[ multi-term ]]&lt;br /&gt;
&lt;br /&gt;
[[ eshell ]] is a shell (not a terminal emulator, nor a process hosted in one) written in pure [[ Emacs Lisp ]]. It is very powerful, flexible and customizable, but poorly documented at time of writing.&lt;br /&gt;
&lt;br /&gt;
Emacs itself is fully functional either in a terminal or a windowing system. Some keystrokes available under window systems may not work in a terminal and vice versa.&lt;br /&gt;
&lt;br /&gt;
== Accessibility ==&lt;br /&gt;
&lt;br /&gt;
* [http://emacspeak.sourceforge.net/ Emacspeak] for the visually challenged.&lt;br /&gt;
&lt;br /&gt;
== Security and cryptography ==&lt;br /&gt;
&lt;br /&gt;
* [[ Gnu Privacy Guard ]] (GPG) support and integration&lt;br /&gt;
&lt;br /&gt;
== Getting Involved ==&lt;br /&gt;
* IRC Channel&lt;br /&gt;
&lt;br /&gt;
* [[ Mailing list archives ]]&lt;br /&gt;
&lt;br /&gt;
* [http://bzr.savannah.gnu.org/lh/emacs/trunk/files Browsable source repository]&lt;br /&gt;
&lt;br /&gt;
[[Contributing to Emacs]]&lt;br /&gt;
&lt;br /&gt;
== Niche Uses ==&lt;br /&gt;
&lt;br /&gt;
* [[ Media player ]]&lt;br /&gt;
* [[ Presentations ]]&lt;br /&gt;
* [[ Screencasts ]]&lt;br /&gt;
* [[ Statistics ]]&lt;br /&gt;
* [[ Binary files]]&lt;br /&gt;
* [[ Docview ]]&lt;br /&gt;
* [[ Pictures ]]&lt;br /&gt;
** [[ Inline Images ]]&lt;br /&gt;
** [[ Artist mode ]]&lt;br /&gt;
&lt;br /&gt;
== Games and Entertainment ==&lt;br /&gt;
* Tetris&lt;br /&gt;
* Doctor&lt;br /&gt;
&lt;br /&gt;
* Humor&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.gnu.org/gnu/rms-lisp.html My Lisp Experiences and the Development of GNU Emacs]&lt;br /&gt;
&lt;br /&gt;
* XEmacs and GNU Emacs&lt;br /&gt;
&lt;br /&gt;
== Popular Culture and Community ==&lt;br /&gt;
* Adding Emacs-style key bindings to other programs and operating systems.&lt;br /&gt;
* St Ignucius and the Church of Emacs&lt;br /&gt;
* Saving the world from &amp;lt;tt&amp;gt;vi&amp;lt;/tt&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
	<entry>
		<id>https://wikemacs.org/index.php?title=WikEmacs:Guidelines&amp;diff=565</id>
		<title>WikEmacs:Guidelines</title>
		<link rel="alternate" type="text/html" href="https://wikemacs.org/index.php?title=WikEmacs:Guidelines&amp;diff=565"/>
		<updated>2012-03-26T16:04:17Z</updated>

		<summary type="html">&lt;p&gt;Gregben: /* General */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Start with http://meta.wikimedia.org/wiki/Help:Wikitext_examples if you are new to MediaWiki markup.&lt;br /&gt;
&lt;br /&gt;
== General ==&lt;br /&gt;
&lt;br /&gt;
* Articles should be geared only towards the current and future versions of Emacs (currently 23 and 24) for maintainability's sake. Mentions of older Emacs versions should be as few as possible.&lt;br /&gt;
* Articles should not copy Emacs's or extension's official documentation - they should refer to it instead. An overview, some nice pointers, tips and links. &lt;br /&gt;
* Comments and questions should go to an article's discussion page. Always sign your comments with the &amp;lt;nowiki&amp;gt;~~~~&amp;lt;/nowiki&amp;gt; special syntax after them, otherwise the discussion will be hard to follow.&lt;br /&gt;
&lt;br /&gt;
== Templates ==&lt;br /&gt;
&lt;br /&gt;
There are templates defined for referencing ''variables'', ''function'', ''command'', ''keys'', ''manual'' etc.  Use them for uniform experience.  See [http://wikemacs.org/wiki/index.php?title=Special%3AAllPages&amp;amp;from=&amp;amp;to=&amp;amp;namespace=10 Templates]. [[Template:Keys]]&lt;br /&gt;
&lt;br /&gt;
== Categories ==&lt;br /&gt;
&lt;br /&gt;
There are special categories defined for ''Operating system'', ''Emacs releases'', ''Programming languages'' etc. Use these when possible or introduce new ones as required. See [[Special:Categories]].&lt;/div&gt;</summary>
		<author><name>Gregben</name></author>
	</entry>
</feed>