Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t stop at empty lines in ‘end-of-defun’ #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions julia-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,24 @@ f(x) = x + 1" 'beginning-of-defun "\\+" 4))
"f(x)::Int8 =
x *x" 'end-of-defun "(" "*x" 'end))

(ert-deftest julia--test-end-of-defun-assn-with-empty-lines ()
"Point should move to end of assignment function."
(julia--should-move-point
"f(x)::Int8 =

# no comment
x*x" 'end-of-defun "(" "*x" 'end))

(ert-deftest julia-test-end-of-defun-with-empty-lines ()
"Point should move to end of function."
(julia--should-move-point
"
function forty_two()

# no comment
return 42
end" 'end-of-defun 0 "end" 'end))

(ert-deftest julia--test-end-of-defun-nested-1 ()
"Point should move to end of inner function when called from inner."
(julia--should-move-point
Expand Down
3 changes: 2 additions & 1 deletion julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ Return nil if point is not in a function, otherwise point."
(while (and (not (eobp))
(forward-line 1)
(or (julia-syntax-comment-or-string-p)
(> (current-indentation) beg-defun-indent)))))
(> (current-indentation) beg-defun-indent)
(looking-at-p "^\\s-*\\(?:#.*\\)*$")))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just use forward-comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to move over empty lines including those with “only but
not enough” whitespaces. forward-comment won’t do the job.
Replacing looking-at-p with (forward-comment 1) will move the
cursor to the line with the return statement and return nil.

function f()

    x = 42
    return x
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in cases like

f(x)::Int8 =
# no comment
    x*x

function forty_two()
 # no comment
    return 42
end

where end-of-defun jumps from first to end of second. It also gets stuck when point is just prior to the first function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For forward-comment I had been thinking along the lines of

(while (and (not (eobp))
                    (forward-line 1)
                    (or (forward-comment 5)
                        (julia-syntax-comment-or-string-p)
                        (> (current-indentation) beg-defun-indent)))))

(end-of-line)
(point))))

Expand Down