Commit b75af38c authored by Johannes Mueller's avatar Johannes Mueller Committed by GitHub

[cython-mode.el] Fix endless loop reported in #3218 and other bugs around it (GH-4460)

The function `(cython-current-defun)` of `cython-mode.el` had some issues:

* ran into an endless loop
* for `cdef`s and `cpdef`s it picked the function type rather than the function name.
* did not properly handle nested functions

Closes https://github.com/cython/cython/issues/3218
parent ee7f61a5
......@@ -264,16 +264,25 @@ Finds end of innermost nested class or method definition."
(save-excursion
;; Move up the tree of nested `class' and `def' blocks until we
;; get to zero indentation, accumulating the defined names.
(let ((start t)
(let ((not-finished t)
accum)
(while (or start (> (current-indentation) 0))
(setq start nil)
(cython-beginning-of-block)
(end-of-line)
(beginning-of-defun)
(if (looking-at (rx (0+ space) (or "def" "cdef" "cpdef" "class") (1+ space)
(skip-chars-backward " \t\r\n")
(cython-beginning-of-defun)
(while not-finished
(beginning-of-line)
(skip-chars-forward " \t\r\n")
(if (looking-at (rx (0+ space) (or "def" "class") (1+ space)
(group (1+ (or word (syntax symbol))))))
(push (match-string 1) accum)))
(push (match-string 1) accum)
(if (looking-at (rx (0+ space) (or "cdef" "cpdef") (1+ space) (1+ word) (1+ space)
(group (1+ (or word (syntax symbol))))))
(push (match-string 1) accum)))
(let ((indentation (current-indentation)))
(if (= 0 indentation)
(setq not-finished nil)
(while (= indentation (current-indentation))
(message "%s %s" indentation (current-indentation))
(cython-beginning-of-defun)))))
(if accum (mapconcat 'identity accum ".")))))
;;;###autoload
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment