Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

469 line
15 KiB

5 年之前
  1. ;;; haskell-customize.el --- Customization settings -*- lexical-binding: t -*-
  2. ;; Copyright (c) 2014 Chris Done. All rights reserved.
  3. ;; This file is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation; either version 3, or (at your option)
  6. ;; any later version.
  7. ;; This file is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'cl-lib)
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16. ;; Customization variables
  17. (defcustom haskell-process-load-or-reload-prompt nil
  18. "Nil means there will be no prompts on starting REPL. Defaults will be accepted."
  19. :type 'boolean
  20. :group 'haskell-interactive)
  21. ;;;###autoload
  22. (defgroup haskell nil
  23. "Major mode for editing Haskell programs."
  24. :link '(custom-manual "(haskell-mode)")
  25. :group 'languages
  26. :prefix "haskell-")
  27. (defvar haskell-mode-pkg-base-dir (file-name-directory load-file-name)
  28. "Package base directory of installed `haskell-mode'.
  29. Used for locating additional package data files.")
  30. (defcustom haskell-completing-read-function 'ido-completing-read
  31. "Default function to use for completion."
  32. :group 'haskell
  33. :type '(choice
  34. (function-item :tag "ido" :value ido-completing-read)
  35. (function-item :tag "helm" :value helm--completing-read-default)
  36. (function-item :tag "completing-read" :value completing-read)
  37. (function :tag "Custom function")))
  38. (defcustom haskell-process-type
  39. 'auto
  40. "The inferior Haskell process type to use.
  41. When set to 'auto (the default), the directory contents and
  42. available programs will be used to make a best guess at the
  43. process type:
  44. If the project directory or one of its parents contains a
  45. \"cabal.sandbox.config\" file, then cabal-repl will be used.
  46. If there's a \"stack.yaml\" file and the \"stack\" executable can
  47. be located, then stack-ghci will be used.
  48. Otherwise if there's a *.cabal file, cabal-repl will be used.
  49. If none of the above apply, ghci will be used."
  50. :type '(choice (const auto)
  51. (const ghci)
  52. (const cabal-repl)
  53. (const stack-ghci)
  54. (const cabal-new-repl))
  55. :group 'haskell-interactive)
  56. (defcustom haskell-process-wrapper-function
  57. #'identity
  58. "Wrap or transform haskell process commands using this function.
  59. Can be set to a custom function which takes a list of arguments
  60. and returns a possibly-modified list.
  61. The following example function arranges for all haskell process
  62. commands to be started in the current nix-shell environment:
  63. (lambda (argv) (append (list \"nix-shell\" \"-I\" \".\" \"--command\" )
  64. (list (mapconcat 'identity argv \" \"))))
  65. See Info Node `(emacs)Directory Variables' for a way to set this option on
  66. a per-project basis."
  67. :group 'haskell-interactive
  68. :type '(choice
  69. (function-item :tag "None" :value identity)
  70. (function :tag "Custom function")))
  71. (defcustom haskell-ask-also-kill-buffers
  72. t
  73. "Ask whether to kill all associated buffers when a session
  74. process is killed."
  75. :type 'boolean
  76. :group 'haskell-interactive)
  77. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  78. ;; Configuration
  79. (defcustom haskell-doc-prettify-types t
  80. "Replace some parts of types with Unicode characters like \"\"
  81. when showing type information about symbols."
  82. :group 'haskell-doc
  83. :type 'boolean
  84. :safe 'booleanp)
  85. (defvar haskell-process-ended-functions (list 'haskell-process-prompt-restart)
  86. "Hook for when the haskell process ends.")
  87. ;;;###autoload
  88. (defgroup haskell-interactive nil
  89. "Settings for REPL interaction via `haskell-interactive-mode'"
  90. :link '(custom-manual "(haskell-mode)haskell-interactive-mode")
  91. :group 'haskell)
  92. (defcustom haskell-process-path-ghci
  93. "ghci"
  94. "The path for starting ghci.
  95. This can either be a single string or a list of strings, where the
  96. first elements is a string and the remaining elements are arguments,
  97. which will be prepended to `haskell-process-args-ghci'."
  98. :group 'haskell-interactive
  99. :type '(choice string (repeat string)))
  100. (defcustom haskell-process-path-cabal
  101. "cabal"
  102. "Path to the `cabal' executable.
  103. This can either be a single string or a list of strings, where the
  104. first elements is a string and the remaining elements are arguments,
  105. which will be prepended to `haskell-process-args-cabal-repl'."
  106. :group 'haskell-interactive
  107. :type '(choice string (repeat string)))
  108. (defcustom haskell-process-path-stack
  109. "stack"
  110. "The path for starting stack.
  111. This can either be a single string or a list of strings, where the
  112. first elements is a string and the remaining elements are arguments,
  113. which will be prepended to `haskell-process-args-stack-ghci'."
  114. :group 'haskell-interactive
  115. :type '(choice string (repeat string)))
  116. (defcustom haskell-process-args-ghci
  117. '("-ferror-spans")
  118. "Any arguments for starting ghci."
  119. :group 'haskell-interactive
  120. :type '(repeat (string :tag "Argument")))
  121. (defcustom haskell-process-args-cabal-repl
  122. '("--ghc-option=-ferror-spans")
  123. "Additional arguments for `cabal repl' invocation.
  124. Note: The settings in `haskell-process-path-ghci' and
  125. `haskell-process-args-ghci' are not automatically reused as `cabal repl'
  126. currently invokes `ghc --interactive'. Use
  127. `--with-ghc=<path-to-executable>' if you want to use a different
  128. interactive GHC frontend; use `--ghc-option=<ghc-argument>' to
  129. pass additional flags to `ghc'."
  130. :group 'haskell-interactive
  131. :type '(repeat (string :tag "Argument")))
  132. (defcustom haskell-process-args-cabal-new-repl
  133. '("--ghc-option=-ferror-spans")
  134. "Additional arguments for `cabal new-repl' invocation.
  135. Note: The settings in `haskell-process-path-ghci' and
  136. `haskell-process-args-ghci' are not automatically reused as
  137. `cabal new-repl' currently invokes `ghc --interactive'. Use
  138. `--with-ghc=<path-to-executable>' if you want to use a different
  139. interactive GHC frontend; use `--ghc-option=<ghc-argument>' to
  140. pass additional flags to `ghc'."
  141. :group 'haskell-interactive
  142. :type '(repeat (string :tag "Argument")))
  143. (defcustom haskell-process-args-stack-ghci
  144. '("--ghci-options=-ferror-spans" "--no-build" "--no-load")
  145. "Additional arguments for `stack ghci' invocation."
  146. :group 'haskell-interactive
  147. :type '(repeat (string :tag "Argument")))
  148. (defcustom haskell-process-do-cabal-format-string
  149. ":!cd %s && %s"
  150. "The way to run cabal comands. It takes two arguments -- the directory and the command.
  151. See `haskell-process-do-cabal' for more details."
  152. :group 'haskell-interactive
  153. :type 'string)
  154. (defcustom haskell-process-log
  155. nil
  156. "Enable debug logging to \"*haskell-process-log*\" buffer."
  157. :type 'boolean
  158. :group 'haskell-interactive)
  159. (defcustom haskell-process-show-debug-tips
  160. t
  161. "Show debugging tips when starting the process."
  162. :type 'boolean
  163. :group 'haskell-interactive)
  164. (defcustom haskell-process-show-overlays
  165. t
  166. "Show in-buffer overlays for errors/warnings.
  167. Flycheck users might like to disable this."
  168. :type 'boolean
  169. :group 'haskell-interactive)
  170. (defcustom haskell-notify-p
  171. nil
  172. "Notify using notifications.el (if loaded)?"
  173. :type 'boolean
  174. :group 'haskell-interactive)
  175. (defcustom haskell-process-suggest-no-warn-orphans
  176. t
  177. "Suggest adding -fno-warn-orphans pragma to file when getting orphan warnings."
  178. :type 'boolean
  179. :group 'haskell-interactive)
  180. (defcustom haskell-process-suggest-hoogle-imports
  181. nil
  182. "Suggest to add import statements using Hoogle as a backend."
  183. :type 'boolean
  184. :group 'haskell-interactive)
  185. (defcustom haskell-process-suggest-hayoo-imports
  186. nil
  187. "Suggest to add import statements using Hayoo as a backend."
  188. :type 'boolean
  189. :group 'haskell-interactive)
  190. (defcustom haskell-process-hayoo-query-url
  191. "http://hayoo.fh-wedel.de/json/?query=%s"
  192. "Query url for json hayoo results."
  193. :type 'string
  194. :group 'haskell-interactive)
  195. (defcustom haskell-process-suggest-haskell-docs-imports
  196. nil
  197. "Suggest to add import statements using haskell-docs as a backend."
  198. :type 'boolean
  199. :group 'haskell-interactive)
  200. (defcustom haskell-process-suggest-add-package
  201. t
  202. "Suggest to add packages to your .cabal file when Cabal says it
  203. is a member of the hidden package, blah blah."
  204. :type 'boolean
  205. :group 'haskell-interactive)
  206. (defcustom haskell-process-suggest-language-pragmas
  207. t
  208. "Suggest adding LANGUAGE pragmas recommended by GHC."
  209. :type 'boolean
  210. :group 'haskell-interactive)
  211. (defcustom haskell-process-suggest-remove-import-lines
  212. nil
  213. "Suggest removing import lines as warned by GHC."
  214. :type 'boolean
  215. :group 'haskell-interactive)
  216. (defcustom haskell-process-suggest-overloaded-strings
  217. t
  218. "Suggest adding OverloadedStrings pragma to file when getting type mismatches with [Char]."
  219. :type 'boolean
  220. :group 'haskell-interactive)
  221. (defcustom haskell-process-check-cabal-config-on-load
  222. t
  223. "Check changes cabal config on loading Haskell files and
  224. restart the GHCi process if changed.."
  225. :type 'boolean
  226. :group 'haskell-interactive)
  227. (defcustom haskell-process-prompt-restart-on-cabal-change
  228. t
  229. "Ask whether to restart the GHCi process when the Cabal file
  230. has changed?"
  231. :type 'boolean
  232. :group 'haskell-interactive)
  233. (defcustom haskell-process-auto-import-loaded-modules
  234. nil
  235. "Auto import the modules reported by GHC to have been loaded?"
  236. :type 'boolean
  237. :group 'haskell-interactive)
  238. (defcustom haskell-process-reload-with-fbytecode
  239. nil
  240. "When using -fobject-code, auto reload with -fbyte-code (and
  241. then restore the -fobject-code) so that all module info and
  242. imports become available?"
  243. :type 'boolean
  244. :group 'haskell-interactive)
  245. (defcustom haskell-process-use-presentation-mode
  246. nil
  247. "Use presentation mode to show things like type info instead of
  248. printing to the message area."
  249. :type 'boolean
  250. :group 'haskell-interactive)
  251. (defcustom haskell-process-suggest-restart
  252. t
  253. "Suggest restarting the process when it has died"
  254. :type 'boolean
  255. :group 'haskell-interactive)
  256. (defcustom haskell-interactive-popup-errors
  257. t
  258. "Popup errors in a separate buffer."
  259. :type 'boolean
  260. :group 'haskell-interactive)
  261. (defcustom haskell-interactive-mode-collapse
  262. nil
  263. "Collapse printed results."
  264. :type 'boolean
  265. :group 'haskell-interactive)
  266. (defcustom haskell-interactive-types-for-show-ambiguous
  267. t
  268. "Show types when there's no Show instance or there's an
  269. ambiguous class constraint."
  270. :type 'boolean
  271. :group 'haskell-interactive)
  272. (defcustom haskell-interactive-prompt "λ> "
  273. "The prompt to use."
  274. :type 'string
  275. :group 'haskell-interactive)
  276. (defcustom haskell-interactive-prompt2 (replace-regexp-in-string
  277. "> $"
  278. "| "
  279. haskell-interactive-prompt)
  280. "The multi-line prompt to use.
  281. The default is `haskell-interactive-prompt' with the last > replaced with |."
  282. :type 'string
  283. :group 'haskell-interactive)
  284. (defcustom haskell-interactive-mode-eval-mode
  285. nil
  286. "Use the given mode's font-locking to render some text."
  287. :type '(choice function (const :tag "None" nil))
  288. :group 'haskell-interactive)
  289. (defcustom haskell-interactive-mode-hide-multi-line-errors
  290. nil
  291. "Hide collapsible multi-line compile messages by default."
  292. :type 'boolean
  293. :group 'haskell-interactive)
  294. (defcustom haskell-interactive-mode-delete-superseded-errors
  295. t
  296. "Whether to delete compile messages superseded by recompile/reloads."
  297. :type 'boolean
  298. :group 'haskell-interactive)
  299. (defcustom haskell-interactive-mode-include-file-name
  300. t
  301. "Include the file name of the module being compiled when
  302. printing compilation messages."
  303. :type 'boolean
  304. :group 'haskell-interactive)
  305. (defcustom haskell-interactive-mode-read-only
  306. t
  307. "Non-nil means most GHCi/haskell-interactive-mode output is read-only.
  308. This does not include the prompt. Configure
  309. `haskell-interactive-prompt-read-only' to change the prompt's
  310. read-only property."
  311. :type 'boolean
  312. :group 'haskell-interactive)
  313. (defcustom haskell-interactive-prompt-read-only
  314. haskell-interactive-mode-read-only
  315. "Non-nil means the prompt (and prompt2) is read-only."
  316. :type 'boolean
  317. :group 'haskell-interactive)
  318. (defcustom haskell-import-mapping
  319. '()
  320. "Support a mapping from module to import lines.
  321. E.g. '((\"Data.Map\" . \"import qualified Data.Map as M
  322. import Data.Map (Map)
  323. \"))
  324. This will import
  325. import qualified Data.Map as M
  326. import Data.Map (Map)
  327. when Data.Map is the candidate.
  328. "
  329. :type '(repeat (cons (string :tag "Module name")
  330. (string :tag "Import lines")))
  331. :group 'haskell-interactive)
  332. (defcustom haskell-language-extensions
  333. '()
  334. "Language extensions in use. Should be in format: -XFoo,
  335. -XNoFoo etc. The idea is that various tools written with HSE (or
  336. any haskell-mode code that needs to be aware of syntactical
  337. properties; such as an indentation mode) that don't know what
  338. extensions to use can use this variable. Examples: hlint,
  339. hindent, structured-haskell-mode, tool-de-jour, etc.
  340. You can set this per-project with a .dir-locals.el file"
  341. :group 'haskell
  342. :type '(repeat 'string))
  343. (defcustom haskell-stylish-on-save nil
  344. "Whether to run stylish-haskell on the buffer before saving.
  345. If this is true, `haskell-add-import' will not sort or align the
  346. imports."
  347. :group 'haskell
  348. :type 'boolean)
  349. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  350. ;; Accessor functions
  351. (defvar inferior-haskell-root-dir nil
  352. "The path which is considered as project root, this is determined by the
  353. presence of a *.cabal file or stack.yaml file or something similar.")
  354. (defun haskell-process-type ()
  355. "Return `haskell-process-type', or a guess if that variable is 'auto.
  356. This function also sets the `inferior-haskell-root-dir'"
  357. (let ((cabal-sandbox (locate-dominating-file default-directory
  358. "cabal.sandbox.config"))
  359. (stack (locate-dominating-file default-directory
  360. "stack.yaml"))
  361. (cabal (locate-dominating-file default-directory
  362. (lambda (d)
  363. (cl-find-if
  364. (lambda (f)
  365. (string-match-p ".\\.cabal\\'" f))
  366. (directory-files d))))))
  367. (if (eq 'auto haskell-process-type)
  368. (cond
  369. ;; User has explicitly initialized this project with cabal
  370. ((and cabal-sandbox
  371. (executable-find "cabal"))
  372. (setq inferior-haskell-root-dir cabal-sandbox)
  373. 'cabal-repl)
  374. ((and stack
  375. (executable-find "stack"))
  376. (setq inferior-haskell-root-dir stack)
  377. 'stack-ghci)
  378. ((and cabal
  379. (executable-find "cabal"))
  380. (setq inferior-haskell-root-dir cabal)
  381. 'cabal-repl)
  382. ((executable-find "ghc")
  383. (setq inferior-haskell-root-dir default-directory)
  384. 'ghci)
  385. ((executable-find "stack")
  386. (setq inferior-haskell-root-dir default-directory)
  387. 'stack-ghci)
  388. (t
  389. (error "Could not find any installation of GHC.")))
  390. haskell-process-type)))
  391. (provide 'haskell-customize)