summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1999-01-18 21:49:39 (GMT)
committerBarry Warsaw <barry@python.org>1999-01-18 21:49:39 (GMT)
commitf8ddb6afa0d4f0b35ed7d811cf994849b7a04da1 (patch)
treef91ed7c121b0d32df4ea64cb4688d9e7b09985d7 /Misc
parentf6cdcd509df1681b2f27e8a4f9130159c8e13723 (diff)
downloadcpython-f8ddb6afa0d4f0b35ed7d811cf994849b7a04da1.zip
cpython-f8ddb6afa0d4f0b35ed7d811cf994849b7a04da1.tar.gz
cpython-f8ddb6afa0d4f0b35ed7d811cf994849b7a04da1.tar.bz2
(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.
Diffstat (limited to 'Misc')
-rw-r--r--Misc/python-mode.el15
1 files changed, 15 insertions, 0 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el
index 15d9f09..0bdcfa1 100644
--- a/Misc/python-mode.el
+++ b/Misc/python-mode.el
@@ -477,6 +477,9 @@ Currently-active file is at the head of the list.")
(define-key py-mode-map "\e\C-e" 'py-end-of-def-or-class)
(define-key py-mode-map "\C-c-" 'py-up-exception)
(define-key py-mode-map "\C-c=" 'py-down-exception)
+ ;; stuff that is `standard' but doesn't interface well with
+ ;; python-mode, which forces us to rebind to special commands
+ (define-key py-mode-map "\C-xnd" 'py-narrow-to-defun)
;; information
(define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report)
(define-key py-mode-map "\C-c\C-v" 'py-version)
@@ -1827,6 +1830,18 @@ it's tried again going backward."
(max comment-column (+ (current-column) (if (bolp) 0 1)))
)))
+(defun py-narrow-to-defun (&optional class)
+ "Make text outside current defun invisible.
+The defun visible is the one that contains point or follows point.
+Optional CLASS is passed directly to `py-beginning-of-def-or-class'."
+ (interactive "P")
+ (save-excursion
+ (widen)
+ (py-end-of-def-or-class class)
+ (let ((end (point)))
+ (py-beginning-of-def-or-class class)
+ (narrow-to-region (point) end))))
+
(defun py-shift-region (start end count)
"Indent lines from START to END by COUNT spaces."