From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: How to tame compiler? Date: Sat, 1 May 2021 10:05:01 +0300 Message-ID: References: <875z03th9b.fsf@web.de> <87czub5a2x.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_stw1.rcdrun.com-9437-1619852925-0001-2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8922"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat May 01 09:09:12 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lcjkW-0002Cg-03 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 01 May 2021 09:09:12 +0200 Original-Received: from localhost ([::1]:37758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcjkV-0005HC-3Q for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 01 May 2021 03:09:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcjkA-0005Gt-NK for help-gnu-emacs@gnu.org; Sat, 01 May 2021 03:08:50 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:59815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcjk8-0008Dg-A3 for help-gnu-emacs@gnu.org; Sat, 01 May 2021 03:08:50 -0400 Original-Received: from localhost ([::ffff:154.231.162.22]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000046239.00000000608CFE7C.000024DD; Sat, 01 May 2021 00:08:44 -0700 Mail-Followup-To: Michael Heerdegen , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87czub5a2x.fsf@web.de> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129260 Archived-At: This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_stw1.rcdrun.com-9437-1619852925-0001-2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 * Michael Heerdegen [2021-05-01 07:54]: > Michael Heerdegen writes: > > > you would have to create dynamical bindings for that. > > Oh, you could also use the second argument of `eval' to specify a > lexical environment. That would also help to get rid of the > warnings. How I understand it, I would need to use dynamical bindings, but in smallest example with lexical-binding t on the top of file, it does not work. So I do not know how to use dynamical bindings. As function `rcd-template-eval' is in other file, when I provide `t' to (eval) in that other file, that still gives warnings in the file where variables are used, and then it will not expand. I have lost control. My program works, but it should not work. In fact if I remove: (ignore "Avoid compiler warnings" to-name hello-name body unsubscribe-text unsubscribe-url) than nothing works, and template does not get expanded, probably because of lexical bindings. (eval) I use without t If I comment `ignore' or I do not use ignore, it stops working, and nothing expands. If I do use ignore as above, it does work. But in the smallest example as in attached files, it does not work. Maybe it is some bug, and program works due to bug. I cannot bring it to minimum example, it just works, exactly how it is in these attached exampled (which don't work). -- 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/ --=_stw1.rcdrun.com-9437-1619852925-0001-2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="test.el" ;; -*- lexical-binding: t; -*- ;; (add-to-list 'load-path "~/Programming/emacs-lisp") (require 'rcd-template) (defun my-fun () (let* ((hello-name "Joe") ;; (lexical-binding nil) (template "⟦ hello-name ⟧") (expanded-body (rcd-template-eval template))) (ignore "Avoid compiler warnings" hello-name template) (message "%s" expanded-body))) (my-fun) --=_stw1.rcdrun.com-9437-1619852925-0001-2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="rcd-template.el" ;;; rcd-template.el --- template ;; -*- lexical-binding: t; -*- ;;; Commentary: ;; ;;; Code: (defvar rcd-template-delimiter-open "⟦") (defvar rcd-template-delimiter-close "⟧") (defun rcd-template-eval (string &optional delimiters) "Evaluates Emacs Lisp enclosed by `rcd-template-delimiter-open' and `rcd-template-delimiter-close'. Optional DELIMITERS list may be provided to change default delimiters, first list member has to be the opening delimiter and second the closing delimiter. Space or new line has to follow `rcd-template-delimiter-open' and precede `rcd-template-delimiter-close' for evaluation to get invoked." (let* ((delimiters (or delimiters (list rcd-template-delimiter-open rcd-template-delimiter-close))) (open (car delimiters)) (close (cadr delimiters))) (with-temp-buffer (insert string) (goto-char 0) (while (re-search-forward (rx (literal open) (one-or-more (or blank "\n")) (group (minimal-match (one-or-more anything))) (one-or-more (or blank "\n")) (literal close)) nil t) ;;(message "Found match") (let* ((lisp (car (read-from-string (buffer-substring-no-properties (1+ (match-beginning 0)) (1- (match-end 0)))))) (value (condition-case nil (eval lisp) (error ""))) (value (string-or-empty-string value))) ;; (message "HELLO: %s" (eval (format "%s" hello-name))) (delete-region (match-beginning 0) (match-end 0)) (insert (format "%s" value)))) (buffer-string)))) (defun rcd-template-buffer-eval () (interactive) (let* ((buffer (buffer-string)) (mode major-mode) (point (point))) (pop-to-buffer-same-window "Preview") (insert (rcd-template-eval buffer)) (goto-char point) (funcall mode) (espeak "Preview"))) (defun string-or-empty-string (i) "Returns empty string for nil" (let* ((type (type-of i))) (cond ((or (eql type 'integer) (eql type 'float)) (number-to-string i)) ((null i) "") ((eql type 'symbol) (prin1-to-string i)) ((eql type 'string) i)))) (provide 'rcd-template) ;;; rcd-template.el ends here --=_stw1.rcdrun.com-9437-1619852925-0001-2--