@@ -340,6 +340,7 @@ see documentation for that variable for more details."
340
340
(set (make-local-variable 'dabbrev-case-distinction ) nil )
341
341
(set (make-local-variable 'dabbrev-case-replace ) nil )
342
342
(set (make-local-variable 'dabbrev-abbrev-char-regexp ) " \\ sw\\ |[.]" )
343
+ (setq-local beginning-of-defun-function 'purescript-beginning-of-defun )
343
344
(setq prettify-symbols-alist purescript-font-lock-prettify-symbols-alist)
344
345
(when (bound-and-true-p purescript-font-lock-symbols)
345
346
(warn " `purescript-font-lock-symbols' is obsolete: please enable `prettify-symbols-mode' locally or globally instead." ))
@@ -470,6 +471,35 @@ Brings up the documentation for purescript-mode-hook."
470
471
(format " [ %s .. ] " (purescript-string-take (purescript-trim (cadr lines)) 10 ))
471
472
" " ))))))
472
473
474
+ (defun purescript-current-line-string ()
475
+ " Returns current line as a string."
476
+ (buffer-substring-no-properties (line-beginning-position ) (line-end-position )))
477
+
478
+ (defun purescript-beginning-of-defun-single ()
479
+ (while (and (looking-at-p (rx (* space) eol))
480
+ (not (bobp )))
481
+ (forward-line -1 )) ; can't get indentation on an empty line
482
+ (let ((indent-level (current-indentation )))
483
+ (while
484
+ (not
485
+ (or (ignore (forward-line -1 )) ; do-while implementation
486
+ (bobp )
487
+ (and (< (current-indentation ) indent-level)
488
+ (string-match-p
489
+ (rx (*? anything)
490
+ (or bol space word-boundary) " ="
491
+ (or eol space word-boundary))
492
+ ; ; Emacs doesn't allow to limit search just to the curent line
493
+ ; ; barring the regex eol, but eol overly complicates matching.
494
+ (purescript-current-line-string))))))))
495
+
496
+ (defun purescript-beginning-of-defun (&optional repeat )
497
+ " Move point to the beginning of the current PureScript function."
498
+ (purescript-beginning-of-defun-single)
499
+ (dotimes (_ (if repeat
500
+ (- repeat 1 ) ; the function was already called once
501
+ 0 ))
502
+ (purescript-beginning-of-defun-single)))
473
503
474
504
(provide 'purescript-mode )
475
505
0 commit comments