Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
`py-backward-def-or-class' fixed
  • Loading branch information
andreas-roehler committed Aug 12, 2016
1 parent ba4e27a commit 5dfdaae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
41 changes: 18 additions & 23 deletions python-mode.el
Expand Up @@ -6058,46 +6058,41 @@ With BOL, return line-beginning-position"
(setq erg (line-beginning-position))))
(or erg (goto-char orig))))

(defun py--backward-def-or-class-matcher (regexp indent)
(defun py--backward-def-or-class-matcher (regexp indent origline)
(let (done)
(while (and
(not done)
(re-search-backward regexp nil 'move 1)
(or
(nth 8 (parse-partial-sexp (point-min) (point)))
;; (if
;; ;; looking one level below
;; (< 0 indent)
;; (if
;; (<= indent (current-indentation))
;; t
;; (setq done (match-beginning 0)))
(if
;; looking one level below
(< 0 indent)
(if
(<= indent (current-indentation))
t
(setq done (match-beginning 0)))
(if
(< indent (current-indentation))
t
(setq done (match-beginning 0)))))))
(unless (eq (py-count-lines) origline)
(and (not (bolp)) (<= indent (current-indentation))))

t
(setq done (match-beginning 0))))))
done))

(defun py--backward-def-or-class-intern (regexp &optional bol)
;; get the right start-indent
;; (when (empty-line-p)
;; (skip-chars-backward " \t\r\n\f"))
;; ;; just behind a closing delimiter
;; (when (and (eolp) (member (char-before) (list ?\) ?} ?\] ?\" ?')))
;; (forward-char -1))
(let ((indent (if (empty-line-p)
(let ((origline (py-count-lines))
(indent (if (empty-line-p)
(current-indentation)
(save-excursion
(if (py--beginning-of-statement-p)
(current-indentation)
(py-backward-statement)
(current-indentation)))))

;; (progn (when (py-in-string-or-comment-p)
;; (py-backward-statement))
;; (current-indentation)))
erg)
(setq erg (py--backward-def-or-class-matcher regexp indent))
;; (if (and (< (current-column) origindent) (looking-at regexp))
;; (setq erg (point))
(setq erg (py--backward-def-or-class-matcher regexp indent origline))
(and erg (looking-back "async ")
(goto-char (match-beginning 0))
(setq erg (point)))
Expand Down
21 changes: 21 additions & 0 deletions test/py-ert-tests-1.el
Expand Up @@ -1428,5 +1428,26 @@ except:
;; (should (eq (char-after) ?c))
;; ))

(ert-deftest py-ert-backward-def-or-class ()
(py-test-with-temp-buffer
"class _Simple(object):
# emulate something
def foo(self, element, tag, namespaces=None):
pass
def bar(self, element, tag, namespaces=None):
return list(self.iterfind(element, tag, namespaces))"
(forward-line -1)
(end-of-line)
(py-backward-def-or-class)
(should (char-equal ?d (char-after)))
(py-backward-def-or-class)
(should (char-equal ?c (char-after)))
(should (bolp))
(search-forward "pass")
(py-backward-def-or-class)
(should (char-equal ?d (char-after)))))



(provide 'py-ert-tests-1)
;;; py-ert-tests-1.el ends here

0 comments on commit 5dfdaae

Please sign in to comment.