Skip to content

Commit a0dd740

Browse files
committed
Split interaction mode into two minor modes a la indentation
1 parent 591d1a8 commit a0dd740

File tree

3 files changed

+102
-41
lines changed

3 files changed

+102
-41
lines changed

haskell-mode.el

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -227,36 +227,25 @@ be set to the preferred literate style."
227227
;;;###autoload
228228
(defvar haskell-mode-map
229229
(let ((map (make-sparse-keymap)))
230-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231-
;; For inferior haskell mode, use the below bindings
232-
;; (define-key map [?\M-C-x] 'inferior-haskell-send-defun)
233-
;; (define-key map [?\C-x ?\C-e] 'inferior-haskell-send-last-sexp)
234-
;; (define-key map [?\C-c ?\C-r] 'inferior-haskell-send-region)
235-
(define-key map [?\C-x ?\C-d] 'inferior-haskell-send-decl)
236-
(define-key map [?\C-c ?\C-z] 'switch-to-haskell)
237-
(define-key map [?\C-c ?\C-l] 'inferior-haskell-load-file)
238-
;; I think it makes sense to bind inferior-haskell-load-and-run to C-c
239-
;; C-r, but since it used to be bound to `reload' until June 2007, I'm
240-
;; going to leave it out for now.
241-
;; (define-key map [?\C-c ?\C-r] 'inferior-haskell-load-and-run)
242-
(define-key map [?\C-c ?\C-b] 'switch-to-haskell)
243-
;; (define-key map [?\C-c ?\C-s] 'inferior-haskell-start-process)
244-
;; That's what M-; is for.
245-
;; (define-key map "\C-c\C-c" 'comment-region)
246-
(define-key map (kbd "C-c C-t") 'inferior-haskell-type)
247-
(define-key map (kbd "C-c C-i") 'inferior-haskell-info)
248-
(define-key map (kbd "C-c M-.") 'inferior-haskell-find-definition)
249-
(define-key map (kbd "C-c C-d") 'inferior-haskell-find-haddock)
250-
(define-key map [?\C-c ?\C-v] 'haskell-check)
251-
252230
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
253231
;; Editing-specific commands
254232
(define-key map (kbd "C-c C-.") 'haskell-mode-format-imports)
255233
(define-key map [remap delete-indentation] 'haskell-delete-indentation)
256-
234+
(define-key map (kbd "C-c C-l") 'haskell-mode-enable-process-minor-mode)
235+
(define-key map (kbd "C-c C-b") 'haskell-mode-enable-process-minor-mode)
236+
(define-key map (kbd "C-c C-v") 'haskell-mode-enable-process-minor-mode)
237+
(define-key map (kbd "C-c C-t") 'haskell-mode-enable-process-minor-mode)
238+
(define-key map (kbd "C-c C-i") 'haskell-mode-enable-process-minor-mode)
257239
map)
258240
"Keymap used in Haskell mode.")
259241

242+
(defun haskell-mode-enable-process-minor-mode ()
243+
"Tell the user to choose a minor mode for process interaction."
244+
(interactive)
245+
(error "You tried to do an indentation command, but an interaction mode has not been enabled yet.
246+
247+
Run M-x describe-variable haskell-mode-hook for a list of such modes."))
248+
260249
(easy-menu-define haskell-mode-menu haskell-mode-map
261250
"Menu for the Haskell major mode."
262251
;; Suggestions from Pupeno <[email protected]>:
@@ -267,8 +256,8 @@ be set to the preferred literate style."
267256
["Indent region" indent-region mark-active]
268257
["(Un)Comment region" comment-region mark-active]
269258
"---"
270-
["Start interpreter" switch-to-haskell]
271-
["Load file" inferior-haskell-load-file]
259+
["Start interpreter" haskell-process-switch]
260+
["Load file" haskell-process-load-file]
272261
"---"
273262
["Load tidy core" ghc-core-create-core]
274263
"---"
@@ -407,27 +396,47 @@ May return a qualified name."
407396
(defcustom haskell-mode-hook nil
408397
"Hook run after entering `haskell-mode'.
409398
410-
Some of the supported modules that can be activated via this hook:
399+
You may be looking at this documentation because you haven't
400+
configured indentation or process interaction.
411401
412-
`haskell-decl-scan', Graeme E Moss
413-
Scans top-level declarations, and places them in a menu.
414-
415-
`haskell-doc', Hans-Wolfgang Loidl
416-
Echoes types of functions or syntax of keywords when the cursor is idle.
402+
Indentation modes:
417403
418-
`haskell-indentation', Kristof Bastiaensen
404+
`haskell-indentation-mode', Kristof Bastiaensen
419405
Intelligent semi-automatic indentation Mk2
420406
421-
`haskell-indent', Guy Lapalme
407+
`haskell-indent-mode', Guy Lapalme
422408
Intelligent semi-automatic indentation.
423409
424-
`haskell-simple-indent', Graeme E Moss and Heribert Schuetz
410+
`haskell-simple-indent-mode', Graeme E Moss and Heribert Schuetz
425411
Simple indentation.
426412
427-
Module X is activated using the command `turn-on-X'. For example,
428-
`haskell-doc' is activated using `turn-on-haskell-doc'.
429-
For more information on a specific module, see the help for its `X-mode'
430-
function. Some modules can be deactivated using `turn-off-X'.
413+
Interaction modes:
414+
415+
`interactive-haskell-mode'
416+
Interact with per-project GHCi processes through a REPL and
417+
directory-aware sessions.
418+
419+
`inf-haskell-mode'
420+
Interact with a GHCi process using comint-mode. Deprecated.
421+
422+
Other modes:
423+
424+
`haskell-decl-scan-mode', Graeme E Moss
425+
Scans top-level declarations, and places them in a menu.
426+
427+
`haskell-doc-mode', Hans-Wolfgang Loidl
428+
Echoes types of functions or syntax of keywords when the cursor is idle.
429+
430+
To activate a minor-mode, simply run the interactive command. For
431+
example, `M-x haskell-doc-mode'. Run it again to disable it.
432+
433+
To enable a mode for every haskell-mode buffer, add a hook in
434+
your Emacs configuration. For example, to enable
435+
haskell-indent-mode and interactive-haskell-mode, use the
436+
following:
437+
438+
(add-hook 'haskell-mode-hook 'haskell-indent-mode)
439+
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
431440
432441
See Info node `(haskell-mode)haskell-mode-hook' for more details.
433442
@@ -737,8 +746,11 @@ To be added to `flymake-init-create-temp-buffer-copy'."
737746

738747
(defun haskell-mode-suggest-indent-choice ()
739748
"Ran when the user tries to indent in the buffer but no indentation mode has been selected.
740-
Brings up the documentation for haskell-mode-hook."
741-
(describe-variable 'haskell-mode-hook))
749+
Explains what has happened and suggests reading docs for `haskell-mode-hook'."
750+
(interactive)
751+
(error "You tried to do an interaction command, but an indentation mode has not been enabled yet.
752+
753+
Run M-x describe-variable haskell-mode-hook for a list of such modes."))
742754

743755
(defun haskell-mode-format-imports ()
744756
"Format the imports by aligning and sorting them."

haskell-process.el

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ to be loaded by ghci."
523523
(format "%s %s"
524524
(ecase haskell-process-type
525525
('ghci haskell-process-path-cabal)
526-
('cabal-repl haskell-process-path-cabal)
526+
('cabal-repl haskell-process-path-cabal)
527527
('cabal-ghci haskell-process-path-cabal)
528528
('cabal-dev haskell-process-path-cabal-dev))
529529
(caddr state)))))
@@ -1620,6 +1620,26 @@ function and remove this comment.
16201620
(haskell-guess-module-name)
16211621
".imports")))
16221622

1623+
(defvar interactive-haskell-mode-map
1624+
(let ((map (make-sparse-keymap)))
1625+
(define-key map (kbd "C-c C-l") 'haskell-process-load-or-reload)
1626+
(define-key map (kbd "C-c C-t") 'haskell-process-do-type)
1627+
(define-key map (kbd "C-c C-i") 'haskell-process-do-info)
1628+
(define-key map (kbd "M-.") 'haskell-mode-jump-to-def-or-tag)
1629+
(define-key map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
1630+
(define-key map (kbd "C-c C-c") 'haskell-process-cabal-build)
1631+
(define-key map (kbd "C-c c") 'haskell-process-cabal)
1632+
(define-key map [?\C-c ?\C-b] 'haskell-interactive-switch)
1633+
(define-key map [?\C-c ?\C-z] 'haskell-interactive-switch)
1634+
map)
1635+
"Keymap for using haskell-interactive-mode.")
1636+
1637+
;;;###autoload
1638+
(define-minor-mode interactive-haskell-mode
1639+
"Minor mode for enabling haskell-process interaction."
1640+
:lighter " Interactive"
1641+
:keymap interactive-haskell-mode-map)
1642+
16231643
(provide 'haskell-process)
16241644

16251645
;; Local Variables:

inf-haskell.el

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,35 @@ we load it."
792792
(url (concat url "#v:" sym)))
793793
(if url (browse-url url) (error "Local file doesn't exist"))))
794794

795+
(defvar inf-haskell-mode-map
796+
(let ((map (make-sparse-keymap)))
797+
;; (define-key map [?\M-C-x] 'inferior-haskell-send-defun)
798+
;; (define-key map [?\C-x ?\C-e] 'inferior-haskell-send-last-sexp)
799+
;; (define-key map [?\C-c ?\C-r] 'inferior-haskell-send-region)
800+
(define-key map [?\C-x ?\C-d] 'inferior-haskell-send-decl)
801+
(define-key map [?\C-c ?\C-z] 'switch-to-haskell)
802+
(define-key map [?\C-c ?\C-l] 'inferior-haskell-load-file)
803+
;; I think it makes sense to bind inferior-haskell-load-and-run to C-c
804+
;; C-r, but since it used to be bound to `reload' until June 2007, I'm
805+
;; going to leave it out for now.
806+
;; (define-key map [?\C-c ?\C-r] 'inferior-haskell-load-and-run)
807+
(define-key map [?\C-c ?\C-b] 'switch-to-haskell)
808+
;; (define-key map [?\C-c ?\C-s] 'inferior-haskell-start-process)
809+
;; That's what M-; is for.
810+
(define-key map (kbd "C-c C-t") 'inferior-haskell-type)
811+
(define-key map (kbd "C-c C-i") 'inferior-haskell-info)
812+
(define-key map (kbd "C-c M-.") 'inferior-haskell-find-definition)
813+
(define-key map (kbd "C-c C-d") 'inferior-haskell-find-haddock)
814+
(define-key map [?\C-c ?\C-v] 'haskell-check)
815+
map)
816+
"Keymap for using inf-haskell.")
817+
818+
;;;###autoload
819+
(define-minor-mode inf-haskell-mode
820+
"Minor mode for enabling inf-haskell process interaction."
821+
:lighter " Inf-Haskell"
822+
:keymap inf-haskell-mode-map)
823+
795824
(provide 'inf-haskell)
796825

797826
;; Local Variables:

0 commit comments

Comments
 (0)