@@ -850,32 +850,46 @@ fact n =
850
850
(4 0 2 4 6 )
851
851
(5 0 2 4 6 ))
852
852
853
+ (defmacro with-temp-switch-to-buffer (&rest body )
854
+ " Create a temporary buffer, use `switch-to-buffer' and evaluate BODY there like `progn' .
855
+
856
+ Seems that `execute-kbd-macro' is not able to correctly execute keybindings without this."
857
+ (declare (indent 0 ) (debug t ))
858
+ (let ((temp-buffer (make-symbol " temp-buffer" )))
859
+ `(let ((, temp-buffer (generate-new-buffer " *temp*" )))
860
+ ; ; FIXME: kill-buffer can change current-buffer in some odd cases.
861
+ (unwind-protect
862
+ (progn
863
+ (switch-to-buffer , temp-buffer )
864
+ ,@body )
865
+ (and (buffer-name , temp-buffer )
866
+ (kill-buffer , temp-buffer ))))))
867
+
853
868
(ert-deftest haskell-indentation-ret-indents ()
854
- (switch-to-buffer ( get-buffer-create " source.hs " ))
855
- (haskell-mode )
856
- (insert " main = do" )
857
- ( execute-kbd-macro ( kbd " <RET> " ))
858
- ( should ( equal 2 ( count-lines ( point-min ) ( point )) ))
859
- (should (equal 2 (- (point ) (line-beginning-position )))))
869
+ (with-temp- switch-to-buffer
870
+ (haskell-mode )
871
+ (insert " main = do" )
872
+
873
+ ( execute-kbd-macro ( kbd " <RET> " ))
874
+ (should (equal 2 (- (point ) (line-beginning-position ) )))))
860
875
861
876
(ert-deftest haskell-indentation-tab-and-backtab ()
862
- (switch-to-buffer ( get-buffer-create " source.hs " ))
863
- (haskell-mode )
864
- (insert " main = do\n lala\n " )
865
- ( execute-kbd-macro ( kbd " TAB " ))
866
- ( should ( equal 4 ( count-lines ( point-min ) ( point )) ))
867
- (should (equal 4 (- (point ) (line-beginning-position ))))
868
- ( execute-kbd-macro ( kbd " <backtab> " ))
869
- ( should ( equal 4 ( count-lines ( point-min ) ( point )) ))
870
- (should (equal 2 (- (point ) (line-beginning-position )))))
877
+ (with-temp- switch-to-buffer
878
+ (haskell-mode )
879
+ (insert " main = do\n lala\n " )
880
+
881
+ ( execute-kbd-macro ( kbd " TAB " ))
882
+ (should (equal 4 (- (point ) (line-beginning-position ))))
883
+
884
+ ( execute-kbd-macro ( kbd " <backtab> " ))
885
+ (should (equal 2 (- (point ) (line-beginning-position ) )))))
871
886
872
887
(ert-deftest haskell-indentation-altj-comment ()
873
888
:expected-result :failed
874
- (switch-to-buffer (get-buffer-create " another.hs" ))
875
- (haskell-mode )
876
- (insert " main = do\n return ()\n\n -- comment" )
877
- (execute-kbd-macro (kbd " M-j" ))
878
- (should (equal 2 (count-lines (point-min ) (point ))))
879
- (should (equal 3 (- (point ) (line-beginning-position )))))
889
+ (with-temp-switch-to-buffer
890
+ (haskell-mode )
891
+ (insert " main = do\n return ()\n\n -- comment" )
892
+ (execute-kbd-macro (kbd " M-j" ))
893
+ (should (equal 3 (- (point ) (line-beginning-position ))))))
880
894
881
895
; ;; haskell-indentation-tests.el ends here
0 commit comments