haskell / haskell-snippets

Official collection of YASnippet Haskell snippets for Emacs.
12 stars 9 forks source link

current-column wrong in interactive-haskell-mode #9

Open unhammer opened 4 years ago

unhammer commented 4 years ago
(add-hook 'haskell-interactive-mode-hook 'yas-minor-mode)
(add-hook 'interactive-haskell-mode-hook
            (defun my-interactive-haskell-use-snippets ()
                (yas-activate-extra-mode 'haskell-mode)))

turns it on in interactive-haskell-mode, but most of the snippets don't expand because they test (current-column) (to check that we're writing "imp" at the start of the line) which gets offset due to the repl prompt. One solution would be to have a helper like doing something like

(defun haskell-snippets-current-column ()
  (let ((prompt-len (if (eq major-mode 'haskell-interactive-mode)
                        (save-excursion
                          (goto-char (line-beginning-position))
                          (cond ((looking-at-p (regexp-quote
                                                haskell-interactive-prompt))
                                 (length haskell-interactive-prompt))
                                ((looking-at-p (regexp-quote
                                                haskell-interactive-prompt2))
                                 (length haskell-interactive-prompt2))
                                (t 0)))
                      0)))
    (- (current-column) prompt-len)))

(and using that instead of current-column in the snippets) but maybe there's a built-in thing like that in emacs? (or one could use haskell-interactive-mode-bol)