Skip to content

Commit 42b1db5

Browse files
committed
Merge pull request #1116 from geraldus/gman/fix-820
Prevent haskell-doc-mode to hang Emacs during user input waiting
2 parents c15c844 + 5369eb6 commit 42b1db5

10 files changed

+444
-261
lines changed

haskell-cabal.el

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
;;; haskell-cabal.el --- Support for Cabal packages -*- lexical-binding: t -*-
22

3-
;; Copyright (C) 2007, 2008 Stefan Monnier
3+
;; Copyright © 2007, 2008 Stefan Monnier
4+
;; 2016 Arthur Fayzrakhmanov
45

56
;; Author: Stefan Monnier <[email protected]>
67

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

859860
(defun haskell-cabal-find-or-create-source-file ()
860-
"Open the source file this line refers to"
861+
"Open the source file this line refers to."
861862
(interactive)
862863
(let* ((src-dirs (append (haskell-cabal-subsection-entry-list
863864
(haskell-cabal-section) "hs-source-dirs")
@@ -868,17 +869,25 @@ Source names from main-is and c-sources sections are left untouched
868869
(let ((candidates
869870
(delq nil (mapcar
870871
(lambda (dir)
871-
(let ((file (haskell-cabal-join-paths base-dir dir filename)))
872+
(let ((file (haskell-cabal-join-paths base-dir
873+
dir
874+
filename)))
872875
(when (and (file-readable-p file)
873876
(not (file-directory-p file)))
874877
file)))
875878
src-dirs))))
876879
(if (null candidates)
877-
(let* ((src-dir (haskell-cabal-join-paths base-dir (or (car src-dirs) "")))
878-
(newfile (haskell-cabal-join-paths src-dir filename))
879-
(do-create-p (y-or-n-p (format "Create file %s ?" newfile))))
880-
(when do-create-p
881-
(find-file-other-window newfile )))
880+
(unwind-protect
881+
(progn
882+
(haskell-mode-toggle-interactive-prompt-state)
883+
(let* ((src-dir
884+
(haskell-cabal-join-paths base-dir
885+
(or (car src-dirs) "")))
886+
(newfile (haskell-cabal-join-paths src-dir filename))
887+
(do-create-p (y-or-n-p (format "Create file %s ?" newfile))))
888+
(when do-create-p
889+
(find-file-other-window newfile ))))
890+
(haskell-mode-toggle-interactive-prompt-state t))
882891
(find-file-other-window (car candidates)))))))
883892

884893

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

988997
(defun haskell-cabal-add-build-dependency (dependency &optional sort silent)
989-
"Add the given build dependency to every section"
998+
"Add the given DEPENDENCY to every section in cabal file.
999+
If SORT argument is given sort dependencies in section after update.
1000+
Pass SILENT argument to update all sections without asking user."
9901001
(haskell-cabal-map-sections
9911002
(lambda (section)
9921003
(when (haskell-cabal-source-section-p section)
993-
(when (or silent
994-
(y-or-n-p (format "Add dependency %s to %s section %s?"
995-
dependency
996-
(haskell-cabal-section-name section)
997-
(haskell-cabal-section-value section))))
998-
(haskell-cabal-section-add-build-dependency dependency sort section)
999-
nil)))))
1000-
1001-
(defun haskell-cabal-add-dependency (package &optional version no-prompt
1002-
sort silent)
1003-
"Add PACKAGE (and optionally suffix -VERSION) to the cabal
1004-
file. Prompts the user before doing so.
1005-
1004+
(unwind-protect
1005+
(progn
1006+
(when
1007+
(or silent
1008+
(y-or-n-p (format "Add dependency %s to %s section %s?"
1009+
dependency
1010+
(haskell-cabal-section-name section)
1011+
(haskell-cabal-section-value section))))
1012+
(haskell-cabal-section-add-build-dependency dependency
1013+
sort
1014+
section))
1015+
nil)
1016+
(haskell-mode-toggle-interactive-prompt-state t))))))
1017+
1018+
(defun haskell-cabal-add-dependency
1019+
(package &optional version no-prompt sort silent)
1020+
"Add PACKAGE to the cabal file.
10061021
If VERSION is non-nil it will be appended as a minimum version.
1007-
If NO-PROMPT is nil the minimum-version is read from the minibuffer
1008-
When SORT is non-nil the package entries are sorted afterwards
1009-
If SILENT ist nil the user is prompted for each source-section
1010-
"
1022+
If NO-PROMPT is nil the minimum package version is read from the
1023+
minibuffer. When SORT is non-nil the package entries are sorted
1024+
afterwards. If SILENT is non-nil the user is prompted for each
1025+
source-section."
10111026
(interactive
1012-
(list (read-from-minibuffer "Package entry: ")
1013-
nil t t nil))
1014-
(save-window-excursion
1015-
(find-file-other-window (haskell-cabal-find-file))
1016-
(let ((entry (if no-prompt package
1017-
(read-from-minibuffer
1018-
"Package entry: "
1019-
(concat package (if version (concat " >= " version) ""))))))
1020-
(haskell-cabal-add-build-dependency entry sort silent)
1021-
(when (or silent (y-or-n-p "Save cabal file?"))
1022-
(save-buffer)))))
1027+
(list (read-from-minibuffer "Package entry: ") nil t t nil))
1028+
(haskell-mode-toggle-interactive-prompt-state)
1029+
(unwind-protect
1030+
(save-window-excursion
1031+
(find-file-other-window (haskell-cabal-find-file))
1032+
(let ((entry (if no-prompt package
1033+
(read-from-minibuffer
1034+
"Package entry: "
1035+
(concat package
1036+
(if version (concat " >= " version) ""))))))
1037+
(haskell-cabal-add-build-dependency entry sort silent)
1038+
(when (or silent (y-or-n-p "Save cabal file?"))
1039+
(save-buffer))))
1040+
;; unwind
1041+
(haskell-mode-toggle-interactive-prompt-state t)))
10231042

