branch: externals/eev commit 1b908454516a9b475412b56058dfe9d86e2f7e4f Author: Eduardo Ochs <eduardoo...@gmail.com> Commit: Eduardo Ochs <eduardoo...@gmail.com>
Added `(find-lexical-intro)' and `ee-eval-last-sexp-11'. --- ChangeLog | 10 +++ VERSION | 4 +- eev-eval.el | 216 +++++++++++++++++++++++++++++++++++++++++------------------ eev-intro.el | 209 ++++++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 317 insertions(+), 122 deletions(-) diff --git a/ChangeLog b/ChangeLog index 627b0ad..9b6e4ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ +2021-08-13 Eduardo Ochs <eduardoo...@gmail.com> + + * eev-intro.el (find-lexical-intro): new function. + + * eev-eval.el (ee-eval-lexical): new function. + (ee-eval-last-sexp-11): new function. + 2021-08-11 Eduardo Ochs <eduardoo...@gmail.com> + * eev-eval.el (ee-eval-last-sexp): rewrote completely. + (ee-eval-last-sexp-9): commented out. + * eev-prepared.el (octal-to-num): renamed to `ee-octal-to-num'. * eepitch.el (at-eepitch-target): deleted. It was a copy of diff --git a/VERSION b/VERSION index 64fed88..c845d25 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -Wed Aug 11 10:44:32 GMT 2021 -Wed Aug 11 07:44:32 -03 2021 +Fri Aug 13 05:54:51 GMT 2021 +Fri Aug 13 02:54:51 -03 2021 diff --git a/eev-eval.el b/eev-eval.el index ee997f1..9f86aab 100644 --- a/eev-eval.el +++ b/eev-eval.el @@ -19,7 +19,7 @@ ;; ;; Author: Eduardo Ochs <eduardoo...@gmail.com> ;; Maintainer: Eduardo Ochs <eduardoo...@gmail.com> -;; Version: 20201130 +;; Version: 20210813 ;; Keywords: e-scripts ;; ;; Latest version: <http://angg.twu.net/eev-current/eev-eval.el> @@ -40,24 +40,33 @@ ;; (find-eev-quick-intro "2. Evaluating Lisp" "When you type `M-e'") ;; (find-eev-quick-intro "2. Evaluating Lisp" "numeric prefixes") ;; (find-eev-quick-intro "2. Evaluating Lisp" "`M-0 M-e'") +;; (find-eval-intro "`M-E' (meta-shift-e)") +;; ;; Note that `M-2 M-e' and `M-3 M-e' only make sense when the sexp is ;; a hyperlink. +;; Index: +;; «.tools» (to "tools") +;; «.arg-variants» (to "arg-variants") +;; «.ee-eval-last-sexp» (to "ee-eval-last-sexp") +;; «.two-old-definitions» (to "two-old-definitions") (require 'eev-flash) ; (find-eev "eev-flash.el") (require 'eev-multiwindow) ; (find-eev "eev-multiwindow.el") -;;; _ _ -;;; _____ ____ _| | ___ _____ ___ __ ___ ___ | | -;;; / _ \ \ / / _` | |_____/ __|/ _ \ \/ / '_ \ _____ / _ \/ _ \| | -;;; | __/\ V / (_| | |_____\__ \ __/> <| |_) |_____| __/ (_) | | -;;; \___| \_/ \__,_|_| |___/\___/_/\_\ .__/ \___|\___/|_| -;;; |_| -;;; -;;; Evaluating sexps (alternatives to eval-last-sexp) -;;; + + + +;;; _____ _ +;;; |_ _|__ ___ | |___ +;;; | |/ _ \ / _ \| / __| +;;; | | (_) | (_) | \__ \ +;;; |_|\___/ \___/|_|___/ +;;; +;; «tools» (to ".tools") +;; Move backward and forward by sexps, get sexp, eval in special ways. ;; See (find-efunction 'eval-last-sexp-1) (defun ee-backward-sexp () @@ -89,11 +98,36 @@ This is an internal function used by `ee-eval-last-sexp'." (defmacro ee-no-debug (&rest body) `(let ((debug-on-error nil)) ,@body)) -;; `ee-eval' is also defined elsewhere: +;; `ee-eval' is also defined in this other file: ;; (find-eevfile "eepitch.el" "defun ee-eval") ;; (defun ee-eval (sexp) (let ((debug-on-error nil)) (eval sexp))) +;; +(defun ee-eval (sexp) + "Eval SEXP with `debug-on-error' turned off." + (ee-no-debug (eval sexp))) + +(defun ee-eval-lexical (sexp) + "Like `ee-eval', but uses lexical binding." + (ee-no-debug (eval sexp 'lexical))) + + + -(defun ee-eval (sexp) (ee-no-debug (eval sexp))) +;;; _ _ +;;; __ _ _ __ __ _ __ ____ _ _ __(_) __ _ _ __ | |_ ___ +;;; / _` | '__/ _` | \ \ / / _` | '__| |/ _` | '_ \| __/ __| +;;; | (_| | | | (_| | \ V / (_| | | | | (_| | | | | |_\__ \ +;;; \__,_|_| \__, | \_/ \__,_|_| |_|\__,_|_| |_|\__|___/ +;;; |___/ +;; +;; «arg-variants» (to ".arg-variants") +;; The variants that are executed when we run `M-0 M-e', `M-1 M-e', +;; etc instead of just `M-e'. To implement a variant for, for example, +;; `M-4 M-2 M-e' you just need to define `ee-eval-last-sexp-42'. + +(defun ee-eval-last-sexp-default (&optional arg) + "Evaluate the sexp before point and show the result in the echo area." + (prin1 (ee-eval (read (ee-last-sexp))))) (defun ee-eval-last-sexp-0 () "Highlight the sexp before point." @@ -133,47 +167,123 @@ This is an internal function used by `ee-eval-last-sexp'." "Evaluate the sexp before point and pretty-print its result in other buffer." (find-epp (ee-eval (read (ee-last-sexp))))) -(defun ee-eval-last-sexp-9 () - "A hack for testing `call-interactively'" - (let ((interactive-clause (read (ee-last-sexp)))) - (let ((debug-on-error nil)) - (call-interactively - `(lambda (&rest args) ,interactive-clause - (message "%S" args)))))) +(defun ee-eval-last-sexp-11 () + "Like `ee-eval-last-sexp-default', but uses lexical binding." + (prin1 (ee-eval-lexical (read (ee-last-sexp))))) +;; ;; The old definition for `ee-eval-last-sexp-default', +;; ;; that contained an undocumented hack: +;; ;; +;; (defun ee-eval-last-sexp-default (&optional arg) +;; "Evaluate the sexp before point and show the result in the echo area." +;; (prin1 (let ((ee-arg arg)) (ee-eval (read (ee-last-sexp)))))) +;; +;; ;; This was hard to explain and to use... +;; ;; +;; (defun ee-eval-last-sexp-9 () +;; "A hack for testing `call-interactively'." +;; (let ((interactive-clause (read (ee-last-sexp)))) +;; (let ((debug-on-error nil)) +;; (call-interactively +;; `(lambda (&rest args) ,interactive-clause +;; (message "%S" args)))))) -(defun ee-eval-last-sexp (&optional arg) - "By default, evaluate sexp before point, and print value in minibuffer. -This is eev's variant of `eval-last-sexp', and it can behave in + + + +;;; __ __ +;;; | \/ | ___ +;;; | |\/| |_____ / _ \ +;;; | | | |_____| __/ +;;; |_| |_| \___| +;;; +;; «ee-eval-last-sexp» (to ".ee-eval-last-sexp") +;; See: (find-emacs-keys-intro "1. Basic keys (eev)") +;; (find-emacs-keys-intro "1. Basic keys (eev)" "M-e") + +(defun ee-eval-sexp-eol (&optional arg) +"Go to the end of line, then run `ee-eval-last-sexp'. +By default, evaluate sexp before eol, and print value in minibuffer. +This is eev's variant of `C-e C-x C-e', and it can behave in several different ways depending on the prefix argument ARG. See: (find-eev-quick-intro \"`M-0 M-e'\") If ARG is: - nil: evaluate the sexp with `debug-on-error' turned off + nil: evaluate the sexp (with `debug-on-error' turned off) 0: highlight the sexp temporarily 1: show the sexp as a string - 2: show the target of the sexp in another window - 3: same, but also switch to the new window + 2: eval and show the target of the sexp in another window + 3: same as 2, but also switch to the new window 4: evaluate the sexp in debug mode 5: run the sexp with `debug-on-error' turned on - 7: this is equivalent to `M-e <down>' + 7: evaluate then move down 8: eval then pretty-print the result in another buffer - 9: a hack for testing `call-interactively' -other: set EE-ARG to ARG and eval (ee-last-sexp)." + 11: like nil, but using lexical binding. + +The listing above shows the default behaviors. To add a special +behavior for, say, ARG=42, define a function +`ee-eval-last-sexp-42'." (interactive "P") - (cond ((eq arg 0) (ee-eval-last-sexp-0)) - ((eq arg 1) (ee-eval-last-sexp-1)) - ((eq arg 2) (ee-eval-last-sexp-2)) - ((eq arg 3) (ee-eval-last-sexp-3)) - ((eq arg 4) (ee-eval-last-sexp-4)) - ((eq arg 5) (ee-eval-last-sexp-5)) - ((eq arg 7) (ee-eval-last-sexp-7)) - ((eq arg 8) (ee-eval-last-sexp-8)) - ((eq arg 9) (ee-eval-last-sexp-9)) - (t (prin1 (let ((ee-arg arg)) - (ee-eval (read (ee-last-sexp)))))))) - -;; (defun ee-eval-last-sexp (&optional arg) + (end-of-line) + (ee-eval-last-sexp arg)) + + +;; See: (find-eval-intro "`M-E' (meta-shift-e)") +;; +(defun ee-eval-last-sexp (&optional arg) + "By default, evaluate sexp before point, and show the result. +This is eev's variant of `eval-last-sexp', and it can behave in +several different ways depending on the prefix argument ARG. + +See `ee-eval-sexp-eol'." + (interactive "P") + (if (null arg) + (ee-eval-last-sexp-default) + (if (fboundp (intern (format "ee-eval-last-sexp-%d" arg))) + (funcall (intern (format "ee-eval-last-sexp-%d" arg))) + (ee-eval-last-sexp-default arg)))) + + + +;; «two-old-definitions» (to ".two-old-definitions") +;; Two old definitions for `ee-eval-last-sexp'. +;; I'm keeping them here in comments because they are nice to discuss +;; in workshops (when we have time to discuss basic elisp). +;; +;; +;; (defun ee-eval-last-sexp-OLD (&optional arg) +;; "By default, evaluate sexp before point, and print value in minibuffer. +;; This is eev's variant of `eval-last-sexp', and it can behave in +;; several different ways depending on the prefix argument ARG. +;; See: (find-eev-quick-intro \"`M-0 M-e'\") +;; +;; If ARG is: +;; nil: evaluate the sexp with `debug-on-error' turned off +;; 0: highlight the sexp temporarily +;; 1: show the sexp as a string +;; 2: show the target of the sexp in another window +;; 3: same, but also switch to the new window +;; 4: evaluate the sexp in debug mode +;; 5: run the sexp with `debug-on-error' turned on +;; 7: this is equivalent to `M-e <down>' +;; 8: eval then pretty-print the result in another buffer +;; 9: a hack for testing `call-interactively' +;; other: set EE-ARG to ARG and eval (ee-last-sexp)." +;; (interactive "P") +;; (cond ((eq arg 0) (ee-eval-last-sexp-0)) +;; ((eq arg 1) (ee-eval-last-sexp-1)) +;; ((eq arg 2) (ee-eval-last-sexp-2)) +;; ((eq arg 3) (ee-eval-last-sexp-3)) +;; ((eq arg 4) (ee-eval-last-sexp-4)) +;; ((eq arg 5) (ee-eval-last-sexp-5)) +;; ((eq arg 7) (ee-eval-last-sexp-7)) +;; ((eq arg 8) (ee-eval-last-sexp-8)) +;; ((eq arg 9) (ee-eval-last-sexp-9)) +;; (t (prin1 (let ((ee-arg arg)) +;; (ee-eval (read (ee-last-sexp)))))))) +;; +;; +;; (defun ee-eval-last-sexp-VERY-OLD (&optional arg) ;; "By default, evaluate sexp before point, and print value in minibuffer. ;; This is eev's variant of `eval-last-sexp', and it can behave in ;; several different ways depending on the prefix argument ARG. @@ -208,30 +318,6 @@ other: set EE-ARG to ARG and eval (ee-last-sexp)." ;; (t (prin1 (let ((ee-arg arg)) ;; (ee-eval (read (ee-last-sexp)))))))) -(defun ee-eval-sexp-eol (&optional arg) -"Go to the end of line, then run `ee-eval-last-sexp'. -By default, evaluate sexp before eol, and print value in minibuffer. -This is eev's variant of `C-e C-x C-e', and it can behave in -several different ways depending on the prefix argument ARG. -See: (find-eev-quick-intro \"`M-0 M-e'\") - -If ARG is: - nil: evaluate the sexp with `debug-on-error' turned off - 0: highlight the sexp temporarily - 1: show the sexp as a string - 2: show the target of the sexp in another window - 3: same, but also switch to the new window - 4: evaluate the sexp in debug mode - 5: run the sexp with `debug-on-error' turned on - 8: eval then pretty-print the result in another buffer - 9: a hack for testing `call-interactively' -other: set EE-ARG to ARG and eval (ee-last-sexp)." - (interactive "P") - (end-of-line) - (ee-eval-last-sexp arg)) - - - (provide 'eev-eval) diff --git a/eev-intro.el b/eev-intro.el index 58a274e..a052010 100644 --- a/eev-intro.el +++ b/eev-intro.el @@ -56,49 +56,50 @@ ;; Quick index: -;; «.find-intro-dual» (to "find-intro-dual") -;; «.find-eintro» (to "find-eintro") +;; «.find-intro-dual» (to "find-intro-dual") +;; «.find-eintro» (to "find-eintro") ;; -;; «.find-eev-quick-intro» (to "find-eev-quick-intro") -;; «.find-emacs-keys-intro» (to "find-emacs-keys-intro") -;; «.find-eev-install-intro» (to "find-eev-install-intro") -;; «.find-eev-intro» (to "find-eev-intro") -;; «.find-here-links-intro» (to "find-here-links-intro") -;; «.find-refining-intro» (to "find-refining-intro") +;; «.find-eev-quick-intro» (to "find-eev-quick-intro") +;; «.find-emacs-keys-intro» (to "find-emacs-keys-intro") +;; «.find-eev-install-intro» (to "find-eev-install-intro") +;; «.find-eev-intro» (to "find-eev-intro") +;; «.find-here-links-intro» (to "find-here-links-intro") +;; «.find-refining-intro» (to "find-refining-intro") ;; -;; «.find-eval-intro» (to "find-eval-intro") -;; «.find-links-conv-intro» (to "find-links-conv-intro") -;; «.find-links-intro» (to "find-links-intro") -;; «.find-eepitch-intro» (to "find-eepitch-intro") -;; «.find-wrap-intro» (to "find-wrap-intro") -;; «.find-eejump-intro» (to "find-eejump-intro") -;; «.find-anchors-intro» (to "find-anchors-intro") -;; «.find-code-c-d-intro» (to "find-code-c-d-intro") -;; «.find-pdf-like-intro» (to "find-pdf-like-intro") -;; «.find-brxxx-intro» (to "find-brxxx-intro") -;; «.find-psne-intro» (to "find-psne-intro") +;; «.find-eval-intro» (to "find-eval-intro") +;; «.find-links-conv-intro» (to "find-links-conv-intro") +;; «.find-links-intro» (to "find-links-intro") +;; «.find-eepitch-intro» (to "find-eepitch-intro") +;; «.find-wrap-intro» (to "find-wrap-intro") +;; «.find-eejump-intro» (to "find-eejump-intro") +;; «.find-anchors-intro» (to "find-anchors-intro") +;; «.find-code-c-d-intro» (to "find-code-c-d-intro") +;; «.find-pdf-like-intro» (to "find-pdf-like-intro") +;; «.find-brxxx-intro» (to "find-brxxx-intro") +;; «.find-psne-intro» (to "find-psne-intro") ;; -;; «.find-audiovideo-intro» (to "find-audiovideo-intro") -;; «.find-multiwindow-intro» (to "find-multiwindow-intro") -;; «.find-rcirc-intro» (to "find-rcirc-intro") -;; «.find-templates-intro» (to "find-templates-intro") -;; «.find-prepared-intro» (to "find-prepared-intro") -;; «.find-bounded-intro» (to "find-bounded-intro") -;; «.find-channels-intro» (to "find-channels-intro") -;; «.find-videos-intro» (to "find-videos-intro") - -;; «.find-defun-intro» (to "find-defun-intro") -;; «.find-emacs-intro» (to "find-emacs-intro") -;; «.find-org-intro» (to "find-org-intro") -;; «.find-escripts-intro» (to "find-escripts-intro") -;; «.find-git-intro» (to "find-git-intro") +;; «.find-audiovideo-intro» (to "find-audiovideo-intro") +;; «.find-multiwindow-intro» (to "find-multiwindow-intro") +;; «.find-rcirc-intro» (to "find-rcirc-intro") +;; «.find-templates-intro» (to "find-templates-intro") +;; «.find-prepared-intro» (to "find-prepared-intro") +;; «.find-bounded-intro» (to "find-bounded-intro") +;; «.find-channels-intro» (to "find-channels-intro") +;; «.find-videos-intro» (to "find-videos-intro") + +;; «.find-defun-intro» (to "find-defun-intro") +;; «.find-emacs-intro» (to "find-emacs-intro") +;; «.find-org-intro» (to "find-org-intro") +;; «.find-escripts-intro» (to "find-escripts-intro") +;; «.find-git-intro» (to "find-git-intro") ;; «.find-little-languages-intro» (to "find-little-languages-intro") ;; «.find-windows-beginner-intro» (to "find-windows-beginner-intro") ;; Videos: ;; «.find-three-main-keys-intro» (to "find-three-main-keys-intro") ;; -;; «.find-elisp-intro» (to "find-elisp-intro") +;; «.find-elisp-intro» (to "find-elisp-intro") +;; «.find-lexical-intro» (to "find-lexical-intro") ;; See: (find-anchors-intro) @@ -2591,50 +2592,51 @@ recommended reading order. These are the basic ones: 9. (find-psne-intro) 10. (find-rcirc-intro) 11. (find-elisp-intro) - 12. (find-eev-install-intro) + 12. (find-lexical-intro) + 13. (find-eev-install-intro) This is a very basic tutorial intended mainly for M$ Windows users: - 13. (find-windows-beginner-intro) + 14. (find-windows-beginner-intro) These ones explain ideas, conventions, and usage patterns: - 14. (find-escripts-intro) - 15. (find-links-conv-intro) + 15. (find-escripts-intro) + 16. (find-links-conv-intro) These are older and more technical versions of sections of the eev-quick-intro: - 16. (find-eval-intro) - 17. (find-links-intro) - 18. (find-brxxx-intro) - 19. (find-wrap-intro) - 20. (find-eejump-intro) - 21. (find-anchors-intro) - 22. (find-code-c-d-intro) + 17. (find-eval-intro) + 18. (find-links-intro) + 19. (find-brxxx-intro) + 20. (find-wrap-intro) + 21. (find-eejump-intro) + 22. (find-anchors-intro) + 23. (find-code-c-d-intro) These are etcs: - 23. (find-multiwindow-intro) - 24. (find-templates-intro) - 25. (find-org-intro) - 26. (find-git-intro) + 24. (find-multiwindow-intro) + 25. (find-templates-intro) + 26. (find-org-intro) + 27. (find-git-intro) These ones explain advanced features that require extra setup: - 27. (find-prepared-intro) - 28. (find-bounded-intro) - 29. (find-channels-intro) + 28. (find-prepared-intro) + 29. (find-bounded-intro) + 30. (find-channels-intro) This one is used in a video: - 30. (find-three-main-keys-intro) + 31. (find-three-main-keys-intro) These ones are obsolete: - 31. (find-emacs-intro) - 32. (find-defun-intro) + 32. (find-emacs-intro) + 33. (find-defun-intro) Item 25 is an index of old video tutorials, with scripts for downloading local copies of them and links to important positions @@ -13465,6 +13467,103 @@ will give you information about the current definition. +;;; _ _ _ +;;; | | _____ _(_) ___ __ _| | +;;; | |/ _ \ \/ / |/ __/ _` | | +;;; | | __/> <| | (_| (_| | | +;;; |_|\___/_/\_\_|\___\__,_|_| +;;; +;; «find-lexical-intro» (to ".find-lexical-intro") +;; Skel: (find-intro-links "lexical") + +(defun find-lexical-intro (&rest pos-spec-list) (interactive) + (let ((ee-buffer-name "*(find-lexical-intro)*")) + (apply 'find-eintro "\ +\(Re)generate: (find-lexical-intro) +Source code: (find-efunction 'find-lexical-intro) +More intros: (find-eev-quick-intro) + (find-eev-intro) + (find-eepitch-intro) +This buffer is _temporary_ and _editable_. +It is meant as both a tutorial and a sandbox. + + +This will become a _tutorial_ on lexical binding in the future, +and it will be a complement to this elisp tutorial: + (find-elisp-intro) +but at this moment I know far less about lexical binding that I +should, and this is just an embarassingly small collection of +links, tests, and examples... + +See: + (find-eevfile \"eev-template0.el\" \"intrinsically INCOMPATIBLE with lexical\") + + + +0. `ee-eval-lexical' +==================== +See: (find-eev \"eev-eval.el\" \"ee-eval-last-sexp\") + (find-eev \"eev-eval.el\" \"ee-eval-last-sexp\" \"11:\") + (find-eev \"eev-eval.el\" \"tools\") + (find-eev \"eev-eval.el\" \"tools\" \"ee-eval-lexical\") + (find-efunctiondescr 'eval) + +Try to evaluate this sexp with `M-e' and with `M-1 M-1 M-e': + + (let ((x 42)) + (defun foo () (* x x)) + (symbol-function 'foo)) + + + + +1. Creating closures +==================== +Long form: + + (eval '(let ((x 42)) (defun foo () (* x x))) 'lexical) + (eval '(let ((x 42)) (defun foo () (* x x))) nil) + (symbol-function 'foo) + +Short form: + + (let ((x 42)) + (defun foo () (* x x)) + (symbol-function 'foo)) + +Even shorter: + + (let ((x 42)) + (function (lambda foo () (* x x)))) + + + + +2. `letxgetx' +============= +See: (find-elnode \"Dynamic Binding\" \"defun getx\") + (find-elnode \"Lexical Binding\" \"defun getx\") + (find-elnode \"Void Variables\") + + (makunbound 'x) + (defun getx () x) + (getx) + (let ((x 1)) (getx)) + (defun letxgetx () (let ((x 1)) (getx))) + (letxgetx) + (symbol-function 'letxgetx) + + + +" pos-spec-list))) + +;; (find-lexical-intro) + + + + + + ;; «find-little-languages-intro» (to ".find-little-languages-intro") ;; Skel: (find-intro-links "little-languages")