Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8ddb6a

Browse files
committed
(py-narrow-to-defun): New command (bound to C-x n d) which mimics the
standard narrow-to-defun but works with Python classes and methods. With no arg, narrows to most enclosing def/method. With C-u arg, narrows to most enclosing class.
1 parent f6cdcd5 commit f8ddb6a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Misc/python-mode.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ Currently-active file is at the head of the list.")
477477
(define-key py-mode-map "\e\C-e" 'py-end-of-def-or-class)
478478
(define-key py-mode-map "\C-c-" 'py-up-exception)
479479
(define-key py-mode-map "\C-c=" 'py-down-exception)
480+
;; stuff that is `standard' but doesn't interface well with
481+
;; python-mode, which forces us to rebind to special commands
482+
(define-key py-mode-map "\C-xnd" 'py-narrow-to-defun)
480483
;; information
481484
(define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report)
482485
(define-key py-mode-map "\C-c\C-v" 'py-version)
@@ -1827,6 +1830,18 @@ it's tried again going backward."
18271830
(max comment-column (+ (current-column) (if (bolp) 0 1)))
18281831
)))
18291832

1833+
(defun py-narrow-to-defun (&optional class)
1834+
"Make text outside current defun invisible.
1835+
The defun visible is the one that contains point or follows point.
1836+
Optional CLASS is passed directly to `py-beginning-of-def-or-class'."
1837+
(interactive "P")
1838+
(save-excursion
1839+
(widen)
1840+
(py-end-of-def-or-class class)
1841+
(let ((end (point)))
1842+
(py-beginning-of-def-or-class class)
1843+
(narrow-to-region (point) end))))
1844+
18301845

18311846
(defun py-shift-region (start end count)
18321847
"Indent lines from START to END by COUNT spaces."

0 commit comments

Comments
 (0)