- (let ((start t)
- accum)
- (while (or start (> (current-indentation) 0))
- (setq start nil)
- (python-beginning-of-block)
- (end-of-line)
- (beginning-of-defun)
- (if (looking-at (rx (0+ space) (or "def" "class") (1+ space)
- (group (1+ (or word (syntax symbol))))))
- (push (match-string 1) accum)))
- (if accum (mapconcat 'identity accum ".")))))
+ (let ((accum)
+ (length -1))
+ (catch 'done
+ (while (or (null length-limit)
+ (null (cdr accum))
+ (< length length-limit))
+ (setq start nil)
+ (let ((started-from (point)))
+ (python-beginning-of-block)
+ (end-of-line)
+ (beginning-of-defun)
+ (when (= (point) started-from)
+ (throw 'done nil)))
+ (when (looking-at (rx (0+ space) (or "def" "class") (1+ space)
+ (group (1+ (or word (syntax symbol))))))
+ (push (match-string 1) accum)
+ (setq length (+ length 1 (length (car accum)))))
+ (when (= (current-indentation) 0)
+ (throw 'done nil))))
+ (when accum
+ (when (and length-limit (> length length-limit))
+ (setcar accum ".."))
+ (mapconcat 'identity accum ".")))))