aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorNoam Postavsky2017-03-02 22:37:03 -0500
committerNoam Postavsky2017-03-02 23:03:20 -0500
commitf5388ba8a7f3970afd0e2bcc52c834ae56178442 (patch)
tree125960f2cedd2c4586e8b2ebcf33d926eae4c54c /lisp
parent55c0c3e31bc3dff83753cdba6288228bd025ac84 (diff)
downloademacs-f5388ba8a7f3970afd0e2bcc52c834ae56178442.tar.gz
emacs-f5388ba8a7f3970afd0e2bcc52c834ae56178442.zip
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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emacs-lisp/pp.el51
1 files changed, 18 insertions, 33 deletions
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index 2938c37e8a8..7ef46a48bde 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -1,4 +1,4 @@
1;;; pp.el --- pretty printer for Emacs Lisp 1;;; pp.el --- pretty printer for Emacs Lisp -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1989, 1993, 2001-2017 Free Software Foundation, Inc. 3;; Copyright (C) 1989, 1993, 2001-2017 Free Software Foundation, Inc.
4 4
@@ -67,8 +67,7 @@ to make output that `read' can handle, whenever this is possible."
67 (progn (skip-chars-backward " \t\n") (point))) 67 (progn (skip-chars-backward " \t\n") (point)))
68 (insert "\n")))) 68 (insert "\n"))))
69 ((ignore-errors (up-list 1) t) 69 ((ignore-errors (up-list 1) t)
70 (while (looking-at-p "\\s)") 70 (skip-syntax-forward ")")
71 (forward-char 1))
72 (delete-region 71 (delete-region
73 (point) 72 (point)
74 (progn (skip-chars-forward " \t\n") (point))) 73 (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'."
129 (interactive 128 (interactive
130 (list (read--expression "Eval: "))) 129 (list (read--expression "Eval: ")))
131 (message "Evaluating...") 130 (message "Evaluating...")
132 (setq values (cons (eval expression lexical-binding) values)) 131 (push (eval expression lexical-binding) values)
133 (pp-display-expression (car values) "*Pp Eval Output*")) 132 (pp-display-expression (car values) "*Pp Eval Output*"))
134 133
135;;;###autoload 134;;;###autoload
@@ -141,22 +140,21 @@ Also add the value to the front of the list in the variable `values'."
141 140
142(defun pp-last-sexp () 141(defun pp-last-sexp ()
143 "Read sexp before point. Ignores leading comment characters." 142 "Read sexp before point. Ignores leading comment characters."
144 (let ((stab (syntax-table)) (pt (point)) start exp) 143 (with-syntax-table emacs-lisp-mode-syntax-table
145 (set-syntax-table emacs-lisp-mode-syntax-table) 144 (let ((pt (point)))
146 (save-excursion 145 (save-excursion
147 (forward-sexp -1) 146 (forward-sexp -1)
148 ;; If first line is commented, ignore all leading comments: 147 (read
149 (if (save-excursion (beginning-of-line) (looking-at-p "[ \t]*;")) 148 ;; If first line is commented, ignore all leading comments:
150 (progn 149 (if (save-excursion (beginning-of-line) (looking-at-p "[ \t]*;"))
151 (setq exp (buffer-substring (point) pt)) 150 (let ((exp (buffer-substring (point) pt))
152 (while (string-match "\n[ \t]*;+" exp start) 151 (start nil))
153 (setq start (1+ (match-beginning 0)) 152 (while (string-match "\n[ \t]*;+" exp start)
154 exp (concat (substring exp 0 start) 153 (setq start (1+ (match-beginning 0))
155 (substring exp (match-end 0))))) 154 exp (concat (substring exp 0 start)
156 (setq exp (read exp))) 155 (substring exp (match-end 0)))))
157 (setq exp (read (current-buffer))))) 156 exp)
158 (set-syntax-table stab) 157 (current-buffer)))))))
159 exp))
160 158
161;;;###autoload 159;;;###autoload
162(defun pp-eval-last-sexp (arg) 160(defun pp-eval-last-sexp (arg)
@@ -178,19 +176,6 @@ Ignores leading comment characters."
178 (insert (pp-to-string (macroexpand-1 (pp-last-sexp)))) 176 (insert (pp-to-string (macroexpand-1 (pp-last-sexp))))
179 (pp-macroexpand-expression (pp-last-sexp)))) 177 (pp-macroexpand-expression (pp-last-sexp))))
180 178
181;;; Test cases for quote
182;; (pp-eval-expression ''(quote quote))
183;; (pp-eval-expression ''((quote a) (quote b)))
184;; (pp-eval-expression ''('a 'b)) ; same as above
185;; (pp-eval-expression ''((quote (quote quote)) (quote quote)))
186;; These do not satisfy the quote test.
187;; (pp-eval-expression ''quote)
188;; (pp-eval-expression ''(quote))
189;; (pp-eval-expression ''(quote . quote))
190;; (pp-eval-expression ''(quote a b))
191;; (pp-eval-expression ''(quotefoo))
192;; (pp-eval-expression ''(a b))
193
194(provide 'pp) ; so (require 'pp) works 179(provide 'pp) ; so (require 'pp) works
195 180
196;;; pp.el ends here 181;;; pp.el ends here