10241043
(provide 'haskell-cabal)
10251044

haskell-commands.el

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
;;; specific commands such as show type signature, show info, haskell process
77
;;; commands and etc.
88

9-
;; Copyright (c) 2014 Chris Done. All rights reserved.
9+
;; Copyright © 2014 Chris Done. All rights reserved.
10+
;; 2016 Arthur Fayzrakhmanov
1011

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

2627
(require 'cl-lib)
2728
(require 'etags)
29+
(require 'haskell-mode)
2830
(require 'haskell-compat)
2931
(require 'haskell-process)
3032
(require 'haskell-font-lock)
@@ -740,39 +742,53 @@ inferior GHCi process."
740742
(interactive)
741743
(let ((session (haskell-interactive-session))
742744
(changed nil))
743-
(if (null (haskell-session-get session
744-
'ignored-files))
745+
(if (null (haskell-session-get session 'ignored-files))
745746
(message "Nothing to unignore!")
746-
(cl-loop for file in (haskell-session-get session
747-
'ignored-files)
748-
do (cl-case (read-event
749-
(propertize (format "Set permissions? %s (y, n, v: stop and view file)"
750-
file)
751-
'face 'minibuffer-prompt))
752-
(?y
753-
(haskell-process-unignore-file session file)
754-
(setq changed t))
755-
(?v
756-
(find-file file)
757-
(cl-return))))
758-
(when (and changed
759-
(y-or-n-p "Restart GHCi process now? "))
760-
(haskell-process-restart)))))
747+
(cl-loop for file in (haskell-session-get session 'ignored-files)
748+
do
749+
(haskell-mode-toggle-interactive-prompt-state)
750+
(unwind-protect
751+
(progn
752+
(cl-case
753+
(read-event
754+
(propertize
755+
(format "Set permissions? %s (y, n, v: stop and view file)"
756+
file)
757+
'face
758+
'minibuffer-prompt))
759+
(?y
760+
(haskell-process-unignore-file session file)
761+
(setq changed t))
762+
(?v
763+
(find-file file)
764+
(cl-return)))
765+
(when (and changed
766+
(y-or-n-p "Restart GHCi process now? "))
767+
(haskell-process-restart)))
768+
;; unwind
769+
(haskell-mode-toggle-interactive-prompt-state t))))))
761770

762771
;;;###autoload
763772
(defun haskell-session-change-target (target)
764773
"Set the build TARGET for cabal REPL."
765774
(interactive
766775
(list
767-
(completing-read "New build target: " (haskell-cabal-enum-targets)
768-
nil nil nil 'haskell-cabal-targets-history)))
776+
(completing-read "New build target: "
777+
(haskell-cabal-enum-targets)
778+
nil
779+
nil
780+
nil
781+
'haskell-cabal-targets-history)))
769782
(let* ((session haskell-session)
770783
(old-target (haskell-session-get session 'target)))
771784
(when session
772785
(haskell-session-set-target session target)
773-
(when (and (not (string= old-target target))
774-
(y-or-n-p "Target changed, restart haskell process?"))
775-
(haskell-process-start session)))))
786+
(when (not (string= old-target target))
787+
(haskell-mode-toggle-interactive-prompt-state)
788+
(unwind-protect
789+
(when (y-or-n-p "Target changed, restart haskell process?")
790+
(haskell-process-start session)))
791+
(haskell-mode-toggle-interactive-prompt-state t)))))
776792

777793
;;;###autoload
778794
(defun haskell-mode-stylish-buffer ()

haskell-debug.el

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
;;; haskell-debug.el --- Debugging mode via GHCi -*- lexical-binding: t -*-
22

3-
;; Copyright (c) 2014 Chris Done. All rights reserved.
3+
;; Copyright © 2014 Chris Done. All rights reserved.
4+
;; 2016 Arthur Fayzrakhmanov
45

56
;; This file is free software; you can redistribute it and/or modify
67
;; it under the terms of the GNU General Public License as published by
@@ -223,13 +224,16 @@
223224
(cond
224225
((get-text-property (point) 'break)
225226
(let ((break (get-text-property (point) 'break)))
226-
(when (y-or-n-p (format "Delete breakpoint #%d?"
227-
(plist-get break :number)))
228-
(haskell-process-queue-sync-request
229-
(haskell-debug-process)
230-
(format ":delete %d"
231-
(plist-get break :number)))
232-
(haskell-debug/refresh))))))
227+
(haskell-mode-toggle-interactive-prompt-state)
228+
(unwind-protect
229+
(when (y-or-n-p (format "Delete breakpoint #%d?"
230+
(plist-get break :number)))
231+
(haskell-process-queue-sync-request
232+
(haskell-debug-process)
233+
(format ":delete %d"
234+
(plist-get break :number)))
235+
(haskell-debug/refresh))
236+
(haskell-mode-toggle-interactive-prompt-state t))))))
233237

234238
(defun haskell-debug/trace ()
235239
"Trace the expression."
@@ -272,16 +276,20 @@
272276
(t
273277
(if context
274278
(message "Computation finished.")
275-
(when (y-or-n-p "Computation completed without breaking. Reload the module and retry?")
276-
(message "Reloading and resetting breakpoints...")
277-
(haskell-interactive-mode-reset-error (haskell-debug-session))
278-
(cl-loop for break in breakpoints
279-
do (haskell-process-queue-sync-request
280-
(haskell-debug-process)
281-
(concat ":load " (plist-get break :path))))
282-
(cl-loop for break in breakpoints
283-
do (haskell-debug-break break))
284-
(haskell-debug/step expr)))))))))
279+
(progn
280+
(haskell-mode-toggle-interactive-prompt-state)
281+
(unwind-protect
282+
(when (y-or-n-p "Computation completed without breaking. Reload the module and retry?")
283+
(message "Reloading and resetting breakpoints...")
284+
(haskell-interactive-mode-reset-error (haskell-debug-session))
285+
(cl-loop for break in breakpoints
286+
do (haskell-process-queue-sync-request
287+
(haskell-debug-process)
288+
(concat ":load " (plist-get break :path))))
289+
(cl-loop for break in breakpoints
290+
do (haskell-debug-break break))
291+
(haskell-debug/step expr))
292+
(haskell-mode-toggle-interactive-prompt-state t))))))))))
285293
(haskell-debug/refresh)))
286294

287295
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

haskell-doc.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
;;; haskell-doc.el --- show function types in echo area -*- coding: utf-8; lexical-binding: t -*-
22

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

67
;; Author: Hans-Wolfgang Loidl <[email protected]>
78
;; Temporary Maintainer and Hacker: Graeme E Moss <[email protected]>
@@ -1424,6 +1425,7 @@ is not."
14241425
This function is run by an idle timer to print the type
14251426
automatically if `haskell-doc-mode' is turned on."
14261427
(and haskell-doc-mode
1428+
(not haskell-mode-interactive-prompt-state)
14271429
(not (eobp))
14281430
(not executing-kbd-macro)
14291431
;; Having this mode operate in the minibuffer makes it impossible to

haskell-hoogle.el

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
;;; haskell-hoogle.el --- Look up Haskell documentation via hoogle or hayoo -*- lexical-binding: t; -*-
22

3-
;; Copyright (C) 2015 Steve Purcell
3+
;; Copyright © 2015 Steve Purcell
4+
;; 2016 Arthur Fayzrakhmanov
45

56
;; Author: Steve Purcell <[email protected]>
67
;; Keywords: docs
@@ -113,10 +114,12 @@ is asked to show extra info for the items matching QUERY.."
113114
(browse-url (format "http://localhost:%i/?hoogle=%s"
114115
haskell-hoogle-port-number
115116
(read-string "hoogle: " (haskell-ident-at-point))))
116-
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
117-
(haskell-hoogle-start-server))))
117+
(haskell-mode-toggle-interactive-prompt-state)
118+
(unwind-protect
119+
(when (y-or-n-p "Hoogle server not running, start hoogle server? ")
120+
(haskell-hoogle-start-server))
121+
(haskell-mode-toggle-interactive-prompt-state t))))
118122

119-
120123

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

0 commit comments

Comments
 (0)