emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master f5388ba: Switch pp.el to lexical binding


From: Noam Postavsky
Subject: [Emacs-diffs] master f5388ba: Switch pp.el to lexical binding
Date: Thu, 2 Mar 2017 23:02:36 -0500 (EST)

branch: master
commit f5388ba8a7f3970afd0e2bcc52c834ae56178442
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Switch pp.el to lexical binding
    
    Additionally, do some minor code cleanup.
    
    * lisp/emacs-lisp/pp.el: Set lexical-binding.
    (pp-buffer): Use skip-syntax-forward.
    (pp-eval-expression): Use push.
    (pp-last-sexp): Use with-syntax-table.
    * test/lisp/emacs-lisp/pp-tests.el: New tests.
---
 lisp/emacs-lisp/pp.el            | 51 ++++++++++++++--------------------------
 test/lisp/emacs-lisp/pp-tests.el | 35 +++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index 2938c37..7ef46a4 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -1,4 +1,4 @@
-;;; pp.el --- pretty printer for Emacs Lisp
+;;; pp.el --- pretty printer for Emacs Lisp  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1989, 1993, 2001-2017 Free Software Foundation, Inc.
 
@@ -67,8 +67,7 @@ to make output that `read' can handle, whenever this is 
possible."
            (progn (skip-chars-backward " \t\n") (point)))
           (insert "\n"))))
      ((ignore-errors (up-list 1) t)
-      (while (looking-at-p "\\s)")
-        (forward-char 1))
+      (skip-syntax-forward ")")
       (delete-region
        (point)
        (progn (skip-chars-forward " \t\n") (point)))
@@ -129,7 +128,7 @@ Also add the value to the front of the list in the variable 
`values'."
   (interactive
    (list (read--expression "Eval: ")))
   (message "Evaluating...")
-  (setq values (cons (eval expression lexical-binding) values))
+  (push (eval expression lexical-binding) values)
   (pp-display-expression (car values) "*Pp Eval Output*"))
 
 ;;;###autoload
@@ -141,22 +140,21 @@ Also add the value to the front of the list in the 
variable `values'."
 
 (defun pp-last-sexp ()
   "Read sexp before point.  Ignores leading comment characters."
-  (let ((stab (syntax-table)) (pt (point)) start exp)
-    (set-syntax-table emacs-lisp-mode-syntax-table)
-    (save-excursion
-      (forward-sexp -1)
-      ;; If first line is commented, ignore all leading comments:
-      (if (save-excursion (beginning-of-line) (looking-at-p "[ \t]*;"))
-         (progn
-           (setq exp (buffer-substring (point) pt))
-           (while (string-match "\n[ \t]*;+" exp start)
-             (setq start (1+ (match-beginning 0))
-                   exp (concat (substring exp 0 start)
-                               (substring exp (match-end 0)))))
-           (setq exp (read exp)))
-       (setq exp (read (current-buffer)))))
-    (set-syntax-table stab)
-    exp))
+  (with-syntax-table emacs-lisp-mode-syntax-table
+    (let ((pt (point)))
+      (save-excursion
+        (forward-sexp -1)
+        (read
+         ;; If first line is commented, ignore all leading comments:
+         (if (save-excursion (beginning-of-line) (looking-at-p "[ \t]*;"))
+             (let ((exp (buffer-substring (point) pt))
+                   (start nil))
+               (while (string-match "\n[ \t]*;+" exp start)
+                 (setq start (1+ (match-beginning 0))
+                       exp (concat (substring exp 0 start)
+                                   (substring exp (match-end 0)))))
+               exp)
+           (current-buffer)))))))
 
 ;;;###autoload
 (defun pp-eval-last-sexp (arg)
@@ -178,19 +176,6 @@ Ignores leading comment characters."
       (insert (pp-to-string (macroexpand-1 (pp-last-sexp))))
     (pp-macroexpand-expression (pp-last-sexp))))
 
-;;; Test cases for quote
-;; (pp-eval-expression ''(quote quote))
-;; (pp-eval-expression ''((quote a) (quote b)))
-;; (pp-eval-expression ''('a 'b))      ; same as above
-;; (pp-eval-expression ''((quote (quote quote)) (quote quote)))
-;; These do not satisfy the quote test.
-;; (pp-eval-expression ''quote)
-;; (pp-eval-expression ''(quote))
-;; (pp-eval-expression ''(quote . quote))
-;; (pp-eval-expression ''(quote a b))
-;; (pp-eval-expression ''(quotefoo))
-;; (pp-eval-expression ''(a b))
-
 (provide 'pp)                          ; so (require 'pp) works
 
 ;;; pp.el ends here
diff --git a/test/lisp/emacs-lisp/pp-tests.el b/test/lisp/emacs-lisp/pp-tests.el
new file mode 100644
index 0000000..b9ed79c
--- /dev/null
+++ b/test/lisp/emacs-lisp/pp-tests.el
@@ -0,0 +1,35 @@
+;;; pp-tests.el --- Test suite for pretty printer.  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'pp)
+
+(ert-deftest pp-print-quote ()
+  (should (string= (pp-to-string 'quote) "quote"))
+  (should (string= (pp-to-string ''quote) "'quote"))
+  (should (string= (pp-to-string '('a 'b)) "('a 'b)\n"))
+  (should (string= (pp-to-string '(''quote 'quote)) "(''quote 'quote)\n"))
+  (should (string= (pp-to-string '(quote)) "(quote)\n"))
+  (should (string= (pp-to-string '(quote . quote)) "(quote . quote)\n"))
+  (should (string= (pp-to-string '(quote a b)) "(quote a b)\n"))
+  (should (string= (pp-to-string '(quotefoo)) "(quotefoo)\n"))
+  (should (string= (pp-to-string '(a b)) "(a b)\n")))
+
+;;; pp-tests.el ends here.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]