From 2e81c032efdc4241c576c6ead36efaa641e69744 Mon Sep 17 00:00:00 2001 From: JAremko Date: Wed, 11 Mar 2020 08:57:19 +0200 Subject: [PATCH] [spacebind] enable nested form fmt --- core/core-spacebind.el | 82 +++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/core/core-spacebind.el b/core/core-spacebind.el index b73454730..979741d74 100644 --- a/core/core-spacebind.el +++ b/core/core-spacebind.el @@ -195,42 +195,52 @@ NOTE: This function strips all newline characters, replaces successive spaces with a singular in string elements of FORM and trims tails of function labels delimited by \"|\" character." (list - (cl-destructuring-bind - (key-or-prefix-form - leader-label-or-fn-symbol - leader-label-or-next-form) - (mapcar (lambda (el) - ;; Convert new lines and multiply spaces into singular. - ;; This is done to enable better binding form formatting. - (if (stringp el) - (replace-regexp-in-string "[\n[:space:]]+" " " el) - el)) - (seq-take form 3)) - (let ((full-key-or-prefix (append - path - ;; ("key" :label "label") or "key". - `(,(or (car-safe key-or-prefix-form) - key-or-prefix-form)))) - (key-or-prefix-label (thread-first key-or-prefix-form - (cdr-safe) - (plist-get :label)))) - (if (symbolp leader-label-or-fn-symbol) - (funcall k-fn - full-key-or-prefix - key-or-prefix-label - leader-label-or-fn-symbol - ;; Discard everything after | symbol in labels. - ;; This way we can add extra text into the documentation - ;; while omitting it in labels. - (replace-regexp-in-string - "[[:punct:][:space:]]*|.*" - "" - ;; Either "label" or ("doc label" :label "label"). - (or (thread-first leader-label-or-next-form - (cdr-safe) - (plist-get :label)) - leader-label-or-next-form))) - (funcall p-fn full-key-or-prefix leader-label-or-fn-symbol)))))) + (cl-labels ((apply-str-fmt + (el) + (thread-last el + ;; Convert new lines and multiply spaces into singular. + ;; This is done to enable better binding forms. + (replace-regexp-in-string "[\n[:space:]]+" " ") + ;; Discard everything after | symbol in labels. + ;; This way we can add extra text into the README.org + ;; files while omitting it in labels. + (replace-regexp-in-string "[[:punct:][:space:]]*|.+" ""))) + (str-fmt-rec + (depth el) + (cond + ((stringp el) (apply-str-fmt el)) + ((and (= depth 0) + (listp el)) + ;; We don't want to go deeper than a single level. + (mapcar (apply-partially #'str-fmt-rec (1+ depth)) el)) + (t el))) + (str-fmt + (el) + (str-fmt-rec 0 el))) + (cl-destructuring-bind + (key-or-prefix-form + leader-label-or-fn-symbol + leader-label-or-next-form) + (mapcar #'str-fmt (seq-take form 3)) + (let ((full-key-or-prefix (append + path + ;; ("key" :label "label") or "key". + `(,(or (car-safe key-or-prefix-form) + key-or-prefix-form)))) + (key-or-prefix-label (thread-first key-or-prefix-form + (cdr-safe) + (plist-get :label)))) + (if (symbolp leader-label-or-fn-symbol) + (funcall k-fn + full-key-or-prefix + key-or-prefix-label + leader-label-or-fn-symbol + ;; Either "label" or ("doc label" :label "label"). + (or (thread-first leader-label-or-next-form + (cdr-safe) + (plist-get :label)) + leader-label-or-next-form)) + (funcall p-fn full-key-or-prefix leader-label-or-fn-symbol))))))) (defun spacemacs//spacebind-form-walker-rec (path k-fn p-fn form) "Recursive body of `spacemacs//spacebind-form-walker'."