From 3048379bd45f4ea3e4f73c033552bd75bc894c2e Mon Sep 17 00:00:00 2001 From: Nikita Bloshchanevich Date: Sun, 4 Apr 2021 10:57:25 +0200 Subject: [PATCH 1/2] Print #' for `function' `macrostep' already prints `quote' like ', so do something similar for `function' (sharpquote). --- macrostep.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/macrostep.el b/macrostep.el index 297d549..5cce52a 100644 --- a/macrostep.el +++ b/macrostep.el @@ -1042,12 +1042,12 @@ should be dynamically let-bound around calls to this function." ((listp sexp) ;; Print quoted and quasiquoted forms nicely. (let ((head (car sexp))) - (cond ((and (eq head 'quote) ; quote - (= (length sexp) 2)) - (insert "'") + (cond ((and (memq head '(quote function)) ; quote/sharpquote + (= (length sexp) 2)) + (insert (if (eq 'quote head) "'" "#'")) (macrostep-print-sexp (cadr sexp))) - ((and (eq head '\`) ; backquote + ((and (eq head '\`) ; backquote (= (length sexp) 2)) (if (assq sexp macrostep-collected-macro-form-alist) (macrostep-propertize From ba2704ef40b5915ff9868d28988879b473ff1363 Mon Sep 17 00:00:00 2001 From: Nikita Bloshchanevich Date: Mon, 5 Apr 2021 20:38:38 +0200 Subject: [PATCH 2/2] Don't `error' for irregular quote forms `length' doesn't work on macros that expand to irregular quote forms, e.g. (quote . x), where X is not a list. Handle those correctly as well, by abstracting the quote checking code into a function that checks for `cons'es. --- macrostep.el | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/macrostep.el b/macrostep.el index 5cce52a..e77d45e 100644 --- a/macrostep.el +++ b/macrostep.el @@ -1016,6 +1016,12 @@ Controls the printing of sub-forms in `macrostep-print-sexp'.") collect `(put-text-property ,start (point) ,key ,value)))))) +(defun macrostep--quote-p (quote-types sexp) + "Check whether SEXP is `quote'-like form. +QUOTE-TYPES is the list of quote types to be checked for (e.g. +`quote', `backquote')." + (and (memq (car sexp) quote-types) (consp (cdr sexp)) (null (cddr sexp)))) + (defun macrostep-print-sexp (sexp) "Insert SEXP like `print', fontifying macro forms and uninterned symbols. @@ -1042,13 +1048,11 @@ should be dynamically let-bound around calls to this function." ((listp sexp) ;; Print quoted and quasiquoted forms nicely. (let ((head (car sexp))) - (cond ((and (memq head '(quote function)) ; quote/sharpquote - (= (length sexp) 2)) + (cond ((macrostep--quote-p '(quote function) sexp) ; quote/sharpquote (insert (if (eq 'quote head) "'" "#'")) (macrostep-print-sexp (cadr sexp))) - ((and (eq head '\`) ; backquote - (= (length sexp) 2)) + ((macrostep--quote-p '(\`) sexp) ; backquote (if (assq sexp macrostep-collected-macro-form-alist) (macrostep-propertize (insert "`") @@ -1058,8 +1062,7 @@ should be dynamically let-bound around calls to this function." (insert "`")) (macrostep-print-sexp (cadr sexp))) - ((and (memq head '(\, \,@)) ; unquote - (= (length sexp) 2)) + ((macrostep--quote-p '(\, \,@) sexp) ; unquote (princ head (current-buffer)) (macrostep-print-sexp (cadr sexp))) @@ -1075,17 +1078,17 @@ should be dynamically let-bound around calls to this function." ;; Save the real expansion as a text property on the ;; opening paren (macrostep-propertize - (insert "(") - 'macrostep-macro-start t - 'macrostep-expanded-text sexp - 'macrostep-environment environment) + (insert "(") + 'macrostep-macro-start t + 'macrostep-expanded-text sexp + 'macrostep-environment environment) ;; Fontify the head of the macro (macrostep-propertize - (macrostep-print-sexp head) - 'font-lock-face - (if macro? - 'macrostep-macro-face - 'macrostep-compiler-macro-face))) + (macrostep-print-sexp head) + 'font-lock-face + (if macro? + 'macrostep-macro-face + 'macrostep-compiler-macro-face))) ;; Not a macro form (insert "(") (macrostep-print-sexp head))))