From: Juanma Barranquero Date: Sun, 5 Feb 2012 02:09:35 +0000 (+0100) Subject: lisp/emacs-lisp/pp.el: Do not reimplement common macros; use `looking-at-p'. X-Git-Tag: emacs-pretest-24.0.94~316 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0696d25514565119ee268fa8d9c10b2b5a561b4f;p=emacs.git lisp/emacs-lisp/pp.el: Do not reimplement common macros; use `looking-at-p'. (pp-to-string): Use `with-temp-buffer'. (pp-buffer): Use `ignore-errors', `looking-at-p'. (pp-last-sexp): Use `looking-at-p'. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 198b7c53322..8db7b4b1b89 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2012-02-05 Juanma Barranquero + + * emacs-lisp/pp.el (pp-to-string): Use `with-temp-buffer'. + (pp-buffer): Use `ignore-errors', `looking-at-p'. + (pp-last-sexp): Use `looking-at-p'. + 2012-02-04 Glenn Morris * files.el (revert-buffer): diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el index c795d985b7e..48e0d6d6a21 100644 --- a/lisp/emacs-lisp/pp.el +++ b/lisp/emacs-lisp/pp.el @@ -41,17 +41,14 @@ "Return a string containing the pretty-printed representation of OBJECT. OBJECT can be any Lisp object. Quoting characters are used as needed to make output that `read' can handle, whenever this is possible." - (with-current-buffer (generate-new-buffer " pp-to-string") - (unwind-protect - (progn - (lisp-mode-variables nil) - (set-syntax-table emacs-lisp-mode-syntax-table) - (let ((print-escape-newlines pp-escape-newlines) - (print-quoted t)) - (prin1 object (current-buffer))) - (pp-buffer) - (buffer-string)) - (kill-buffer (current-buffer))))) + (with-temp-buffer + (lisp-mode-variables nil) + (set-syntax-table emacs-lisp-mode-syntax-table) + (let ((print-escape-newlines pp-escape-newlines) + (print-quoted t)) + (prin1 object (current-buffer))) + (pp-buffer) + (buffer-string))) ;;;###autoload (defun pp-buffer () @@ -60,9 +57,7 @@ to make output that `read' can handle, whenever this is possible." (while (not (eobp)) ;; (message "%06d" (- (point-max) (point))) (cond - ((condition-case err-var - (prog1 t (down-list 1)) - (error nil)) + ((ignore-errors (down-list 1) t) (save-excursion (backward-char 1) (skip-chars-backward "'`#^") @@ -71,10 +66,8 @@ to make output that `read' can handle, whenever this is possible." (point) (progn (skip-chars-backward " \t\n") (point))) (insert "\n")))) - ((condition-case err-var - (prog1 t (up-list 1)) - (error nil)) - (while (looking-at "\\s)") + ((ignore-errors (up-list 1) t) + (while (looking-at-p "\\s)") (forward-char 1)) (delete-region (point) @@ -154,7 +147,7 @@ Also add the value to the front of the list in the variable `values'." (save-excursion (forward-sexp -1) ;; If first line is commented, ignore all leading comments: - (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;")) + (if (save-excursion (beginning-of-line) (looking-at-p "[ \t]*;")) (progn (setq exp (buffer-substring (point) pt)) (while (string-match "\n[ \t]*;+" exp start)