branch: elpa/haskell-tng-mode commit dbbe4888487abb7473cd76e15f3fcc207869b190 Author: Tseen She <ts33n....@gmail.com> Commit: Tseen She <ts33n....@gmail.com>
abbrevs don't fire in comments / strings --- haskell-tng-extra-abbrev.el | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/haskell-tng-extra-abbrev.el b/haskell-tng-extra-abbrev.el index 285cd5e..e897cc7 100644 --- a/haskell-tng-extra-abbrev.el +++ b/haskell-tng-extra-abbrev.el @@ -14,22 +14,35 @@ (require 'haskell-tng-mode) ;; TODO a macro to easily define an abbrev and skeleton? -;; TODO don't fire abbrevs in comments (abbrev-table-put haskell-tng-mode-abbrev-table :regexp (rx (or bol space) ;; don't fire for \case (submatch (+ (not space))) point)) +(defun haskell-tng--abbrev-expand-p () + "abbrevs should not expand in strings and comments." + (not (nth 8 (syntax-ppss)))) + (define-skeleton haskell-tng--skeleton-case-of "case...of boilerplate" nil "case " _ " of") - (define-abbrev haskell-tng-mode-abbrev-table "case" "" #'haskell-tng--skeleton-case-of :system t - :case-fixed t) + :case-fixed t + :enable-function #'haskell-tng--abbrev-expand-p) + +(define-skeleton haskell-tng--skeleton-if-then-else + "if...then...else boilerplate" + nil "if " _ " then else") +(define-abbrev + haskell-tng-mode-abbrev-table + "if" "" #'haskell-tng--skeleton-if-then-else + :system t + :case-fixed t + :enable-function #'haskell-tng--abbrev-expand-p) (add-hook 'haskell-tng-mode-hook