swift-emacs / swift-mode

Emacs support for Apple's Swift programming language.
GNU General Public License v3.0
370 stars 47 forks source link

Prevent hang when the point is at the bottom of the buffer #159

Closed danielmartin closed 5 years ago

danielmartin commented 5 years ago

Fixes #157

If the point is at the bottom of the buffer and which-function-mode is enabled, Emacs freezes. The reason is that the code enters the "unmatched parens" part of the logic and gets stuck navigating blocks forward and backward without ever matching a block correctly.

This can be fixed if we check for the end of buffer case explicitly and return a whole buffer as a block. This makes a point "in between functions" return the same function information as a point at the end of the buffer. Graphically:

protocol P { func f() }
extension P { func g() { f() } }
struct X<T> : P {
    func f() { print("unconstrained") }
}
<--- Point here (which-function-mode returns "P")
struct X<T> : where T : BinaryInteger {
    func f() { print("constrained")
}
<--- Point here (which-function-mode returns "P")
taku0 commented 5 years ago

Thank you for your PR. I will test this in the next weekend.

taku0 commented 5 years ago

It seems that swift-mode:beginning-of-defun gets stuck at the beginning of buffer. I will investigate this further tomorrow.

taku0 commented 5 years ago

Fixed by 04c8a621e9844ef3f7d53c41b046f71aadb1a9d2. Thank you for your PR.