emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/haskell-mode cb573c8db5 16/24: Merge pull request #1774 fr


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-mode cb573c8db5 16/24: Merge pull request #1774 from TikhonJelvis/add-language-pragma-command
Date: Tue, 1 Nov 2022 22:58:54 -0400 (EDT)

branch: elpa/haskell-mode
commit cb573c8db5b856eb37473009f2c62e0717a1cd02
Merge: 8d9b271e9c 19922b81ed
Author: Steve Purcell <steve@sanityinc.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #1774 from TikhonJelvis/add-language-pragma-command
    
    Add interactive command to insert a LANGUAGE pragma
---
 haskell-commands.el         | 10 ++++++++++
 tests/haskell-mode-tests.el |  9 +++++++++
 2 files changed, 19 insertions(+)

diff --git a/haskell-commands.el b/haskell-commands.el
index fba236d47e..c916e26489 100644
--- a/haskell-commands.el
+++ b/haskell-commands.el
@@ -36,6 +36,7 @@
 (require 'haskell-utils)
 (require 'highlight-uses-mode)
 (require 'haskell-cabal)
+(require 'haskell-ghc-support)
 
 (defcustom haskell-mode-stylish-haskell-path "stylish-haskell"
   "Path to `stylish-haskell' executable."
@@ -935,5 +936,14 @@ newlines and extra whitespace in signature before 
insertion."
         (insert sig "\n")
         (indent-to col)))))
 
+(defun haskell-command-insert-language-pragma (extension)
+  "Insert a {-# LANGUAGE _ #-} pragma at the top of the current
+buffer for the given extension."
+  (interactive
+   (list (completing-read "Extension: " haskell-ghc-supported-extensions)))
+  (save-excursion
+    (goto-char (point-min))
+    (insert (format "{-# LANGUAGE %s #-}\n" extension))))
+
 (provide 'haskell-commands)
 ;;; haskell-commands.el ends here
diff --git a/tests/haskell-mode-tests.el b/tests/haskell-mode-tests.el
index d31fe55704..47b8d8a133 100644
--- a/tests/haskell-mode-tests.el
+++ b/tests/haskell-mode-tests.el
@@ -666,4 +666,13 @@ moves over sexps."
          (goto-char (point-min))
          (should (looking-at-p "main = return ()")))))))
 
+(ert-deftest haskell-mode-add-language-pragma-with-existing-text ()
+  (with-temp-buffer
+    (haskell-mode)
+    (insert "module Main where\n")
+    (end-of-buffer)
+    (haskell-command-insert-language-pragma "ViewPatterns")
+    (should (string= (buffer-string)
+                     "{-# LANGUAGE ViewPatterns #-}\nmodule Main where\n"))))
+
 (provide 'haskell-mode-tests)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]