=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2013-03-18 19:44:15 +0000
+++ lisp/ChangeLog	2013-03-18 20:37:01 +0000
@@ -1,3 +1,5 @@
+2013-03-18  Aaron S. Hawley  <aaron.s.hawley@gmail.com>
+
+        * emacs-lisp/lisp.el (forward-sexp): Signal an error when end of
+        buffer or beginning of buffer reached.
+
@@ -1974,7 +1979,7 @@
 	(js--multi-line-declaration-indentation): New function.
 	(js--proper-indentation): Use it.
 
-2013-01-11  Aaron S. Hawley  <Aaron.Hawley@vtinfo.com>
+2013-01-11  Aaron S. Hawley  <aaron.s.hawley@gmail.com>
 
 	* calc/calc.el (calc-highlight-selections-with-faces)
 	 (calc-dispatch):

=== modified file 'lisp/emacs-lisp/lisp.el'
--- lisp/emacs-lisp/lisp.el	2013-01-01 09:11:05 +0000
+++ lisp/emacs-lisp/lisp.el	2013-03-18 19:38:50 +0000
@@ -58,6 +58,10 @@
   (or arg (setq arg 1))
   (if forward-sexp-function
       (funcall forward-sexp-function arg)
+    (when (and (> arg 0) (eobp))
+      (signal 'end-of-buffer nil))
+    (when (and (< arg 0) (bobp))
+      (signal 'beginning-of-buffer nil))
     (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
     (if (< arg 0) (backward-prefix-chars))))
 

=== added file 'test/automated/sexp-tests.el'
--- test/automated/sexp-tests.el	1970-01-01 00:00:00 +0000
+++ test/automated/sexp-tests.el	2013-03-18 21:51:52 +0000
@@ -0,0 +1,98 @@
+;;; sexp-tests.el --- Test S-expression support in Emacs
+
+;; Copyright (C) 2013  Aaron S. Hawley
+
+;; Author: Aaron S. Hawley <aaron.s.hawley@gmail.com>
+;; Keywords: internal
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Testing of `forward-sexp'.
+
+;;; Code:
+
+(require 'ert)
+
+(ert-deftest sexp-forward-1 ()
+  "Test basics of \\[forward-sexp]."
+  (with-temp-buffer
+    (insert "()")
+    (goto-char (point-min))
+    (should (null
+             (forward-sexp 1)))))
+
+(ert-deftest sexp-backward-1 ()
+  "Test basics of \\[backward-sexp]."
+  (with-temp-buffer
+    (insert "()")
+    (should (null
+             (forward-sexp -1)))))
+
+(ert-deftest sexp-forward-1-error-eobp ()
+  "Test error when \\[forward-sexp] at `eobp'."
+  (with-temp-buffer
+    (insert "()")
+    (should-error
+     (forward-sexp 1))))
+
+(ert-deftest sexp-backward-1-error-eobp ()
+  "Test error when \\[backward-sexp] at `bobp'."
+  (with-temp-buffer
+    (insert "()")
+    (goto-char (point-min))
+    (should-error
+     (forward-sexp -1))))
+
+(ert-deftest sexp-forward-2-eobp-no-error ()
+  "Test lack of error when \\[forward-sexp] beyond `eobp'."
+  (with-temp-buffer
+    (insert "()")
+    (goto-char (point-min))
+    (should (null
+     (forward-sexp 2)))
+    (should (eobp))))
+
+(ert-deftest sexp-backward-2-bobp-no-error ()
+  "Test lack of error when \\[backward-sexp] beyond `bobp'."
+  (with-temp-buffer
+    (insert "()")
+    (should (null
+     (forward-sexp -2)))
+    (should (bobp))))
+
+(ert-deftest sexp-forward-2-eobp-subsequent-error ()
+  "Test error when \\[forward-sexp] when started from `eobp'."
+  (with-temp-buffer
+    (insert "()")
+    (goto-char (point-min))
+    (should (null
+     (forward-sexp 2)))
+    (should (eobp))
+    (should-error
+     (forward-sexp 1))))
+
+(ert-deftest sexp-backward-2-bobp-subsequent-error ()
+  "Test error when \\[backward-sexp] when started from `bobp'."
+  (with-temp-buffer
+    (insert "()")
+    (should (null
+     (forward-sexp -2)))
+    (should (bobp))
+    (should-error
+     (forward-sexp -1))))
+
+(provide 'sexp-tests)
+;;; sexp-tests.el ends here

