-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
do not indent leaf tag. #26
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,30 +59,34 @@ XHTML and :HTML5 for HTML5 (HTML syntax)." | |
"Returns a string list corresponding to the `HTML' \(in CL-WHO | ||
syntax) in SEXP. Uses the generic function CONVERT-TO-STRING-LIST | ||
internally. Utility function used by TREE-TO-TEMPLATE." | ||
(let (tag attr-list body) | ||
(cond | ||
((keywordp sexp) | ||
(setq tag sexp)) | ||
((atom (first sexp)) | ||
(setq tag (first sexp)) | ||
;; collect attribute/value pairs into ATTR-LIST and tag body (if | ||
;; any) into BODY | ||
(loop for rest on (cdr sexp) by #'cddr | ||
if (keywordp (first rest)) | ||
collect (cons (first rest) (second rest)) into attr | ||
else | ||
do (progn (setq attr-list attr) | ||
(setq body rest) | ||
(return)) | ||
finally (setq attr-list attr))) | ||
((listp (first sexp)) | ||
(setq tag (first (first sexp))) | ||
(loop for rest on (cdr (first sexp)) by #'cddr | ||
if (keywordp (first rest)) | ||
collect (cons (first rest) (second rest)) into attr | ||
finally (setq attr-list attr)) | ||
(setq body (cdr sexp)))) | ||
(convert-tag-to-string-list tag attr-list body body-fn))) | ||
(flet ((short-leaf-p (s) | ||
(and (loop for e in (rest s) never (and (listp e) (keywordp (first e)))) | ||
(< (loop for e in (rest s) when (stringp e) sum (length e)) | ||
*short-leaf-content-length*)))) | ||
(let (tag attr-list body) | ||
(cond | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. incorrect indentation of |
||
((keywordp sexp) | ||
(setq tag sexp)) | ||
((atom (first sexp)) | ||
(setq tag (first sexp)) | ||
;; collect attribute/value pairs into ATTR-LIST and tag body (if | ||
;; any) into BODY | ||
(loop for rest on (cdr sexp) by #'cddr | ||
if (keywordp (first rest)) | ||
collect (cons (first rest) (second rest)) into attr | ||
else | ||
do (progn (setq attr-list attr) | ||
(setq body rest) | ||
(return)) | ||
finally (setq attr-list attr))) | ||
((listp (first sexp)) | ||
(setq tag (first (first sexp))) | ||
(loop for rest on (cdr (first sexp)) by #'cddr | ||
if (keywordp (first rest)) | ||
collect (cons (first rest) (second rest)) into attr | ||
finally (setq attr-list attr)) | ||
(setq body (cdr sexp)))) | ||
(convert-tag-to-string-list tag attr-list body body-fn (short-leaf-p sexp))))) | ||
|
||
(defun convert-attributes (attr-list) | ||
"Helper function for CONVERT-TAG-TO-STRING-LIST which converts the | ||
|
@@ -132,15 +136,17 @@ forms." | |
,=var= | ||
*attribute-quote-char*))))))) | ||
|
||
(defgeneric convert-tag-to-string-list (tag attr-list body body-fn) | ||
(defgeneric convert-tag-to-string-list (tag attr-list body body-fn leaf-p) | ||
(:documentation "Used by PROCESS-TAG to convert `HTML' into a list | ||
of strings. TAG is a keyword symbol naming the outer tag, ATTR-LIST | ||
is an alist of its attributes \(the car is the attribute's name as a | ||
keyword, the cdr is its value), BODY is the tag's body, and BODY-FN is | ||
a function which should be applied to BODY. The function must return | ||
a list of strings or Lisp forms.")) | ||
a list of strings or Lisp forms. SHORT-LEAF-P is t when the TAG is a | ||
leaf and its content is shorter than *SHORT-LEAF-CONTENT-LENGTH* then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, specifying that this is in characters would be useful. Also, the grammar here irks me. "[...] is t when TAG is a leaf and its content is shorter than SHORT-LEAF-CONTENT-LENGTH characters. Short leaves are not indented." |
||
it is not indented.")) | ||
|
||
(defmethod convert-tag-to-string-list (tag attr-list body body-fn) | ||
(defmethod convert-tag-to-string-list (tag attr-list body body-fn short-leaf-p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an awful lot of required params. Could some of these be |
||
"The standard method which is not specialized. The idea is that you | ||
can use EQL specializers on the first argument." | ||
(declare (optimize speed space)) | ||
|
@@ -164,7 +170,7 @@ can use EQL specializers on the first argument." | |
;; now hand over the tag's body to TREE-TO-TEMPLATE | ||
(let ((*indent* body-indent)) | ||
(funcall body-fn body)) | ||
(when body-indent | ||
(when (and body-indent (not short-leaf-p)) | ||
;; indentation | ||
(list +newline+ (n-spaces *indent*))) | ||
;; closing tag | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docstring is unclear in that it doesn't specify units. I'd much prefer something like "Leaf tags shorter than this many characters won't be indented."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, old stuff! Yes fine by me. Having units is better. I'm also ok with your other comments… but now I should find out how to modify the patch for this PR :-|