diff options
| author | Andreas Schwab | 1998-01-07 10:40:25 +0000 |
|---|---|---|
| committer | Andreas Schwab | 1998-01-07 10:40:25 +0000 |
| commit | 3d98a374018eb8da7832434c781fe1c7b6ae75b1 (patch) | |
| tree | 2d44475fe637a86c520863a738b9ac7191d9e9a5 /lisp | |
| parent | 33933d45beb4ab3b66b421a970fc9d3ab18e9acc (diff) | |
| download | emacs-3d98a374018eb8da7832434c781fe1c7b6ae75b1.tar.gz emacs-3d98a374018eb8da7832434c781fe1c7b6ae75b1.zip | |
(pp-to-string): Greatly simplify by letting the
Emacs printer do the (quote x) to 'x conversion. Better handle
the # print syntax in all its forms.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/pp.el | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el index 34c8857aec9..bdc884ab50b 100644 --- a/lisp/emacs-lisp/pp.el +++ b/lisp/emacs-lisp/pp.el | |||
| @@ -36,54 +36,31 @@ that `read' can handle, whenever this is possible." | |||
| 36 | (progn | 36 | (progn |
| 37 | (lisp-mode-variables nil) | 37 | (lisp-mode-variables nil) |
| 38 | (set-syntax-table emacs-lisp-mode-syntax-table) | 38 | (set-syntax-table emacs-lisp-mode-syntax-table) |
| 39 | (let ((print-escape-newlines pp-escape-newlines)) | 39 | (let ((print-escape-newlines pp-escape-newlines) |
| 40 | (print-quoted t)) | ||
| 40 | (prin1 object (current-buffer))) | 41 | (prin1 object (current-buffer))) |
| 41 | (goto-char (point-min)) | 42 | (goto-char (point-min)) |
| 42 | (while (not (eobp)) | 43 | (while (not (eobp)) |
| 43 | ;; (message "%06d" (- (point-max) (point))) | 44 | ;; (message "%06d" (- (point-max) (point))) |
| 44 | (cond | 45 | (cond |
| 45 | ((looking-at "\\s(\\|#\\s(") | ||
| 46 | (while (looking-at "\\s(\\|#\\s(") | ||
| 47 | (forward-char 1))) | ||
| 48 | ((and (looking-at "\\(quote[ \t]+\\)\\([^.)]\\)") | ||
| 49 | (> (match-beginning 1) 1) | ||
| 50 | (= ?\( (char-after (1- (match-beginning 1)))) | ||
| 51 | ;; Make sure this is a two-element list. | ||
| 52 | (save-excursion | ||
| 53 | (goto-char (match-beginning 2)) | ||
| 54 | (forward-sexp) | ||
| 55 | ;; (looking-at "[ \t]*\)") | ||
| 56 | ;; Avoid mucking with match-data; does this test work? | ||
| 57 | (char-equal ?\) (char-after (point))))) | ||
| 58 | ;; -1 gets the paren preceding the quote as well. | ||
| 59 | (delete-region (1- (match-beginning 1)) (match-end 1)) | ||
| 60 | (insert "'") | ||
| 61 | (forward-sexp 1) | ||
| 62 | (if (looking-at "[ \t]*\)") | ||
| 63 | (delete-region (match-beginning 0) (match-end 0)) | ||
| 64 | (error "Malformed quote")) | ||
| 65 | (backward-sexp 1)) | ||
| 66 | ((condition-case err-var | 46 | ((condition-case err-var |
| 67 | (prog1 t (down-list 1)) | 47 | (prog1 t (down-list 1)) |
| 68 | (error nil)) | 48 | (error nil)) |
| 69 | (backward-char 1) | 49 | (save-excursion |
| 70 | (skip-chars-backward " \t") | 50 | (backward-char 1) |
| 71 | (delete-region | 51 | (skip-chars-backward "'`#^") |
| 72 | (point) | 52 | (when (and (not (bobp)) (= ?\ (char-before))) |
| 73 | (progn (skip-chars-forward " \t") (point))) | 53 | (delete-char -1) |
| 74 | (if (not (char-equal ?' (char-after (1- (point))))) | 54 | (insert "\n")))) |
| 75 | (insert ?\n))) | ||
| 76 | ((condition-case err-var | 55 | ((condition-case err-var |
| 77 | (prog1 t (up-list 1)) | 56 | (prog1 t (up-list 1)) |
| 78 | (error nil)) | 57 | (error nil)) |
| 79 | (while (looking-at "\\s)") | 58 | (while (looking-at "\\s)") |
| 80 | (forward-char 1)) | 59 | (forward-char 1)) |
| 81 | (skip-chars-backward " \t") | ||
| 82 | (delete-region | 60 | (delete-region |
| 83 | (point) | 61 | (point) |
| 84 | (progn (skip-chars-forward " \t") (point))) | 62 | (progn (skip-chars-forward " \t") (point))) |
| 85 | (if (not (char-equal ?' (char-after (1- (point))))) | 63 | (insert ?\n)) |
| 86 | (insert ?\n))) | ||
| 87 | (t (goto-char (point-max))))) | 64 | (t (goto-char (point-max))))) |
| 88 | (goto-char (point-min)) | 65 | (goto-char (point-min)) |
| 89 | (indent-sexp) | 66 | (indent-sexp) |