help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making ielm behave like a shell (getting to previous commands using


From: Jean Louis
Subject: Re: Making ielm behave like a shell (getting to previous commands using the up-arrow key)
Date: Thu, 17 Dec 2020 12:06:57 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* steve-humphreys@gmx.com <steve-humphreys@gmx.com> [2020-12-17 08:20]:
> ielm should be described in "An Introduction to Programming in Emacs
> Lisp".  It is very useful when starting with lisp.

I am often using M-: to evaluate in one line and ielm rarely.

When I need to evaluate I also write it in any buffer and just
evaluate with C-x C-e, including in text buffers.

Then I also use `setq' dynamically many times when debugging:

Then I may do in first step this and get my-var as 1, it becomes
global but I don't care.

(defun my-function ()
  (let* ((setq my-var 1)
         (new (+ my-var 2)))
    new))

Then I do this and evaluate new to be 4, it becomes global, but I don't care.

(defun my-function ()
  (let* ((my-var 1)
         (setq new (+ my-var 2)))
    new))

As that is one way of debugging. But I think I will make function
to evaluate those lines without inserting `setq' and deleting
`setq' afterwards as it is repetitive.

(defun eval-with-setq-sexp ()
  (interactive)
  (let* ((sexp (thing-at-point 'list))
         (end (length sexp))
         (just-do (set-text-properties 0 end nil sexp))
         (sexp (replace-regexp-in-string "^(" "(setq " sexp)))
  (message "%s" (eval (car (read-from-string sexp))))))

Then I could just bind this to a key and move into various parts
of (let FORM) to evaluate those variables when debugging. But I
guess I have to move to beginning or first variable like `a' or
`b' here below:

(global-set-key (kbd "<f5>") 'eval-with-setq-sexp)

(let ((a 1) ; <-- go on a and press your key like F5 and A becomes 1
      (something-else "Here") ; <-- on `something-else' with F5 it becomes 
"Here"
      (b (+ 2 1)))) ; <-- on `b' F5 assigns value 3 to b

Spares me time.

I also use instrumenting of a function when I wish to quickly
debug something. But too often I used (setq slow motion writing
it and typing. I will now switch to key bound debugging with the
above function.

Jean



reply via email to

[Prev in Thread] Current Thread [Next in Thread]