Skip to content

Prevent haskell-doc-mode to hang Emacs during user input waiting #1116

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

Merged
merged 2 commits into from
Jan 30, 2016
Merged
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
93 changes: 56 additions & 37 deletions haskell-cabal.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; haskell-cabal.el --- Support for Cabal packages -*- lexical-binding: t -*-

;; Copyright (C) 2007, 2008 Stefan Monnier
;; Copyright © 2007, 2008 Stefan Monnier
;; 2016 Arthur Fayzrakhmanov

;; Author: Stefan Monnier <monnier@iro.umontreal.ca>

Expand Down Expand Up @@ -857,7 +858,7 @@ Source names from main-is and c-sources sections are left untouched
)

(defun haskell-cabal-find-or-create-source-file ()
"Open the source file this line refers to"
"Open the source file this line refers to."
(interactive)
(let* ((src-dirs (append (haskell-cabal-subsection-entry-list
(haskell-cabal-section) "hs-source-dirs")
Expand All @@ -868,17 +869,25 @@ Source names from main-is and c-sources sections are left untouched
(let ((candidates
(delq nil (mapcar
(lambda (dir)
(let ((file (haskell-cabal-join-paths base-dir dir filename)))
(let ((file (haskell-cabal-join-paths base-dir
dir
filename)))
(when (and (file-readable-p file)
(not (file-directory-p file)))
file)))
src-dirs))))
(if (null candidates)
(let* ((src-dir (haskell-cabal-join-paths base-dir (or (car src-dirs) "")))
(newfile (haskell-cabal-join-paths src-dir filename))
(do-create-p (y-or-n-p (format "Create file %s ?" newfile))))
(when do-create-p
(find-file-other-window newfile )))
(unwind-protect
(progn
(haskell-mode-toggle-interactive-prompt-state)
(let* ((src-dir
(haskell-cabal-join-paths base-dir
(or (car src-dirs) "")))
(newfile (haskell-cabal-join-paths src-dir filename))
(do-create-p (y-or-n-p (format "Create file %s ?" newfile))))
(when do-create-p
(find-file-other-window newfile ))))
(haskell-mode-toggle-interactive-prompt-state t))
(find-file-other-window (car candidates)))))))


Expand Down Expand Up @@ -986,40 +995,50 @@ Source names from main-is and c-sources sections are left untouched
'haskell-cabal-sort-lines-key-fun)))))))

(defun haskell-cabal-add-build-dependency (dependency &optional sort silent)
"Add the given build dependency to every section"
"Add the given DEPENDENCY to every section in cabal file.
If SORT argument is given sort dependencies in section after update.
Pass SILENT argument to update all sections without asking user."
(haskell-cabal-map-sections
(lambda (section)
(when (haskell-cabal-source-section-p section)
(when (or silent
(y-or-n-p (format "Add dependency %s to %s section %s?"
dependency
(haskell-cabal-section-name section)
(haskell-cabal-section-value section))))
(haskell-cabal-section-add-build-dependency dependency sort section)
nil)))))

(defun haskell-cabal-add-dependency (package &optional version no-prompt
sort silent)
"Add PACKAGE (and optionally suffix -VERSION) to the cabal
file. Prompts the user before doing so.

(unwind-protect
(progn
(when
(or silent
(y-or-n-p (format "Add dependency %s to %s section %s?"
dependency
(haskell-cabal-section-name section)
(haskell-cabal-section-value section))))
(haskell-cabal-section-add-build-dependency dependency
sort
section))
nil)
(haskell-mode-toggle-interactive-prompt-state t))))))

