Skip to content
This repository was archived by the owner on Apr 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
839fa3a
elisp: Add option to jump to first error after save
DanielG Dec 29, 2015
26b9880
elisp: Cleanup customs
DanielG Dec 29, 2015
bb46244
elisp: Support jumping to other files on check [broken]
DanielG Dec 30, 2015
89ad7dc
elisp: Fix some errors
DanielG Dec 30, 2015
c5038ac
elisp: Fix more errors
DanielG Dec 30, 2015
3a7372e
elisp: Make ghc-process-running nil even on error
DanielG Dec 30, 2015
0b839ef
elisp: fix error
DanielG Sep 8, 2016
e501148
elisp: fix goto-first-error jumping to last error
DanielG Sep 8, 2016
63c13cb
elisp: don't jump to error if point moved since check
DanielG Sep 8, 2016
79db0c1
elisp: remove some dead code
DanielG Sep 8, 2016
be2947a
elisp: Start cleaning up ghc-mod's Emacs frontend
DanielG Aug 15, 2014
9e110dd
elisp: Give ghc-mod-mode a sexy, short unicode lighter.
DanielG Aug 30, 2014
31965e1
elisp: Dectivate save-buffer advice on mode deinit
DanielG Aug 30, 2014
1bac9f1
elisp: Attach deprication notices to ghc-*-key varaiables
DanielG Aug 30, 2014
99599d5
elisp: Add globalized ghc-mod-mode
DanielG Aug 30, 2014
f5353ae
elisp: Fix advice de/activation
DanielG Aug 30, 2014
c46b4fe
elisp: Add docs for ghc-mod-mode function
DanielG Aug 30, 2014
edc0c37
elisp: indent
DanielG Aug 30, 2014
4d32b75
elisp: update docs
DanielG Sep 17, 2016
f53dddb
remove some unused files
DanielG Sep 17, 2016
3a9c510
elisp: deinit ghc-type and ghc-check properly
DanielG Sep 18, 2016
cd33673
elisp: remove broken C-x C-s binding
simonjwinwood Oct 1, 2016
cbf7c54
elisp: added key bindings to mode docstring
simonjwinwood Oct 1, 2016
7c767b5
elisp: replace advice by after-save-hook
simonjwinwood Oct 1, 2016
c2db467
elisp: throw an error when sync commands fail
DanielG Sep 21, 2016
0845a76
elisp: log sync cmd failures to *GHC Debug* too
DanielG Oct 2, 2016
843b901
Put faces in the correct customize group
simonjwinwood Oct 4, 2016
6c5c32e
Use defcustom over defvar for vars in ghc-check
simonjwinwood Oct 4, 2016
4f7af7d
Cleanup use of overlays
simonjwinwood Oct 4, 2016
327ef25
Revert ghc-check-command back to a defvar
simonjwinwood Oct 12, 2016
9d43fa4
elisp: Fix excessive map-file calls (again)
DanielG May 26, 2017
02f664a
elisp: Unmap files in async-after-callback
DanielG May 26, 2017
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
283 changes: 195 additions & 88 deletions elisp/ghc-check.el

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions elisp/ghc-command.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,4 @@
(delete-region beg (point))
(insert "import " mod " (" syms ")\n"))))

