Skip to content

Commit 6a3257c

Browse files
committed
Made haskell-ident-pos-at-point return nil.
The documentation mandates that `haskell-ident-pos-at-point` return nil when there is no identifier at point; however, it instead returned a cons cell of the form `(n . n)`. This is now fixed, and any code that relied on this behavior has been changed. This also therefore fixes `haskell-spanable-pos-at-point` in the same way.
1 parent f8521d9 commit 6a3257c

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

haskell-commands.el

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -621,26 +621,29 @@ command from GHCi."
621621
(interactive "P")
622622
(let ((ty (haskell-mode-type-at))
623623
(orig (point)))
624-
(if insert-value
625-
(let ((ident-pos (haskell-ident-pos-at-point)))
626-
(cond
627-
((region-active-p)
628-
(delete-region (region-beginning)
629-
(region-end))
630-
(insert "(" ty ")")
631-
(goto-char (1+ orig)))
632-
((= (line-beginning-position) (car ident-pos))
633-
(goto-char (line-beginning-position))
634-
(insert (haskell-fontify-as-mode ty 'haskell-mode)
635-
"\n"))
636-
(t
637-
(save-excursion
638-
(goto-char (car ident-pos))
639-
(let ((col (current-column)))
640-
(save-excursion (insert "\n")
641-
(indent-to col))
642-
(insert (haskell-fontify-as-mode ty 'haskell-mode)))))))
643-
(message "%s" (haskell-fontify-as-mode ty 'haskell-mode)))))
624+
(unless (= (aref ty 0) ?\n)
625+
;; That seems to be what happens when `haskell-mode-type-at` fails
626+
(if insert-value
627+
(let ((ident-pos (or (haskell-ident-pos-at-point)
628+
(cons (point) (point)))))
629+
(cond
630+
((region-active-p)
631+
(delete-region (region-beginning)
632+
(region-end))
633+
(insert "(" ty ")")
634+
(goto-char (1+ orig)))
635+
((= (line-beginning-position) (car ident-pos))
636+
(goto-char (line-beginning-position))
637+
(insert (haskell-fontify-as-mode ty 'haskell-mode)
638+
"\n"))
639+
(t
640+
(save-excursion
641+
(goto-char (car ident-pos))
642+
(let ((col (current-column)))
643+
(save-excursion (insert "\n")
644+
(indent-to col))
645+
(insert (haskell-fontify-as-mode ty 'haskell-mode)))))))
646+
(message "%s" (haskell-fontify-as-mode ty 'haskell-mode))))))
644647

645648
;;;###autoload
646649
(defun haskell-process-generate-tags (&optional and-then-find-this-tag)

haskell-mode.el

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,18 @@ Run M-x describe-variable haskell-mode-hook for a list of such modes."))
486486
May return a qualified name."
487487
(let ((reg (haskell-ident-pos-at-point)))
488488
(when reg
489-
(unless (= (car reg) (cdr reg))
490-
(buffer-substring-no-properties (car reg) (cdr reg))))))
489+
(buffer-substring-no-properties (car reg) (cdr reg)))))
491490

492491
(defun haskell-spanable-pos-at-point ()
493492
"Like `haskell-ident-pos-at-point', but includes any surrounding backticks."
494493
(save-excursion
495494
(let ((pos (haskell-ident-pos-at-point)))
496-
(if pos
497-
(cl-destructuring-bind (start . end) pos
498-
(if (and (eq ?` (char-before start))
499-
(eq ?` (char-after end)))
500-
(cons (- start 1) (+ end 1))
501-
(cons start end)))))))
495+
(when pos
496+
(cl-destructuring-bind (start . end) pos
497+
(if (and (eq ?` (char-before start))
498+
(eq ?` (char-after end)))
499+
(cons (- start 1) (+ end 1))
500+
(cons start end)))))))
502501

503502
(defun haskell-ident-pos-at-point ()
504503
"Return the span of the identifier under point, or nil if none found.
@@ -536,7 +535,8 @@ May return a qualified name."
536535
(looking-at "[[:upper:]]"))
537536
(setq start (point)))
538537
;; This is it.
539-
(cons start end)))))
538+
(unless (= start end)
539+
(cons start end))))))
540540

541541
(defun haskell-delete-indentation (&optional arg)
542542
"Like `delete-indentation' but ignoring Bird-style \">\"."

0 commit comments

Comments
 (0)