[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to tame compiler?
From: |
Jean Louis |
Subject: |
Re: How to tame compiler? |
Date: |
Tue, 4 May 2021 00:39:33 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* Michael Heerdegen <michael_heerdegen@web.de> [2021-05-02 08:59]:
> Jean Louis <bugs@gnu.support> writes:
>
> > How do I go to create dynamical bindings? Help me.
>
> Newest Emacs versions have `dlet' to create dynamical bindings. Here is
> the definition:
>
> #+begin_src emacs-lisp
> (defmacro dlet (binders &rest body)
> "Like `let*' but using dynamic scoping."
> (declare (indent 1) (debug let))
> `(let (_)
> ,@(mapcar (lambda (binder)
> `(defvar ,(if (consp binder) (car binder) binder)))
> binders)
> (let* ,binders ,@body)))
> #+end_src
>
> Use that macro to create dynamical bindings where you really need, and
> rely on lexical binding else.
That really helped me, or I would be lost today.
As my `rcd-template-eval' function did work, but somehow, for unknown
reasons as indicated already by developers, it started misbehaving,
and variables sometimes interpolated, sometimes not, or maybe at
second invokation not.
And I had to enclose the variables in the function within `dlet' and
now it works well. But I have to tame compiler...
This function can now generate thousands of pages, pre-process it,
process with Markdown, Asciidoctor, txt2tags, Org mode, or however,
page is written (or not process...) and produce the output.
I guess it is very inefficient. Important is that it works.
(defun wrs-generate-page (page-id)
(dlet ((page (rcd-db-table-id-hash "pages" page-id cf-db))
(area (rcd-db-table-id-hash "areas" (gethash "pages_area" page) cf-db))
(template (rcd-db-table-id-hash "templates"
(or (gethash "pages_templates" page)
(gethash "areas_template" area))
cf-db))
(pages_title (gethash "pages_title" page))
(pages_keywords (gethash "pages_keywords" page))
(pages_description (gethash "pages_description" page))
(variables (make-hash-table :test 'equal))
(_ (hash-append variables (wrs-variables-hash nil nil nil 3)))
(_ (hash-append variables (wrs-variables-hash (gethash "pages_area"
page))))
(_ (hash-append variables (wrs-variables-hash nil (gethash
"templates_id" template))))
(language (rcd-db-get-entry "languages" "languages_extension"
(or (gethash "pages_language" page)
(gethash "areas_defaultlanguage" area))
cf-db))
(_ (puthash "languages_extension" language variables))
(_ (when (gethash "areas_company" area)
(puthash "areas_company"
(rcd-db-get-entry "accounts" "accounts_name"
(gethash "areas_company" area)
cf-db)
variables)))
(_ (hash-append variables page area template))
(text (rcd-template-eval (gethash "pages_content" page "") '("⟦" "⟧")
variables))
(processor (gethash "templates_processor" template))
(text (wrs-process-text processor text))
(_ (puthash "pages_content" text variables))
(template (gethash "templates_content" template))
(open-graph-type "Article")
(html (rcd-template-eval template '("⟦" "⟧") variables))
(local-file (wrs-page-url page-id t)))
(string-to-file-force html local-file)))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/