all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to tame compiler?
Date: Sat, 1 May 2021 10:05:01 +0300	[thread overview]
Message-ID: <YIz9nZir7FddMLIg@protected.localdomain> (raw)
In-Reply-To: <87czub5a2x.fsf@web.de>

[-- Attachment #1: Type: text/plain, Size: 1610 bytes --]

* Michael Heerdegen <michael_heerdegen@web.de> [2021-05-01 07:54]:
> Michael Heerdegen <michael_heerdegen@web.de> 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/


[-- Attachment #2: test.el --]
[-- Type: text/plain, Size: 370 bytes --]

;; -*- 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)

[-- Attachment #3: rcd-template.el --]
[-- Type: text/plain, Size: 2126 bytes --]

;;; 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

  reply	other threads:[~2021-05-01  7:05 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 14:43 How to tame compiler? Jean Louis
2021-04-22 14:46 ` Stefan Monnier
2021-04-22 15:47   ` Jean Louis
2021-04-22 16:06   ` Jean Louis
2021-04-30 13:31   ` Jorge P. de Morais Neto
2021-04-30 19:38     ` rcd-template-eval - was " Jean Louis
2021-04-30 19:48     ` rcd-template-eval, much is in Org mode Jean Louis
2021-04-30 20:06       ` Tassilo Horn
2021-04-30 22:08       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-30 23:04         ` Org mode rant Jean Louis
2021-05-01  0:46           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  6:10             ` Jean Louis
2021-05-01  6:34               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  9:41                 ` On markdown images Jean Louis
2021-05-01  9:59                   ` Yuri Khan
2021-05-01 10:18                     ` Jean Louis
2021-05-01 11:09                       ` Yuri Khan
2021-05-01 11:25                         ` Jean Louis
2021-05-02 19:30                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-03  5:43                           ` Yuri Khan
2021-05-03 17:08                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-03 23:22                               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04  2:39                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  5:00           ` Org mode rant Bastien
2021-05-01  5:10             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  9:16             ` Jean Louis
2021-05-01 10:06               ` Bastien
2021-05-01 10:42                 ` Jean Louis
2021-05-01 10:10               ` Bastien
2021-05-01 11:19                 ` Jean Louis
2021-05-01 13:48                 ` [External] : " Drew Adams
2021-05-01 14:05                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01 10:10               ` Bastien
2021-04-30 20:23     ` eval myths - Re: How to tame compiler? Jean Louis
2021-04-30 22:11       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-30 23:07         ` Jean Louis
2021-05-01  0:28           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  8:13       ` tomas
2021-04-30 22:06     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-30 22:20       ` Stefan Monnier
2021-04-30 22:31         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-30 22:50           ` Stefan Monnier
2021-04-30 22:56             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  0:44 ` Michael Heerdegen
2021-05-01  3:49   ` Stefan Monnier
2021-05-01  4:55     ` Michael Heerdegen
2021-05-01  6:34     ` Jean Louis
2021-05-01 13:38       ` Stefan Monnier
2021-05-01 16:19         ` Jean Louis
2021-05-02  5:41     ` Michael Heerdegen
2021-05-02  7:37       ` Jean Louis
2021-05-02  7:45       ` Jean Louis
2021-05-02  9:06         ` tomas
2021-05-02 11:18           ` Jean Louis
2021-05-02 12:24             ` tomas
2021-05-02 18:17               ` Jean Louis
2021-05-02 12:06           ` Stages of WWW development compared to Emacs Lisp development Jean Louis
2021-05-02 16:51             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02 18:37               ` Jean Louis
2021-05-02 16:45       ` How to tame compiler? Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02 22:29       ` Stefan Monnier
2021-05-02 23:14         ` Jean Louis
2021-05-03  1:58           ` Eduardo Ochs
2021-05-03  6:51             ` Eval in templates - " Jean Louis
2021-05-01  4:53   ` Michael Heerdegen
2021-05-01  7:05     ` Jean Louis [this message]
2021-05-01  7:59       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-01  6:03   ` Jean Louis
2021-05-01  6:17     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-02  5:58     ` Michael Heerdegen
2021-05-02  6:54       ` Jean Louis
2021-05-03 21:39       ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YIz9nZir7FddMLIg@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.