Skip to content

Customizable settings for skipping questions #409

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

Closed
wants to merge 1 commit into from

Conversation

ikirill
Copy link
Contributor

@ikirill ikirill commented Dec 29, 2014

Creating a new session in a simple project asks many questions for which
the default answers may be absolute fine. This change adds four
customizable variables, and setting them (in file-local and dir-local
variables) would allow questions to be skipped during session creation.

See #407

For example (to use file-local variables; dir-local variables would work too; here t means "default"):

-- Local Variables:
-- haskell-session-ask-new-project: nil
-- haskell-cabal-use-directory: t
-- haskell-session-current-directory: t
-- haskell-session-use-default-target: t
-- End:

Creating a new session in a simple project asks many questions for which
the default answers may be absolute fine.  This change adds four
customizable variables, and setting them (in file-local and dir-local
variables) would allow questions to be skipped during session creation.
@chrisdone
Copy link
Member

I've been thinking to revisit the prompting stuff and it make it not on by default.

@purcell
Copy link
Member

purcell commented Dec 30, 2014

Do you mean that there would simply be an error when using commands which require a session? If so, I personally think that would be better.

@chrisdone
Copy link
Member

Well, rather that the prompting when making a new project wouldn't happen and instead it would just make the general assumptions and you'd customize them later if necessary.

@purcell
Copy link
Member

purcell commented Dec 30, 2014

Aha. Well, that's moving in the opposite direction from what I was suggesting. :-)

I'm a bit wary of sessions getting started automatically, particularly if it happens almost silently using defaults. When that sort of thing goes wrong, it's harder to track down in that sort of scheme than with the alternative of making everything explicit while allowing experts to streamline it.

But that's not to say it couldn't work beautifully.

@chrisdone
Copy link
Member

I was thinking to retain something like the above haskell-session-ask-new-project, but I don't have much time to expand presently.

@ikirill
Copy link
Contributor Author

ikirill commented Dec 30, 2014

If haskell-mode will make assumptions, it should show those assumptions to the user by, say, printing them to the session buffer. There also should be some way to override those assumptions with local variables, too.

@gracjan
Copy link
Contributor

gracjan commented Mar 15, 2015

As I read comments here I see that there is general consensus of not pulling these 4 vars in and rethinking interaction with user again, am I right?

(Do not hesitate to reopen this issue if I misunderstood the intention).

@vlatkoB
Copy link
Contributor

vlatkoB commented Jul 20, 2015

I've made an ugly workaround for this, but the proper way, IMHO, would be to adapt haskell-process-load-file function (or create another one) to accept an argument "to ask or not to ask". So we can bind both to different keys, and have everyone happy.
Would that be acceptable?

Workaround:

;; Start Haskell Interactive mode without prompts
(defun haskell-session-new-assume-from-cabal-no-prompt ()
  (let ((name (haskell-session-default-name)))
    (unless (haskell-session-lookup name)
      (haskell-session-make name))))
(defun haskell-utils-read-directory-name-no-prompt (prompt default)
  (let ((filename (file-truename default)))
    (concat (replace-regexp-in-string "/$" "" filename) "/")))
(defun haskell-session-target-no-prompt (s)
  (let* ((maybe-target (haskell-session-get s 'target))
    (target (if maybe-target maybe-target (haskell-session-set-target s ""))))
    (if (not (string= target "")) target nil)))

;; Auto-accept default values on interactive mode
(fset 'haskell-session-new-assume-from-cabal 'haskell-session-new-assume-from-cabal-no-prompt)
(fset 'haskell-utils-read-directory-name     'haskell-utils-read-directory-name-no-prompt)
(fset 'haskell-session-target                'haskell-session-target-no-prompt)

@gracjan
Copy link
Contributor

gracjan commented Jul 20, 2015 via email

@vlatkoB
Copy link
Contributor

vlatkoB commented Jul 20, 2015

Should behave something like this:

(defun haskell-process-load-or-reload-ad (&optional arg)
  "If ARG is set (C-u), starts session with prompts.
If ARG is not set, accepts defaults without prompting user."
  (interactive "P")
  (if arg
      (haskell-process-load-or-reload)
    (progn
      (advice-add 'haskell-session-new-assume-from-cabal
        :override #'haskell-session-new-assume-from-cabal-no-prompt)
      (advice-add 'haskell-utils-read-directory-name
        :override #'haskell-utils-read-directory-name-no-prompt)
      (advice-add 'haskell-session-target
        :override #'haskell-session-target-no-prompt)
      (haskell-process-load-or-reload)
      (advice-remove 'haskell-session-new-assume-from-cabal
                    #'haskell-session-new-assume-from-cabal-no-prompt)
      (advice-remove 'haskell-utils-read-directory-name
                    #'haskell-utils-read-directory-name-no-prompt)
      (advice-remove 'haskell-session-target
                    #'haskell-session-target-no-prompt))))

This is, of course, just for testing purpose. This depends heavily on the three advised functions above. Those functions are quite scattered and passing an ARG around would not be the best solution. I'm very fresh in emacs, so I do not know if a temporary global would be acceptable.

(defvar do-not-ask nil)
(defun haskell-process-load-or-reload-ad ()
  (interactive)
  (ignore-errors
    (progn
      (setq do-not-ask t)
      (haskell-process-load-or-reload)))
  (setq do-not-ask nil))

and rewrite those three functions to check for do-not-ask.

@purcell
Copy link
Member

purcell commented Jul 21, 2015

Sorry, no time to comment fully here, but I wanted to point out that the new-style advice functions aren't available in all the Emacs versions we currently support.

@vlatkoB
Copy link
Contributor

vlatkoB commented Jul 21, 2015

I made a solution with a variable haskell-process-load-or-reload-p to enable/disable prompts on starting REPL. Default value is t, so no changes in current flow. If user changes it to nil, no prompts appear and defaults are accepted.

The three above mentioned functions are slightly changed just to check the value of haskell-process-load-or-reload-p, and accordingly prompt for a value or accept defaults. No advices.

If you think it's useful, I can make PR.

@gracjan
Copy link
Contributor

gracjan commented Jul 21, 2015 via email

@vlatkoB
Copy link
Contributor

vlatkoB commented Jul 21, 2015

Done

Edit: Link to PR.

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

Successfully merging this pull request may close these issues.

5 participants