(defun ghc-save-buffer ()
(interactive)
;; fixme: better way then saving?
(if ghc-check-command ;; hlint
(if (buffer-modified-p)
(call-interactively 'save-buffer))
(unless buffer-read-only
(set-buffer-modified-p t)
(call-interactively 'save-buffer)))
(ghc-check-syntax))

(provide 'ghc-command)
44 changes: 28 additions & 16 deletions elisp/ghc-comp.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
;;; ghc-comp.el
;;;

;; Author: Kazu Yamamoto <Kazu@Mew.org>
;; Author: Kazu Yamamoto <Kazu@Mew.org>, Daniel Gröber <dxld@darkboxed.org>
;; Created: Sep 25, 2009
;; Revised: Aug 16, 2014

;;; Code:

(require 'ghc-func)
(require 'ghc-rewrite)
(require 'ghc-process)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
Expand Down Expand Up @@ -66,21 +68,24 @@ unloaded modules are loaded")

(defvar ghc-loaded-module nil)


(defvar ghc-mod-comp-syms '(ghc-module-names
ghc-language-extensions
ghc-option-flags
;; hard coded in GHCMod.hs
ghc-keyword-Prelude
ghc-keyword-Control.Applicative
ghc-keyword-Control.Exception
ghc-keyword-Control.Monad
ghc-keyword-Data.Char
ghc-keyword-Data.List
ghc-keyword-Data.Maybe
ghc-keyword-System.IO) )

(defun ghc-comp-init ()
(let* ((syms '(ghc-module-names
ghc-language-extensions
ghc-option-flags
;; hard coded in GHCMod.hs
ghc-keyword-Prelude
ghc-keyword-Control.Applicative
ghc-keyword-Control.Exception
ghc-keyword-Control.Monad
ghc-keyword-Data.Char
ghc-keyword-Data.List
ghc-keyword-Data.Maybe
ghc-keyword-System.IO))
(vals (ghc-boot (length syms))))
(ghc-set syms vals))
(let* ((vals (ghc-boot (length ghc-mod-comp-syms))))
(ghc-set ghc-mod-comp-syms vals))

(ghc-add ghc-module-names "qualified")
(ghc-add ghc-module-names "hiding")
;; hard coded in GHCMod.hs
Expand All @@ -91,7 +96,14 @@ unloaded modules are loaded")
"Data.Char"
"Data.List"
"Data.Maybe"
"System.IO")))
"System.IO"))
(ghc-import-module) )

(defun ghc-comp-deinit ()
(mapcar (lambda (s) (set s nil)) ghc-mod-comp-syms)
(setq ghc-loaded-module nil)
(setq ghc-merged-keyword nil) )


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
Expand Down
34 changes: 21 additions & 13 deletions elisp/ghc-func.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
;;; -*- lexical-binding: t -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; ghc-func.el
Expand Down Expand Up @@ -31,8 +32,6 @@
(while (search-forward from nil t)
(replace-match to)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun ghc-unescape-string (str)
(with-temp-buffer
(insert str)
Expand All @@ -42,8 +41,6 @@
(while (search-forward "\\\\" nil t) (replace-match "\\" nil t))
(buffer-substring-no-properties (point-min) (point-max))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defmacro ghc-add (sym val)
`(setq ,sym (cons ,val ,sym)))

Expand All @@ -52,13 +49,20 @@
(if var (set var (car vals))) ;; var can be nil to skip
(setq vals (cdr vals))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun ghc-filter (pred lst)
(let (ret)
(dolist (x lst (reverse ret))
(if (funcall pred x) (ghc-add ret x)))))

(defun ghc-sort (xs f)
(sort (copy-tree xs) f))

;; on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
;; (.*.) `on` f = \x y -> f x .*. f y

(defun ghc-on (g f)
(lambda (x y) (funcall g (funcall f x) (funcall f y))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun ghc-uniq-lol (lol)
Expand Down Expand Up @@ -234,13 +238,17 @@
(goto-char (point-max))
,@body))

(defun ghc-call-process (cmd x y z &rest args)
(apply 'call-process cmd x y z args)
(when ghc-debug
(let ((cbuf (current-buffer)))
(ghc-with-debug-buffer
(insert (format "%% %s %s\n" cmd (mapconcat 'identity args " ")))
(insert-buffer-substring cbuf)))))
(defun ghc-call-process (cmd infile destination display &rest args)
(let ((rv (apply 'call-process cmd infile destination display args)))
(unwind-protect
(when (/= 0 rv)
(error "Command failed (exit code %d): %s %s"
rv cmd (mapconcat 'identity args " ")))
(when ghc-debug
(let ((cbuf (current-buffer)))
(ghc-with-debug-buffer
(insert (format "%% %s %s -> exit code %d\n" cmd (mapconcat 'identity args " ") rv))
(insert-buffer-substring cbuf)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down
16 changes: 12 additions & 4 deletions elisp/ghc-info.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
;;; ghc-info.el
;;;

;; Author: Kazu Yamamoto <Kazu@Mew.org>
;; Author: Kazu Yamamoto <Kazu@Mew.org>, Daniel Gröber <dxld@darkboxed.org>
;; Created: Nov 15, 2010
;; Revised: Aug 16, 2014

;;; Code:

Expand All @@ -31,9 +32,8 @@
;;; type
;;;

(defvar ghc-type-overlay nil)

(make-variable-buffer-local 'ghc-type-overlay)
(defvar-local ghc-type-overlay nil "Overlay marking the extent of the
expression who's type was just analyzed.")

(defun ghc-type-set-ix (n)
(overlay-put ghc-type-overlay 'ix n))
Expand All @@ -57,12 +57,20 @@

(defun ghc-type-init ()
(setq ghc-type-overlay (make-overlay 0 0))
(overlay-put ghc-type-overlay 'ghc-type t)
(overlay-put ghc-type-overlay 'face 'region)
(ghc-type-clear-overlay)
(setq after-change-functions
(cons 'ghc-type-clear-overlay after-change-functions))
(add-hook 'post-command-hook 'ghc-type-post-command-hook))

(defun ghc-type-deinit ()
(remove-hook 'post-command-hook 'ghc-type-post-command-hook)
(setq after-change-functions
(delq 'ghc-type-clear-overlay after-change-functions))
(ghc-type-clear-overlay)
(remove-overlays (point-min) (point-max) 'ghc-type t))

(defun ghc-type-clear-overlay (&optional _beg _end _len)
(when (overlayp ghc-type-overlay)
(ghc-type-set-ix 0)
Expand Down
83 changes: 53 additions & 30 deletions elisp/ghc-process.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar ghc-process-running nil)
(defvar ghc-process-file-mapping nil)

;; TODO: What happens when ghc-mod returns NG? Probably nothing pleasant.
(defvar ghc-process-waiting-for-ok nil)

(defvar-local ghc-process-process-name nil)
(defvar-local ghc-process-original-buffer nil)
Expand Down Expand Up @@ -53,10 +55,11 @@
(setq ghc-process-original-file file)
(setq ghc-process-root root)
(let ((pro (ghc-get-process cpro name buf root))
(map-cmd (format "map-file %s\n" file)))
; (unmap-cmd (format "unmap-file %s\n" file)))
(when (buffer-modified-p (current-buffer))
(setq ghc-process-file-mapping t)
(map-cmd (format "map-file %s\n" file))
(unmap-cmd (format "unmap-file %s\n" file))
(do-map-file (buffer-modified-p cbuf)))
(when do-map-file
(setq ghc-process-waiting-for-ok t)
(setq ghc-process-async-after-callback nil)
(erase-buffer)
(when ghc-debug
Expand All @@ -71,27 +74,38 @@
(process-send-string pro "\n\004\n")
(condition-case nil
(let ((inhibit-quit nil))
(while ghc-process-file-mapping
(while ghc-process-waiting-for-ok
(accept-process-output pro 0.1 nil t)))
(quit
(setq ghc-process-running nil)
(setq ghc-process-file-mapping nil))))
(setq ghc-process-waiting-for-ok nil))))
;; command
(setq ghc-process-async-after-callback async-after-callback)
(setq ghc-process-async-after-callback
(if do-map-file
;; TODO: probably racy. What happens when ghc-with-process
;; is called again before the unmap wait loop below
;; completes?
(lambda (status)
(if (functionp async-after-callback)
(funcall async-after-callback status))
(when ghc-debug
(ghc-with-debug-buffer
(insert (format "%% %s" unmap-cmd))))
(process-send-string pro unmap-cmd)
(condition-case nil
(let ((inhibit-quit nil))
(while ghc-process-waiting-for-ok
(accept-process-output pro 0.1 nil t)))
(quit
(setq ghc-process-running nil)
(setq ghc-process-waiting-for-ok nil))))
;; else
async-after-callback))
(erase-buffer)
(when ghc-debug
(ghc-with-debug-buffer
(insert (format "%% %s" cmd))))
(process-send-string pro cmd)

;;; this needs to be done asyncrounously after the command actually
;;; finished, gah
;; (when do-map-file
;; (when ghc-debug
;; (ghc-with-debug-buffer
;; (insert (format "%% %s" unmap-cmd))))
;; (process-send-string pro unmap-cmd))

pro)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -169,21 +183,29 @@
(delete-region 1 end)))))
(goto-char (point-max))
(forward-line -1)
(cond
((looking-at "^OK$")
(delete-region (point) (point-max))
(setq ghc-process-file-mapping nil)
(when ghc-process-async-after-callback
(goto-char (point-min))
(funcall ghc-process-async-after-callback 'ok)
(setq ghc-process-running nil)))
((looking-at "^NG ")
(funcall ghc-process-async-after-callback 'ng)
(setq ghc-process-running nil)))))))

(cl-flet ((async-after-callback (status)
(condition-case err
(progn
(funcall ghc-process-async-after-callback status)
(setq ghc-process-running nil))
(error
(setq ghc-process-running nil)
(signal (car err) (cdr err))))))
(cond
((looking-at "^OK$")
(delete-region (point) (point-max))
(setq ghc-process-waiting-for-ok nil)
(when ghc-process-async-after-callback
(goto-char (point-min))
(async-after-callback 'ok)
))
((looking-at "^NG ")
(async-after-callback 'ng))))))))

(defun ghc-process-sentinel (_process _event)
(setq ghc-process-running nil)
(setq ghc-process-file-mapping nil))
(setq ghc-process-waiting-for-ok nil))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down Expand Up @@ -230,6 +252,7 @@
(if (not cpro)
(message "No ghc-mod process")
(delete-process cpro)
(message "ghc-mod process was killed")))))
(message "ghc-mod process was killed")))
(setq mode-line-process nil)))

(provide 'ghc-process)
Loading