(defun haskell-cabal-add-dependency
(package &optional version no-prompt sort silent)
"Add PACKAGE to the cabal file.
If VERSION is non-nil it will be appended as a minimum version.
If NO-PROMPT is nil the minimum-version is read from the minibuffer
When SORT is non-nil the package entries are sorted afterwards
If SILENT ist nil the user is prompted for each source-section
"
If NO-PROMPT is nil the minimum package version is read from the
minibuffer. When SORT is non-nil the package entries are sorted
afterwards. If SILENT is non-nil the user is prompted for each
source-section."
(interactive
(list (read-from-minibuffer "Package entry: ")
nil t t nil))
(save-window-excursion
(find-file-other-window (haskell-cabal-find-file))
(let ((entry (if no-prompt package
(read-from-minibuffer
"Package entry: "
(concat package (if version (concat " >= " version) ""))))))
(haskell-cabal-add-build-dependency entry sort silent)
(when (or silent (y-or-n-p "Save cabal file?"))
(save-buffer)))))
(list (read-from-minibuffer "Package entry: ") nil t t nil))
(haskell-mode-toggle-interactive-prompt-state)
(unwind-protect
(save-window-excursion
(find-file-other-window (haskell-cabal-find-file))
(let ((entry (if no-prompt package
(read-from-minibuffer
"Package entry: "
(concat package
(if version (concat " >= " version) ""))))))
(haskell-cabal-add-build-dependency entry sort silent)
(when (or silent (y-or-n-p "Save cabal file?"))
(save-buffer))))
;; unwind
(haskell-mode-toggle-interactive-prompt-state t)))

