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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions haskell-cabal.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

(require 'cl-lib)
(require 'haskell-utils)
(require 'haskell-customize)

(defconst haskell-cabal-general-fields
;; Extracted with (haskell-cabal-extract-fields-from-doc "general-fields")
Expand Down Expand Up @@ -183,11 +184,15 @@
(defun haskell-cabal-get-dir ()
"Get the Cabal dir for a new project. Various ways of figuring this out,
and indeed just prompting the user. Do them all."
(let* ((file (haskell-cabal-find-file))
(dir (when file (file-name-directory file))))
(haskell-utils-read-directory-name
(format "Cabal dir%s: " (if file (format " (guessed from %s)" (file-relative-name file)) ""))
dir)))
(let* ((file (or (haskell-cabal-find-file) (buffer-file-name)))
(dir (file-name-directory file)))
(cond
((and dir (eq haskell-cabal-use-directory t)) dir)
((stringp haskell-cabal-use-directory) haskell-cabal-use-directory)
(t
(haskell-utils-read-directory-name
(format "Cabal dir%s: " (if file (format " (guessed from %s)" (file-relative-name file)) ""))
dir)))))

(defun haskell-cabal-compute-checksum (dir)
"Compute MD5 checksum of package description file in DIR.
Expand Down
35 changes: 23 additions & 12 deletions haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
(require 'haskell-font-lock)
(require 'haskell-interactive-mode)
(require 'haskell-session)
(require 'haskell-customize)
(require 'highlight-uses-mode)

;;;###autoload
Expand Down Expand Up @@ -553,18 +554,28 @@ command from GHCi."

(defun haskell-session-pwd (session &optional change)
"Prompt for the current directory."
(or (unless change
(haskell-session-get session 'current-dir))
(progn (haskell-session-set-current-dir
session
(haskell-utils-read-directory-name
(if change "Change directory: " "Set current directory: ")
(or (haskell-session-get session 'current-dir)
(haskell-session-get session 'cabal-dir)
(if (buffer-file-name)
(file-name-directory (buffer-file-name))
"~/"))))
(haskell-session-get session 'current-dir))))
(or
(unless change
(haskell-session-get session 'current-dir))
(progn
(haskell-session-set-current-dir
session
(let ((guess (or (haskell-session-get session 'current-dir)
(haskell-session-get session 'cabal-dir)
(if (buffer-file-name)
(file-name-directory (buffer-file-name))
"~/"))))
(if change
(haskell-utils-read-directory-name "Change directory: " guess)
(cond
((and guess (eq haskell-session-current-directory t))
guess)
((stringp haskell-session-current-directory)
haskell-session-current-directory)
(t
(haskell-utils-read-directory-name
"Set current directory: " guess))))))
(haskell-session-get session 'current-dir))))

(defun haskell-process-change-dir (session process dir)
"Change the directory of the current process."
Expand Down
32 changes: 32 additions & 0 deletions haskell-customize.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,38 @@ a per-project basis."
:type 'boolean
:group 'haskell-interactive)

(defcustom haskell-session-ask-new-project
t
"Ask when starting a new project."
:type 'boolean
:safe 'booleanp
:group 'haskell-interactive)

(defcustom haskell-cabal-use-directory
nil
"Use this cabal directory (the default if t, ask if nil)."
:type '(choice (const :tag "Ask" nil)
(const :tag "Default" t)
(string :tag "Directory path"))
:safe 'booleanp
:group 'haskell-interactive)

(defcustom haskell-session-current-directory
nil
"Use this current directory (use buffer's directory if t, ask if nil)."
:type '(choice (const :tag "Ask" nil)
(const :tag "Guess from buffer" t)
(string :tag "Directory path"))
:safe 'booleanp
:group 'haskell-interactive)

(defcustom haskell-session-use-default-target
nil
"Whether to use the default target without asking."
:type 'boolean
:safe 'booleanp
:group 'haskell-interactive)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Configuration

Expand Down
12 changes: 8 additions & 4 deletions haskell-session.el
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,14 @@ If DONTCREATE is non-nil don't create a new session."
(defun haskell-session-target (s)
"Get the session build target."
(let* ((maybe-target (haskell-session-get s 'target))
(target (if maybe-target maybe-target
(let ((new-target
(read-string "build target (empty for default):")))
(haskell-session-set-target s new-target)))))
(target
(if maybe-target
maybe-target
(let ((new-target
(if haskell-session-use-default-target
""
(read-string "build target (empty for default):"))))
(haskell-session-set-target s new-target)))))
(if (not (string= target "")) target nil)))

(defun haskell-session-set-target (s target)
Expand Down
5 changes: 3 additions & 2 deletions haskell.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
(require 'haskell-repl)
(require 'haskell-load)
(require 'haskell-commands)
(require 'haskell-customize)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Basic configuration hooks
Expand Down Expand Up @@ -128,8 +129,8 @@
"Prompt to create a new project based on a guess from the nearest Cabal file."
(let ((name (haskell-session-default-name)))
(unless (haskell-session-lookup name)
(when (y-or-n-p (format "Start a new project named “%s”? "
name))
(when (or (not haskell-session-ask-new-project)
(y-or-n-p (format "Start a new project named “%s”? " name)))
(haskell-session-make name)))))

;;;###autoload
Expand Down