@@ -202,6 +202,7 @@ be set to the preferred literate style."
202
202
(define-key map (kbd " C-c C-v" ) 'haskell-mode-enable-process-minor-mode )
203
203
(define-key map (kbd " C-c C-t" ) 'haskell-mode-enable-process-minor-mode )
204
204
(define-key map (kbd " C-c C-i" ) 'haskell-mode-enable-process-minor-mode )
205
+ (define-key map (kbd " C-c C-s" ) 'haskell-mode-toggle-scc-at-point )
205
206
map)
206
207
" Keymap used in Haskell mode." )
207
208
@@ -891,13 +892,15 @@ LOC = (list FILE LINE COL)"
891
892
892
893
; ; From Bryan O'Sullivan's blog:
893
894
; ; http://www.serpentine.com/blog/2007/10/09/using-emacs-to-insert-scc-annotations-in-haskell-code/
894
- (defun haskell-mode-insert-scc-at-point ()
895
- " Insert an SCC annotation at point."
896
- (interactive )
897
- (if (or (looking-at " \\ b\\ |[ \t ]\\ |$" ) (and (not (bolp ))
898
- (save-excursion
899
- (forward-char -1 )
900
- (looking-at " \\ b\\ |[ \t ]" ))))
895
+ (defun haskell-mode-try-insert-scc-at-point ()
896
+ " Try to insert an SCC annotation at point. Return true if
897
+ successful, nil otherwise."
898
+ (if (or (looking-at " \\ b\\ |[ \t ]\\ |$" )
899
+ ; ; Allow SCC if point is on a non-letter with whitespace to the left
900
+ (and (not (bolp ))
901
+ (save-excursion
902
+ (forward-char -1 )
903
+ (looking-at " [ \t ]" ))))
901
904
(let ((space-at-point (looking-at " [ \t ]" )))
902
905
(unless (and (not (bolp )) (save-excursion
903
906
(forward-char -1 )
@@ -906,13 +909,23 @@ LOC = (list FILE LINE COL)"
906
909
(insert " {-# SCC \"\" #-}" )
907
910
(unless space-at-point
908
911
(insert " " ))
909
- (forward-char (if space-at-point -5 -6 )))
910
- ( error " Not over an area of whitespace " )))
912
+ (forward-char (if space-at-point -5 -6 ))
913
+ t )))
911
914
912
- ; ; Also Bryan O'Sullivan's.
913
- (defun haskell-mode-kill-scc-at-point ()
914
- " Kill the SCC annotation at point."
915
+ (defun haskell-mode-insert-scc-at-point ()
916
+ " Insert an SCC annotation at point."
915
917
(interactive )
918
+ (if (not (haskell-mode-try-insert-scc-at-point))
919
+ (error " Not over an area of whitespace " )))
920
+
921
+ (make-obsolete
922
+ 'haskell-mode-insert-scc-at-point
923
+ 'haskell-mode-toggle-scc-at-point
924
+ " 2015-11-11" )
925
+
926
+ (defun haskell-mode-try-kill-scc-at-point ()
927
+ " Try to kill an SCC annotation at point. Return true if
928
+ successful, nil otherwise."
916
929
(save-excursion
917
930
(let ((old-point (point ))
918
931
(scc " \\ ({-#[ \t ]*SCC \" [^\" ]*\" [ \t ]*#-}\\ )[ \t ]*" ))
@@ -921,8 +934,27 @@ LOC = (list FILE LINE COL)"
921
934
(if (and (looking-at scc)
922
935
(<= (match-beginning 1 ) old-point)
923
936
(> (match-end 1 ) old-point))
924
- (kill-region (match-beginning 0 ) (match-end 0 ))
925
- (error " No SCC at point " )))))
937
+ (progn (kill-region (match-beginning 0 ) (match-end 0 ))
938
+ t )))))
939
+
940
+ ; ; Also Bryan O'Sullivan's.
941
+ (defun haskell-mode-kill-scc-at-point ()
942
+ " Kill the SCC annotation at point."
943
+ (interactive )
944
+ (if (not (haskell-mode-try-kill-scc-at-point))
945
+ (error " No SCC at point " )))
946
+
947
+ (make-obsolete
948
+ 'haskell-mode-kill-scc-at-point
949
+ 'haskell-mode-toggle-scc-at-point
950
+ " 2015-11-11" )
951
+
952
+ (defun haskell-mode-toggle-scc-at-point ()
953
+ " If point is in an SCC annotation, kill the annotation. Otherwise, try to insert a new annotation."
954
+ (interactive )
955
+ (if (not (haskell-mode-try-kill-scc-at-point))
956
+ (if (not (haskell-mode-try-insert-scc-at-point))
957
+ (error " Could not insert or remove SCC " ))))
926
958
927
959
(defun haskell-guess-module-name ()
928
960
" Guess the current module name of the buffer."
0 commit comments