[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
never use `eval' (was: Re: How to mapcar or across a list?)
From: |
Emanuel Berg |
Subject: |
never use `eval' (was: Re: How to mapcar or across a list?) |
Date: |
Thu, 16 Jul 2015 00:57:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
"Pascal J. Bourguignon" <pjb@informatimago.com>
writes:
> It's always a bad idea to use eval, because eval
> evalutes in the nil environment, not in the local
> lexical envrionment.
I have used `eval' eight times in my current setup of
75 files.
Tho some of this code I wrote several years ago, I'd
be happy to correct it. Any hints - general or
specific - are appreciated.
;; From: http://user.it.uu.se/~embe8573/conf/emacs-init/faces.el
(defun set-color-face (name front &optional bold back)
(eval `(defvar ,(make-symbol name)))
(eval `(setq ,(intern name)
`((t (:foreground ,front
:background ,back
:bold ,bold) )))))
(defvar cf-black) (set-color-face "cf-black" "black")
(defvar cf-red) (set-color-face "cf-red" "red")
;; ...
;; From: http://user.it.uu.se/~embe8573/conf/emacs-init/ide/lisp.el
(defun do-repeat-complex-command ()
(interactive)
(eval (car command-history) ))
;; From: http://user.it.uu.se/~embe8573/conf/emacs-init/isbn.el
(defun book-page-to-bibtex ()
(interactive)
(save-excursion
(goto-char (point-min))
(let ((title (get-title))
(data (mapcar 'key-value
'("authors?" "publisher" "published" "isbn-10")) ))
(eval `(create-book nil ,title ,@data) )))) ; don't INSERT
;; From: http://user.it.uu.se/~embe8573/conf/emacs-init/match-data-format.el
(defun match-data-format (data match format-str)
(save-match-data
(string-match match data)
(eval `(message format-str ,@(make-match-list 1 data) ))))
;; From: http://user.it.uu.se/~embe8573/conf/emacs-init/wrap-search.el
(defun wrap-search-again (prefix)
"Search again for the most recent search string of `wrap-search'.
Use \\[universal-argument] \(to set the PREFIX\) to toggle case sensitiveness."
(interactive "p")
(let ((cmd (cl-dolist (cmd command-history)
(if (and (eq (car cmd) 'wrap-search)
(not (string= (cl-caddr cmd) "")) )
(cl-return cmd) ))))
(if cmd
(if (eq prefix 4)
(let*((old-prefix (cadr cmd))
(search-str (cl-caddr cmd))
(new-prefix (if (eq old-prefix 4) 1 4))
(final-cmd `(wrap-search ,new-prefix ,search-str)) )
(setq command-history (cons final-cmd command-history))
(eval final-cmd) )
(eval cmd) )
(message " No previous search.") )))
--
underground experts united
http://user.it.uu.se/~embe8573
- How to mapcar or across a list?, Marcin Borkowski, 2015/07/15
- Message not available
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Barry Margolin, 2015/07/15
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Emanuel Berg, 2015/07/15
- Re: never use `eval' (was: Re: How to mapcar or across a list?), Emanuel Berg, 2015/07/16
- Message not available
- Re: never use `eval', Pascal J. Bourguignon, 2015/07/16
- Re: never use `eval', Emanuel Berg, 2015/07/16
- Re: never use `eval', Barry Margolin, 2015/07/17