branch: elpa/forth-mode
commit 74c0e17c4568ddba1dd77bf1bf8a3fccb6cfc5e8
Author: Helmut Eller <[email protected]>
Commit: Helmut Eller <[email protected]>
Improve beginning-of-defun
* forth-mode.el (forth-beginning-of-defun): New.
(forth-mode): Set beginning-of-defun-function.
* test/tests.el (forth-beginning-of-defun): New test.
---
forth-mode.el | 5 +++++
test/tests.el | 10 ++++++++++
2 files changed, 15 insertions(+)
diff --git a/forth-mode.el b/forth-mode.el
index e46326f9fb..82e98f2035 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -116,6 +116,10 @@
(comment-end ""))
(apply #'fill-paragraph args)))
+(defun forth-beginning-of-defun (arg)
+ (and (re-search-backward "^\\s *: \\_<" nil t (or arg 1))
+ (beginning-of-line)))
+
(unless (fboundp 'prog-mode)
(defalias 'prog-mode 'fundamental-mode))
@@ -136,6 +140,7 @@
(setq-local parse-sexp-lookup-properties t)
(forth-smie-setup)
(setq-local fill-paragraph-function #'forth-fill-paragraph)
+ (setq-local beginning-of-defun-function #'forth-beginning-of-defun)
(setq-local comment-start-skip "\\(?:(\\*\\|\\\\\\) *")
(setq-local comment-start "(")
(setq-local comment-end ")")
diff --git a/test/tests.el b/test/tests.el
index 555c9b6e6c..0b6015e7da 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -258,6 +258,16 @@ The whitespace before and including \"|\" on each line is
removed."
|: frob ( x y -- z ) ;"
#'fill-paragraph))
+(ert-deftest forth-beginning-of-defun ()
+ (forth-should-before/after
+ ": foo bar ;
+ |: baz ( x -- )
+ | if foo→ then ;"
+ ": foo bar ;
+ |→: baz ( x -- )
+ | if foo then ;"
+ #'beginning-of-defun))
+
;; FIXME: maybe insert "( )" instead of "()".
(ert-deftest forth-comment-dwim ()
(forth-should-before/after