|
1 | 1 | ;;; haskell-utils.el --- General utility functions used by haskell-mode modules -*- lexical-binding: t -*-
|
2 | 2 |
|
3 |
| -;; Copyright (C) 2013 Herbert Valerio Riedel |
| 3 | +;; Copyright © 2013 Herbert Valerio Riedel |
| 4 | +;; 2016 Arthur Fayzrakhmanov |
4 | 5 |
|
5 | 6 | ;; Author: Herbert Valerio Riedel <[email protected]>
|
6 | 7 |
|
|
47 | 48 | (defun haskell-utils-read-directory-name (prompt default)
|
48 | 49 | "Read directory name and normalize to true absolute path.
|
49 | 50 | Refer to `read-directory-name' for the meaning of PROMPT and
|
50 |
| -DEFAULT. If `haskell-process-load-or-reload-prompt' is nil, accept `default'." |
| 51 | +DEFAULT. If `haskell-process-load-or-reload-prompt' is nil, |
| 52 | +accept `default'." |
51 | 53 | (let ((filename (file-truename (read-directory-name prompt default default))))
|
52 | 54 | (concat (replace-regexp-in-string "/$" "" filename) "/")))
|
53 | 55 |
|
@@ -105,25 +107,37 @@ only a single space. Then removes all newlines."
|
105 | 107 | (let ((s_ (replace-regexp-in-string "^\s+" " " s)))
|
106 | 108 | (replace-regexp-in-string "\n" "" s_)))
|
107 | 109 |
|
108 |
| -(defun haskell-utils-parse-repl-response (r) |
109 |
| - "Parse response R from REPL and return special kind of result. |
110 |
| -The result is the response string itself with the special property |
111 |
| -response-type added. |
112 |
| -
|
113 |
| -This property could be one of the following: |
| 110 | +(defun haskell-utils-repl-response-error-status (response) |
| 111 | + "Parse response REPL's RESPONSE for errors. |
| 112 | +Returns one of the following symbols: |
114 | 113 |
|
115 | 114 | + unknown-command
|
116 | 115 | + option-missing
|
117 | 116 | + interactive-error
|
118 |
| -+ success" |
119 |
| - (let ((first-line (car (split-string r "\n")))) |
| 117 | ++ no-error |
| 118 | +
|
| 119 | +*Warning*: this funciton covers only three kind of responses: |
| 120 | +
|
| 121 | +* \"unknown command …\" |
| 122 | + REPL missing requested command |
| 123 | +* \"<interactive>:3:5: …\" |
| 124 | + interactive REPL error |
| 125 | +* \"Couldn't guess that module name. Does it exist?\" |
| 126 | + (:type-at and maybe some other commands error) |
| 127 | +* *all other reposnses* are treated as success reposneses and |
| 128 | + 'no-error is returned." |
| 129 | + (let ((first-line (car (split-string response "\n" t)))) |
120 | 130 | (cond
|
121 |
| - ((string-match-p "^unknown command" first-line) 'unknown-command) |
122 |
| - ((string-match-p "^Couldn't guess that module name. Does it exist?" |
123 |
| - first-line) |
| 131 | + ((null first-line) 'no-error) |
| 132 | + ((string-match-p "^unknown command" first-line) |
| 133 | + 'unknown-command) |
| 134 | + ((string-match-p |
| 135 | + "^Couldn't guess that module name. Does it exist?" |
| 136 | + first-line) |
124 | 137 | 'option-missing)
|
125 |
| - ((string-match-p "^<interactive>:" first-line) 'interactive-error) |
126 |
| - (t 'success)))) |
| 138 | + ((string-match-p "^<interactive>:" first-line) |
| 139 | + 'interactive-error) |
| 140 | + (t 'no-error)))) |
127 | 141 |
|
128 | 142 | (defun haskell-utils-compose-type-at-command (pos)
|
129 | 143 | "Prepare :type-at command to be send to haskell process.
|
|
0 commit comments