From 7fc2559721bf90b079fc571771ae51caa91482c5 Mon Sep 17 00:00:00 2001 From: Kirill Ignatiev Date: Mon, 29 Dec 2014 17:56:08 -0500 Subject: [PATCH] Customizable settings for skipping questions 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. --- haskell-cabal.el | 15 ++++++++++----- haskell-commands.el | 35 +++++++++++++++++++++++------------ haskell-customize.el | 32 ++++++++++++++++++++++++++++++++ haskell-session.el | 12 ++++++++---- haskell.el | 5 +++-- 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/haskell-cabal.el b/haskell-cabal.el index 91c75051a..d6f3ee3fe 100644 --- a/haskell-cabal.el +++ b/haskell-cabal.el @@ -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") @@ -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. diff --git a/haskell-commands.el b/haskell-commands.el index e892a21d4..2a8adc0fc 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -22,6 +22,7 @@ (require 'haskell-font-lock) (require 'haskell-interactive-mode) (require 'haskell-session) +(require 'haskell-customize) (require 'highlight-uses-mode) ;;;###autoload @@ -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." diff --git a/haskell-customize.el b/haskell-customize.el index 8f5df6a04..7b9855217 100644 --- a/haskell-customize.el +++ b/haskell-customize.el @@ -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 diff --git a/haskell-session.el b/haskell-session.el index 2f9a03f62..9054685b1 100644 --- a/haskell-session.el +++ b/haskell-session.el @@ -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) diff --git a/haskell.el b/haskell.el index fc3104591..813ab3872 100644 --- a/haskell.el +++ b/haskell.el @@ -25,6 +25,7 @@ (require 'haskell-repl) (require 'haskell-load) (require 'haskell-commands) +(require 'haskell-customize) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Basic configuration hooks @@ -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