(provide 'haskell-cabal)

Expand Down
62 changes: 39 additions & 23 deletions haskell-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
;;; specific commands such as show type signature, show info, haskell process
;;; commands and etc.

;; Copyright (c) 2014 Chris Done. All rights reserved.
;; Copyright © 2014 Chris Done. All rights reserved.
;; 2016 Arthur Fayzrakhmanov

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand All @@ -25,6 +26,7 @@

(require 'cl-lib)
(require 'etags)
(require 'haskell-mode)
(require 'haskell-compat)
(require 'haskell-process)
(require 'haskell-font-lock)
Expand Down Expand Up @@ -740,39 +742,53 @@ inferior GHCi process."
(interactive)
(let ((session (haskell-interactive-session))
(changed nil))
(if (null (haskell-session-get session
'ignored-files))
(if (null (haskell-session-get session 'ignored-files))
(message "Nothing to unignore!")
(cl-loop for file in (haskell-session-get session
'ignored-files)
do (cl-case (read-event
(propertize (format "Set permissions? %s (y, n, v: stop and view file)"
file)
'face 'minibuffer-prompt))
(?y
(haskell-process-unignore-file session file)
(setq changed t))
(?v
(find-file file)
(cl-return))))
(when (and changed
(y-or-n-p "Restart GHCi process now? "))
(haskell-process-restart)))))
(cl-loop for file in (haskell-session-get session 'ignored-files)
do
(haskell-mode-toggle-interactive-prompt-state)
(unwind-protect
(progn
(cl-case
(read-event
(propertize
(format "Set permissions? %s (y, n, v: stop and view file)"
file)
'face
'minibuffer-prompt))
(?y
(haskell-process-unignore-file session file)
(setq changed t))
(?v
(find-file file)
(cl-return)))
(when (and changed
(y-or-n-p "Restart GHCi process now? "))
(haskell-process-restart)))
;; unwind
(haskell-mode-toggle-interactive-prompt-state t))))))

;;;###autoload
(defun haskell-session-change-target (target)
"Set the build TARGET for cabal REPL."
(interactive
(list
(completing-read "New build target: " (haskell-cabal-enum-targets)
nil nil nil 'haskell-cabal-targets-history)))
(completing-read "New build target: "
(haskell-cabal-enum-targets)
nil
nil
nil
'haskell-cabal-targets-history)))
(let* ((session haskell-session)
(old-target (haskell-session-get session 'target)))
(when session
(haskell-session-set-target session target)
(when (and (not (string= old-target target))
(y-or-n-p "Target changed, restart haskell process?"))
(haskell-process-start session)))))
(when (not (string= old-target target))
(haskell-mode-toggle-interactive-prompt-state)
(unwind-protect
(when (y-or-n-p "Target changed, restart haskell process?")
(haskell-process-start session)))
(haskell-mode-toggle-interactive-prompt-state t)))))

;;;###autoload
(defun haskell-mode-stylish-buffer ()
Expand Down
44 changes: 26 additions & 18 deletions haskell-debug.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; haskell-debug.el --- Debugging mode via GHCi -*- lexical-binding: t -*-

;; Copyright (c) 2014 Chris Done. All rights reserved.
;; Copyright © 2014 Chris Done. All rights reserved.
;; 2016 Arthur Fayzrakhmanov

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -223,13 +224,16 @@
(cond
((get-text-property (point) 'break)
(let ((break (get-text-property (point) 'break)))
(when (y-or-n-p (format "Delete breakpoint #%d?"
(plist-get break :number)))
(haskell-process-queue-sync-request
(haskell-debug-process)
(format ":delete %d"
(plist-get break :number)))
(haskell-debug/refresh))))))
(haskell-mode-toggle-interactive-prompt-state)
(unwind-protect
(when (y-or-n-p (format "Delete breakpoint #%d?"
(plist-get break :number)))
(haskell-process-queue-sync-request
(haskell-debug-process)
(format ":delete %d"
(plist-get break :number)))
(haskell-debug/refresh))
(haskell-mode-toggle-interactive-prompt-state t))))))

(defun haskell-debug/trace ()
"Trace the expression."
Expand Down Expand Up @@ -272,16 +276,20 @@
(t
(if context
(message "Computation finished.")
(when (y-or-n-p "Computation completed without breaking. Reload the module and retry?")
(message "Reloading and resetting breakpoints...")
(haskell-interactive-mode-reset-error (haskell-debug-session))
(cl-loop for break in breakpoints
do (haskell-process-queue-sync-request
(haskell-debug-process)
(concat ":load " (plist-get break :path))))
(cl-loop for break in breakpoints
do (haskell-debug-break break))
(haskell-debug/step expr)))))))))
(progn
(haskell-mode-toggle-interactive-prompt-state)
(unwind-protect
(when (y-or-n-p "Computation completed without breaking. Reload the module and retry?")
(message "Reloading and resetting breakpoints...")
(haskell-interactive-mode-reset-error (haskell-debug-session))
(cl-loop for break in breakpoints
do (haskell-process-queue-sync-request
(haskell-debug-process)
(concat ":load " (plist-get break :path))))
(cl-loop for break in breakpoints
do (haskell-debug-break break))
(haskell-debug/step expr))
(haskell-mode-toggle-interactive-prompt-state t))))))))))
(haskell-debug/refresh)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
6 changes: 4 additions & 2 deletions haskell-doc.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
;;; haskell-doc.el --- show function types in echo area -*- coding: utf-8; lexical-binding: t -*-

;; Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
;; Copyright (C) 1997 Hans-Wolfgang Loidl
;; Copyright © 2004, 2005, 2006, 2007, 2009, 2016 Free Software Foundation, Inc.
;; Copyright © 1997 Hans-Wolfgang Loidl
;; 2016 Arthur Fayzrakhmanov

;; Author: Hans-Wolfgang Loidl <hwloidl@dcs.glasgow.ac.uk>
;; Temporary Maintainer and Hacker: Graeme E Moss <gem@cs.york.ac.uk>
Expand Down Expand Up @@ -1424,6 +1425,7 @@ is not."
This function is run by an idle timer to print the type
automatically if `haskell-doc-mode' is turned on."
(and haskell-doc-mode
(not haskell-mode-interactive-prompt-state)
(not (eobp))
(not executing-kbd-macro)
;; Having this mode operate in the minibuffer makes it impossible to
Expand Down
11 changes: 7 additions & 4 deletions haskell-hoogle.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; haskell-hoogle.el --- Look up Haskell documentation via hoogle or hayoo -*- lexical-binding: t; -*-

;; Copyright (C) 2015 Steve Purcell
;; Copyright © 2015 Steve Purcell
;; 2016 Arthur Fayzrakhmanov

;; Author: Steve Purcell <steve@sanityinc.com>
;; Keywords: docs
Expand Down Expand Up @@ -113,10 +114,12 @@ is asked to show extra info for the items matching QUERY.."
(browse-url (format "http://localhost:%i/?hoogle=%s"
haskell-hoogle-port-number
(read-string "hoogle: " (haskell-ident-at-point))))
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
(haskell-hoogle-start-server))))
(haskell-mode-toggle-interactive-prompt-state)
(unwind-protect
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
(haskell-hoogle-start-server))
(haskell-mode-toggle-interactive-prompt-state t))))



(defcustom haskell-hayoo-url "http://hayoo.fh-wedel.de/?query=%s"
"Default value for hayoo web site."
Expand Down
Loading