8000 read-char binding in sunrise-loop extension · Issue #89 · sunrise-commander/sunrise-commander · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

read-char binding in sunrise-loop extension #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lassik opened this issue Aug 11, 2019 · 4 comments
Open

read-char binding in sunrise-loop extension #89

lassik opened this issue Aug 11, 2019 · 4 comments

Comments

@lassik
Copy link
Contributor
lassik commented Aug 11, 2019

package-lint warns:

sunrise-loop.el:212:1: error: "read-char" doesn't start with package's prefix "sunrise-loop".

That function looks like this:

(defun sunrise-loop-cmd-loop ()
  "Main execution loop for the background Elisp interpreter."
  (sunrise-ad-disable "^sunrise-loop-")
  (defun read-char nil ?y) ;; Always answer "yes" to any prompt
  (let ((command) (signature))
    (while t
      (setq command (read))
      (setq signature (md5 (prin1-to-string command)))
      (condition-case description
          (progn
            (if sunrise-loop-debug
                (message "%s" (concat "[[Executing in background: "
                                      (prin1-to-string command) "]]")))
            (eval command)
            (message "[[Command successfully invoked in background]]"))
        (error (message "%s" (concat "[[*ERROR IN BACKGROUND JOB: "
                                     (prin1-to-string description) "*]]"))))
        (message "^%s" signature))))

So it seems it's using a Scheme-style defun-within-a-defun to rebind the standard read-char function to a different for the duration of sunrise-loop-cmd-loop. Then the standard read-char binding is restored at the end.

@zonuexe Can we use (let ((read-char (lambda (&rest _ignored) ?y))) ...) instead?

@lassik
Copy link
Contributor Author
lassik commented Aug 11, 2019

It's not going to be that simple because Emacs Lisp is a Lisp-2 with functions and variables in different namespaces, right? And cl-labels may make lexical bindings instead of dynamic bindings, so that may not work either.

@lassik
Copy link
Contributor Author
lassik commented Aug 11, 2019

This is a hack to answer "yes" to so ABD0 me prompts, so the cleanest approach would probably be to find which prompts those are, and see if there are official variables to suppress those prompts.

@lassik
Copy link
Contributor Author
lassik commented Aug 11, 2019

Taking a closer look at sunrise-loop.el, there is already lots of other advice like this:

(defadvice y-or-n-p (before sunrise-loop-advice-y-or-n-p activate)
  "Modify all confirmation request messages inside a loop scope."
  (when sunrise-loop-scope
    (setq (ad-get-arg 0)
          (replace-regexp-in-string
           "\?" " in the background? (overwrites ALWAYS!)" (ad-get-arg 0)))))

for specific purposes. I wonder which prompts are addressed by read-char that are not covered by the advice.

@lassik lassik added this to the Initial MELPA submission milestone Aug 11, 2019
@lassik
Copy link
Contributor Author
lassik commented Aug 22, 2019

@escherdragon Do you remember which prompts this line:

(defun read-char nil ?y) ;; Always answer "yes" to any prompt

was intended to answer "yes" to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0